Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 56 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 58 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 60 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 61 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 62 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 63 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 64 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 65 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 72 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 75 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 76 | /* file attributes which can be mapped to nfs attributes */ |
| 77 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 78 | | ATTR_UID \ |
| 79 | | ATTR_GID \ |
| 80 | | ATTR_SIZE \ |
| 81 | | ATTR_ATIME \ |
| 82 | | ATTR_MTIME \ |
| 83 | | ATTR_CTIME \ |
| 84 | | ATTR_ATIME_SET \ |
| 85 | | ATTR_MTIME_SET) |
| 86 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 87 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 88 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 89 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 91 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 92 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 93 | 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] | 94 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 95 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 96 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 98 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 99 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 100 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 101 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 102 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 103 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 104 | |
| 105 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 106 | static inline struct nfs4_label * |
| 107 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 108 | struct iattr *sattr, struct nfs4_label *label) |
| 109 | { |
| 110 | int err; |
| 111 | |
| 112 | if (label == NULL) |
| 113 | return NULL; |
| 114 | |
| 115 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 116 | return NULL; |
| 117 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 118 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 119 | &dentry->d_name, (void **)&label->label, &label->len); |
| 120 | if (err == 0) |
| 121 | return label; |
| 122 | |
| 123 | return NULL; |
| 124 | } |
| 125 | static inline void |
| 126 | nfs4_label_release_security(struct nfs4_label *label) |
| 127 | { |
| 128 | if (label) |
| 129 | security_release_secctx(label->label, label->len); |
| 130 | } |
| 131 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 132 | { |
| 133 | if (label) |
| 134 | return server->attr_bitmask; |
| 135 | |
| 136 | return server->attr_bitmask_nl; |
| 137 | } |
| 138 | #else |
| 139 | static inline struct nfs4_label * |
| 140 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 141 | struct iattr *sattr, struct nfs4_label *l) |
| 142 | { return NULL; } |
| 143 | static inline void |
| 144 | nfs4_label_release_security(struct nfs4_label *label) |
| 145 | { return; } |
| 146 | static inline u32 * |
| 147 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 148 | { return server->attr_bitmask; } |
| 149 | #endif |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 152 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 154 | if (err >= -1000) |
| 155 | return err; |
| 156 | switch (err) { |
| 157 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 158 | case -NFS4ERR_LAYOUTTRYLATER: |
| 159 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 160 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 161 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 162 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 163 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 164 | case -NFS4ERR_BADOWNER: |
| 165 | case -NFS4ERR_BADNAME: |
| 166 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 167 | case -NFS4ERR_SHARE_DENIED: |
| 168 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 169 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 170 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 171 | case -NFS4ERR_FILE_OPEN: |
| 172 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 173 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 175 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 176 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 178 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This is our standard bitmap for GETATTR requests. |
| 183 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 184 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | FATTR4_WORD0_TYPE |
| 186 | | FATTR4_WORD0_CHANGE |
| 187 | | FATTR4_WORD0_SIZE |
| 188 | | FATTR4_WORD0_FSID |
| 189 | | FATTR4_WORD0_FILEID, |
| 190 | FATTR4_WORD1_MODE |
| 191 | | FATTR4_WORD1_NUMLINKS |
| 192 | | FATTR4_WORD1_OWNER |
| 193 | | FATTR4_WORD1_OWNER_GROUP |
| 194 | | FATTR4_WORD1_RAWDEV |
| 195 | | FATTR4_WORD1_SPACE_USED |
| 196 | | FATTR4_WORD1_TIME_ACCESS |
| 197 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 198 | | FATTR4_WORD1_TIME_MODIFY |
| 199 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 200 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 201 | FATTR4_WORD2_SECURITY_LABEL |
| 202 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 205 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 206 | FATTR4_WORD0_TYPE |
| 207 | | FATTR4_WORD0_CHANGE |
| 208 | | FATTR4_WORD0_SIZE |
| 209 | | FATTR4_WORD0_FSID |
| 210 | | FATTR4_WORD0_FILEID, |
| 211 | FATTR4_WORD1_MODE |
| 212 | | FATTR4_WORD1_NUMLINKS |
| 213 | | FATTR4_WORD1_OWNER |
| 214 | | FATTR4_WORD1_OWNER_GROUP |
| 215 | | FATTR4_WORD1_RAWDEV |
| 216 | | FATTR4_WORD1_SPACE_USED |
| 217 | | FATTR4_WORD1_TIME_ACCESS |
| 218 | | FATTR4_WORD1_TIME_METADATA |
| 219 | | FATTR4_WORD1_TIME_MODIFY, |
| 220 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 221 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 222 | | FATTR4_WORD2_SECURITY_LABEL |
| 223 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 224 | }; |
| 225 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 226 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 227 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 228 | | FATTR4_WORD0_FILEID, |
| 229 | }; |
| 230 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 231 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | FATTR4_WORD0_FILES_AVAIL |
| 233 | | FATTR4_WORD0_FILES_FREE |
| 234 | | FATTR4_WORD0_FILES_TOTAL, |
| 235 | FATTR4_WORD1_SPACE_AVAIL |
| 236 | | FATTR4_WORD1_SPACE_FREE |
| 237 | | FATTR4_WORD1_SPACE_TOTAL |
| 238 | }; |
| 239 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 240 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | FATTR4_WORD0_MAXLINK |
| 242 | | FATTR4_WORD0_MAXNAME, |
| 243 | 0 |
| 244 | }; |
| 245 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 246 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | | FATTR4_WORD0_MAXREAD |
| 248 | | FATTR4_WORD0_MAXWRITE |
| 249 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 250 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 251 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 252 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 253 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 256 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 257 | FATTR4_WORD0_TYPE |
| 258 | | FATTR4_WORD0_CHANGE |
| 259 | | FATTR4_WORD0_SIZE |
| 260 | | FATTR4_WORD0_FSID |
| 261 | | FATTR4_WORD0_FILEID |
| 262 | | FATTR4_WORD0_FS_LOCATIONS, |
| 263 | FATTR4_WORD1_MODE |
| 264 | | FATTR4_WORD1_NUMLINKS |
| 265 | | FATTR4_WORD1_OWNER |
| 266 | | FATTR4_WORD1_OWNER_GROUP |
| 267 | | FATTR4_WORD1_RAWDEV |
| 268 | | FATTR4_WORD1_SPACE_USED |
| 269 | | FATTR4_WORD1_TIME_ACCESS |
| 270 | | FATTR4_WORD1_TIME_METADATA |
| 271 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 272 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 273 | }; |
| 274 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 275 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | struct nfs4_readdir_arg *readdir) |
| 277 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 278 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 279 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 282 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | readdir->cookie = 0; |
| 288 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 289 | if (cookie == 2) |
| 290 | return; |
| 291 | |
| 292 | /* |
| 293 | * NFSv4 servers do not return entries for '.' and '..' |
| 294 | * Therefore, we fake these entries here. We let '.' |
| 295 | * have cookie 0 and '..' have cookie 1. Note that |
| 296 | * when talking to the server, we always send cookie 0 |
| 297 | * instead of 1 or 2. |
| 298 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 299 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | if (cookie == 0) { |
| 302 | *p++ = xdr_one; /* next */ |
| 303 | *p++ = xdr_zero; /* cookie, first word */ |
| 304 | *p++ = xdr_one; /* cookie, second word */ |
| 305 | *p++ = xdr_one; /* entry len */ |
| 306 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 307 | p++; |
| 308 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 309 | *p++ = htonl(attrs); /* bitmap */ |
| 310 | *p++ = htonl(12); /* attribute buffer length */ |
| 311 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | *p++ = xdr_one; /* next */ |
| 316 | *p++ = xdr_zero; /* cookie, first word */ |
| 317 | *p++ = xdr_two; /* cookie, second word */ |
| 318 | *p++ = xdr_two; /* entry len */ |
| 319 | memcpy(p, "..\0\0", 4); /* entry */ |
| 320 | p++; |
| 321 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 322 | *p++ = htonl(attrs); /* bitmap */ |
| 323 | *p++ = htonl(12); /* attribute buffer length */ |
| 324 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 325 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | readdir->pgbase = (char *)p - (char *)start; |
| 328 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 329 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 332 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 333 | nfs4_stateid *stateid, |
| 334 | struct rpc_cred *cred) |
| 335 | { |
| 336 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 337 | |
| 338 | ops->test_and_free_expired(server, stateid, cred); |
| 339 | } |
| 340 | |
| 341 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 342 | nfs4_stateid *stateid, |
| 343 | struct rpc_cred *cred) |
| 344 | { |
| 345 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 346 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 347 | } |
| 348 | |
| 349 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 350 | const nfs4_stateid *stateid, |
| 351 | struct rpc_cred *cred) |
| 352 | { |
| 353 | nfs4_stateid tmp; |
| 354 | |
| 355 | nfs4_stateid_copy(&tmp, stateid); |
| 356 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 357 | } |
| 358 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 359 | static long nfs4_update_delay(long *timeout) |
| 360 | { |
| 361 | long ret; |
| 362 | if (!timeout) |
| 363 | return NFS4_POLL_RETRY_MAX; |
| 364 | if (*timeout <= 0) |
| 365 | *timeout = NFS4_POLL_RETRY_MIN; |
| 366 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 367 | *timeout = NFS4_POLL_RETRY_MAX; |
| 368 | ret = *timeout; |
| 369 | *timeout <<= 1; |
| 370 | return ret; |
| 371 | } |
| 372 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 373 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 374 | { |
| 375 | int res = 0; |
| 376 | |
| 377 | might_sleep(); |
| 378 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 379 | freezable_schedule_timeout_killable_unsafe( |
| 380 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 381 | if (fatal_signal_pending(current)) |
| 382 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 383 | return res; |
| 384 | } |
| 385 | |
| 386 | /* This is the error handling routine for processes that are allowed |
| 387 | * to sleep. |
| 388 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 389 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 390 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 391 | { |
| 392 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 393 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 394 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 395 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 396 | int ret = errorcode; |
| 397 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 398 | exception->delay = 0; |
| 399 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 400 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 401 | |
| 402 | if (stateid == NULL && state != NULL) |
| 403 | stateid = &state->stateid; |
| 404 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 405 | switch(errorcode) { |
| 406 | case 0: |
| 407 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 408 | case -NFS4ERR_DELEG_REVOKED: |
| 409 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 410 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 411 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 412 | if (inode != NULL && stateid != NULL) { |
| 413 | nfs_inode_find_state_and_recover(inode, |
| 414 | stateid); |
| 415 | goto wait_on_recovery; |
| 416 | } |
| 417 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 418 | if (inode) { |
| 419 | int err; |
| 420 | |
| 421 | err = nfs_async_inode_return_delegation(inode, |
| 422 | stateid); |
| 423 | if (err == 0) |
| 424 | goto wait_on_recovery; |
| 425 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 426 | exception->retry = 1; |
| 427 | break; |
| 428 | } |
| 429 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 430 | if (state == NULL) |
| 431 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 432 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 433 | if (ret < 0) |
| 434 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 435 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 436 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 437 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 438 | nfs4_schedule_lease_recovery(clp); |
| 439 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 440 | case -NFS4ERR_MOVED: |
| 441 | ret = nfs4_schedule_migration_recovery(server); |
| 442 | if (ret < 0) |
| 443 | break; |
| 444 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 445 | case -NFS4ERR_LEASE_MOVED: |
| 446 | nfs4_schedule_lease_moved_recovery(clp); |
| 447 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 448 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 449 | case -NFS4ERR_BADSESSION: |
| 450 | case -NFS4ERR_BADSLOT: |
| 451 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 452 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 453 | case -NFS4ERR_DEADSESSION: |
| 454 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 455 | case -NFS4ERR_SEQ_MISORDERED: |
| 456 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 457 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 458 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 459 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 460 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 461 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 462 | if (exception->timeout > HZ) { |
| 463 | /* We have retried a decent amount, time to |
| 464 | * fail |
| 465 | */ |
| 466 | ret = -EBUSY; |
| 467 | break; |
| 468 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 469 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 470 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 471 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 472 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 473 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 474 | exception->delay = 1; |
| 475 | return 0; |
| 476 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 477 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 478 | case -NFS4ERR_OLD_STATEID: |
| 479 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 480 | break; |
| 481 | case -NFS4ERR_BADOWNER: |
| 482 | /* The following works around a Linux server bug! */ |
| 483 | case -NFS4ERR_BADNAME: |
| 484 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 485 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 486 | exception->retry = 1; |
| 487 | printk(KERN_WARNING "NFS: v4 server %s " |
| 488 | "does not accept raw " |
| 489 | "uid/gids. " |
| 490 | "Reenabling the idmapper.\n", |
| 491 | server->nfs_client->cl_hostname); |
| 492 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 493 | } |
| 494 | /* We failed to handle the error */ |
| 495 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 496 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 497 | exception->recovering = 1; |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /* This is the error handling routine for processes that are allowed |
| 502 | * to sleep. |
| 503 | */ |
| 504 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 505 | { |
| 506 | struct nfs_client *clp = server->nfs_client; |
| 507 | int ret; |
| 508 | |
| 509 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 510 | if (exception->delay) { |
| 511 | ret = nfs4_delay(server->client, &exception->timeout); |
| 512 | goto out_retry; |
| 513 | } |
| 514 | if (exception->recovering) { |
| 515 | ret = nfs4_wait_clnt_recover(clp); |
| 516 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 517 | return -EIO; |
| 518 | goto out_retry; |
| 519 | } |
| 520 | return ret; |
| 521 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 522 | if (ret == 0) |
| 523 | exception->retry = 1; |
| 524 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 525 | } |
| 526 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 527 | static int |
| 528 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 529 | int errorcode, struct nfs4_exception *exception) |
| 530 | { |
| 531 | struct nfs_client *clp = server->nfs_client; |
| 532 | int ret; |
| 533 | |
| 534 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 535 | if (exception->delay) { |
| 536 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 537 | goto out_retry; |
| 538 | } |
| 539 | if (exception->recovering) { |
| 540 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 541 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 542 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 543 | goto out_retry; |
| 544 | } |
| 545 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 546 | ret = -EIO; |
| 547 | return ret; |
| 548 | out_retry: |
| 549 | if (ret == 0) |
| 550 | exception->retry = 1; |
| 551 | return ret; |
| 552 | } |
| 553 | |
| 554 | static int |
| 555 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 556 | struct nfs4_state *state, long *timeout) |
| 557 | { |
| 558 | struct nfs4_exception exception = { |
| 559 | .state = state, |
| 560 | }; |
| 561 | |
| 562 | if (task->tk_status >= 0) |
| 563 | return 0; |
| 564 | if (timeout) |
| 565 | exception.timeout = *timeout; |
| 566 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 567 | task->tk_status, |
| 568 | &exception); |
| 569 | if (exception.delay && timeout) |
| 570 | *timeout = exception.timeout; |
| 571 | if (exception.retry) |
| 572 | return -EAGAIN; |
| 573 | return 0; |
| 574 | } |
| 575 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 576 | /* |
| 577 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 578 | * or 'false' otherwise. |
| 579 | */ |
| 580 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 581 | { |
| 582 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 583 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 584 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 585 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 586 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | spin_lock(&clp->cl_lock); |
| 589 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 590 | clp->cl_last_renewal = timestamp; |
| 591 | spin_unlock(&clp->cl_lock); |
| 592 | } |
| 593 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 594 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 595 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 596 | struct nfs_client *clp = server->nfs_client; |
| 597 | |
| 598 | if (!nfs4_has_session(clp)) |
| 599 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 600 | } |
| 601 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 602 | struct nfs4_call_sync_data { |
| 603 | const struct nfs_server *seq_server; |
| 604 | struct nfs4_sequence_args *seq_args; |
| 605 | struct nfs4_sequence_res *seq_res; |
| 606 | }; |
| 607 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 608 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 609 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 610 | { |
| 611 | args->sa_slot = NULL; |
| 612 | args->sa_cache_this = cache_reply; |
| 613 | args->sa_privileged = 0; |
| 614 | |
| 615 | res->sr_slot = NULL; |
| 616 | } |
| 617 | |
| 618 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 619 | { |
| 620 | args->sa_privileged = 1; |
| 621 | } |
| 622 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 623 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 624 | { |
| 625 | struct nfs4_slot *slot = res->sr_slot; |
| 626 | struct nfs4_slot_table *tbl; |
| 627 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 628 | tbl = slot->table; |
| 629 | spin_lock(&tbl->slot_tbl_lock); |
| 630 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 631 | nfs4_free_slot(tbl, slot); |
| 632 | spin_unlock(&tbl->slot_tbl_lock); |
| 633 | |
| 634 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static int nfs40_sequence_done(struct rpc_task *task, |
| 638 | struct nfs4_sequence_res *res) |
| 639 | { |
| 640 | if (res->sr_slot != NULL) |
| 641 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 642 | return 1; |
| 643 | } |
| 644 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 645 | #if defined(CONFIG_NFS_V4_1) |
| 646 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 647 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 648 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 649 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 650 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 651 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 652 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 653 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 654 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 655 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 656 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 657 | /* Bump the slot sequence number */ |
| 658 | if (slot->seq_done) |
| 659 | slot->seq_nr++; |
| 660 | slot->seq_done = 0; |
| 661 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 662 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 663 | /* Be nice to the server: try to ensure that the last transmitted |
| 664 | * value for highest_user_slotid <= target_highest_slotid |
| 665 | */ |
| 666 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 667 | send_new_highest_used_slotid = true; |
| 668 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 669 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 670 | send_new_highest_used_slotid = false; |
| 671 | goto out_unlock; |
| 672 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 673 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 674 | |
| 675 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 676 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 677 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 678 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 679 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 680 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 681 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 682 | if (waitqueue_active(&tbl->slot_waitq)) |
| 683 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 684 | } |
| 685 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 686 | static int nfs41_sequence_process(struct rpc_task *task, |
| 687 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 688 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 689 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 690 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 691 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 692 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 693 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 694 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 695 | if (slot == NULL) |
| 696 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 697 | /* don't increment the sequence number if the task wasn't sent */ |
| 698 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 699 | goto out; |
| 700 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 701 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 702 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 703 | if (slot->interrupted) { |
Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 704 | if (res->sr_status != -NFS4ERR_DELAY) |
| 705 | slot->interrupted = 0; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 706 | interrupted = true; |
| 707 | } |
| 708 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 709 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 710 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 711 | switch (res->sr_status) { |
| 712 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 713 | /* If previous op on slot was interrupted and we reused |
| 714 | * the seq# and got a reply from the cache, then retry |
| 715 | */ |
| 716 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 717 | ++slot->seq_nr; |
| 718 | goto retry_nowait; |
| 719 | } |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 720 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 721 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 722 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 723 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 724 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 725 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 726 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 727 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 728 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 729 | case 1: |
| 730 | /* |
| 731 | * sr_status remains 1 if an RPC level error occurred. |
| 732 | * The server may or may not have processed the sequence |
| 733 | * operation.. |
| 734 | * Mark the slot as having hosted an interrupted RPC call. |
| 735 | */ |
| 736 | slot->interrupted = 1; |
| 737 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 738 | case -NFS4ERR_DELAY: |
| 739 | /* The server detected a resend of the RPC call and |
| 740 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 741 | * of RFC5661. |
| 742 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 743 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 744 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 745 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 746 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 747 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 748 | case -NFS4ERR_BADSLOT: |
| 749 | /* |
| 750 | * The slot id we used was probably retired. Try again |
| 751 | * using a different slot id. |
| 752 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 753 | goto retry_nowait; |
| 754 | case -NFS4ERR_SEQ_MISORDERED: |
| 755 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 756 | * Was the last operation on this sequence interrupted? |
| 757 | * If so, retry after bumping the sequence number. |
| 758 | */ |
| 759 | if (interrupted) { |
| 760 | ++slot->seq_nr; |
| 761 | goto retry_nowait; |
| 762 | } |
| 763 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 764 | * Could this slot have been previously retired? |
| 765 | * If so, then the server may be expecting seq_nr = 1! |
| 766 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 767 | if (slot->seq_nr != 1) { |
| 768 | slot->seq_nr = 1; |
| 769 | goto retry_nowait; |
| 770 | } |
| 771 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 772 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 773 | ++slot->seq_nr; |
| 774 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 775 | default: |
| 776 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 777 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 778 | } |
| 779 | out: |
| 780 | /* The session may be reset by one of the error handlers. */ |
| 781 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 782 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 783 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 784 | retry_nowait: |
| 785 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 786 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 787 | task->tk_status = 0; |
| 788 | ret = 0; |
| 789 | } |
| 790 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 791 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 792 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 793 | goto out; |
| 794 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 795 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 796 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 797 | |
| 798 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 799 | { |
| 800 | if (!nfs41_sequence_process(task, res)) |
| 801 | return 0; |
| 802 | if (res->sr_slot != NULL) |
| 803 | nfs41_sequence_free_slot(res); |
| 804 | return 1; |
| 805 | |
| 806 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 807 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 808 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 809 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 810 | { |
| 811 | if (res->sr_slot == NULL) |
| 812 | return 1; |
| 813 | if (res->sr_slot->table->session != NULL) |
| 814 | return nfs41_sequence_process(task, res); |
| 815 | return nfs40_sequence_done(task, res); |
| 816 | } |
| 817 | |
| 818 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 819 | { |
| 820 | if (res->sr_slot != NULL) { |
| 821 | if (res->sr_slot->table->session != NULL) |
| 822 | nfs41_sequence_free_slot(res); |
| 823 | else |
| 824 | nfs40_sequence_free_slot(res); |
| 825 | } |
| 826 | } |
| 827 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 828 | 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] | 829 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 830 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 831 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 832 | if (!res->sr_slot->table->session) |
| 833 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 834 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 835 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 836 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 837 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 838 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 839 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 840 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 841 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 842 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 843 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 844 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 845 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 846 | } |
| 847 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 848 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 849 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 850 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 851 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 852 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 853 | } |
| 854 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 855 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 856 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 857 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 858 | }; |
| 859 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 860 | #else /* !CONFIG_NFS_V4_1 */ |
| 861 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 862 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 863 | { |
| 864 | return nfs40_sequence_done(task, res); |
| 865 | } |
| 866 | |
| 867 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 868 | { |
| 869 | if (res->sr_slot != NULL) |
| 870 | nfs40_sequence_free_slot(res); |
| 871 | } |
| 872 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 873 | int nfs4_sequence_done(struct rpc_task *task, |
| 874 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 875 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 876 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 877 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 878 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 879 | |
| 880 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 881 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 882 | int nfs4_setup_sequence(const struct nfs_client *client, |
| 883 | struct nfs4_sequence_args *args, |
| 884 | struct nfs4_sequence_res *res, |
| 885 | struct rpc_task *task) |
| 886 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 887 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 888 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 889 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 890 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 891 | /* slot already allocated? */ |
| 892 | if (res->sr_slot != NULL) |
| 893 | goto out_start; |
| 894 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 895 | if (session) { |
| 896 | tbl = &session->fc_slot_table; |
| 897 | task->tk_timeout = 0; |
| 898 | } |
| 899 | |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 900 | spin_lock(&tbl->slot_tbl_lock); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 901 | /* The state manager will wait until the slot table is empty */ |
| 902 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 903 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 904 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 905 | slot = nfs4_alloc_slot(tbl); |
| 906 | if (IS_ERR(slot)) { |
| 907 | /* Try again in 1/4 second */ |
| 908 | if (slot == ERR_PTR(-ENOMEM)) |
| 909 | task->tk_timeout = HZ >> 2; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 910 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 911 | } |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 912 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 913 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 914 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 915 | args->sa_slot = slot; |
| 916 | |
| 917 | res->sr_slot = slot; |
| 918 | if (session) { |
| 919 | res->sr_timestamp = jiffies; |
| 920 | res->sr_status_flags = 0; |
| 921 | res->sr_status = 1; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 922 | } |
| 923 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 924 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 925 | out_start: |
| 926 | rpc_call_start(task); |
| 927 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 928 | |
| 929 | out_sleep: |
| 930 | if (args->sa_privileged) |
| 931 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 932 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 933 | else |
| 934 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 935 | spin_unlock(&tbl->slot_tbl_lock); |
| 936 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 937 | } |
| 938 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 939 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 940 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 941 | { |
| 942 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 943 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 944 | data->seq_args, data->seq_res, task); |
| 945 | } |
| 946 | |
| 947 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 948 | { |
| 949 | struct nfs4_call_sync_data *data = calldata; |
| 950 | nfs4_sequence_done(task, data->seq_res); |
| 951 | } |
| 952 | |
| 953 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 954 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 955 | .rpc_call_done = nfs40_call_sync_done, |
| 956 | }; |
| 957 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 958 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 959 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 960 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 961 | struct nfs4_sequence_args *args, |
| 962 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 963 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 964 | int ret; |
| 965 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 966 | struct nfs_client *clp = server->nfs_client; |
| 967 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 968 | .seq_server = server, |
| 969 | .seq_args = args, |
| 970 | .seq_res = res, |
| 971 | }; |
| 972 | struct rpc_task_setup task_setup = { |
| 973 | .rpc_client = clnt, |
| 974 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 975 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 976 | .callback_data = &data |
| 977 | }; |
| 978 | |
| 979 | task = rpc_run_task(&task_setup); |
| 980 | if (IS_ERR(task)) |
| 981 | ret = PTR_ERR(task); |
| 982 | else { |
| 983 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 984 | rpc_put_task(task); |
| 985 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 986 | return ret; |
| 987 | } |
| 988 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 989 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 990 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 991 | struct rpc_message *msg, |
| 992 | struct nfs4_sequence_args *args, |
| 993 | struct nfs4_sequence_res *res, |
| 994 | int cache_reply) |
| 995 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 996 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 997 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1000 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1001 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
| 1003 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1004 | |
| 1005 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1006 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1007 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1008 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1009 | nfsi->attrtimeo_timestamp = jiffies; |
| 1010 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1012 | if (cinfo->before != dir->i_version) |
| 1013 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1014 | NFS_INO_INVALID_ACL; |
| 1015 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1016 | dir->i_version = cinfo->after; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1017 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1018 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1019 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | spin_unlock(&dir->i_lock); |
| 1021 | } |
| 1022 | |
| 1023 | struct nfs4_opendata { |
| 1024 | struct kref kref; |
| 1025 | struct nfs_openargs o_arg; |
| 1026 | struct nfs_openres o_res; |
| 1027 | struct nfs_open_confirmargs c_arg; |
| 1028 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1029 | struct nfs4_string owner_name; |
| 1030 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1031 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1033 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1035 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | struct nfs4_state_owner *owner; |
| 1037 | struct nfs4_state *state; |
| 1038 | struct iattr attrs; |
| 1039 | unsigned long timestamp; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1040 | bool rpc_done; |
| 1041 | bool file_created; |
| 1042 | bool is_recover; |
| 1043 | bool cancelled; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1044 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1046 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1047 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1048 | int err, struct nfs4_exception *exception) |
| 1049 | { |
| 1050 | if (err != -EINVAL) |
| 1051 | return false; |
| 1052 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1053 | return false; |
| 1054 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1055 | exception->retry = 1; |
| 1056 | return true; |
| 1057 | } |
| 1058 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1059 | static u32 |
| 1060 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1061 | fmode_t fmode, int openflags) |
| 1062 | { |
| 1063 | u32 res = 0; |
| 1064 | |
| 1065 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1066 | case FMODE_READ: |
| 1067 | res = NFS4_SHARE_ACCESS_READ; |
| 1068 | break; |
| 1069 | case FMODE_WRITE: |
| 1070 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1071 | break; |
| 1072 | case FMODE_READ|FMODE_WRITE: |
| 1073 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1074 | } |
| 1075 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1076 | goto out; |
| 1077 | /* Want no delegation if we're using O_DIRECT */ |
| 1078 | if (openflags & O_DIRECT) |
| 1079 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1080 | out: |
| 1081 | return res; |
| 1082 | } |
| 1083 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1084 | static enum open_claim_type4 |
| 1085 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1086 | enum open_claim_type4 claim) |
| 1087 | { |
| 1088 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1089 | return claim; |
| 1090 | switch (claim) { |
| 1091 | default: |
| 1092 | return claim; |
| 1093 | case NFS4_OPEN_CLAIM_FH: |
| 1094 | return NFS4_OPEN_CLAIM_NULL; |
| 1095 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1096 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1097 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1098 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1099 | } |
| 1100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
| 1102 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1103 | { |
| 1104 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1105 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1106 | p->o_res.seqid = p->o_arg.seqid; |
| 1107 | p->c_res.seqid = p->c_arg.seqid; |
| 1108 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1109 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1110 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1111 | 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] | 1112 | } |
| 1113 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1114 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1115 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1116 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1117 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1118 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1119 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1120 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1121 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1122 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1123 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1124 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1125 | struct nfs4_opendata *p; |
| 1126 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1127 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1128 | if (p == NULL) |
| 1129 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1130 | |
| 1131 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1132 | if (IS_ERR(p->f_label)) |
| 1133 | goto err_free_p; |
| 1134 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1135 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1136 | if (IS_ERR(p->a_label)) |
| 1137 | goto err_free_f; |
| 1138 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1139 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1140 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1141 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1142 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1143 | nfs_sb_active(dentry->d_sb); |
| 1144 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1145 | p->dir = parent; |
| 1146 | p->owner = sp; |
| 1147 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1148 | p->o_arg.open_flags = flags; |
| 1149 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1150 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1151 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1152 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1153 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1154 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1155 | * will return permission denied for all bits until close */ |
| 1156 | if (!(flags & O_EXCL)) { |
| 1157 | /* ask server to check for all possible rights as results |
| 1158 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1159 | switch (p->o_arg.claim) { |
| 1160 | default: |
| 1161 | break; |
| 1162 | case NFS4_OPEN_CLAIM_NULL: |
| 1163 | case NFS4_OPEN_CLAIM_FH: |
| 1164 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1165 | NFS4_ACCESS_MODIFY | |
| 1166 | NFS4_ACCESS_EXTEND | |
| 1167 | NFS4_ACCESS_EXECUTE; |
| 1168 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1169 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1170 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1171 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1172 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1173 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1174 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1175 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1176 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1177 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1178 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1179 | case NFS4_OPEN_CLAIM_NULL: |
| 1180 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1181 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1182 | p->o_arg.fh = NFS_FH(dir); |
| 1183 | break; |
| 1184 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1185 | case NFS4_OPEN_CLAIM_FH: |
| 1186 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1187 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1188 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1189 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1190 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1191 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1192 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1193 | p->o_arg.u.attrs = &p->attrs; |
| 1194 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1195 | |
| 1196 | verf[0] = jiffies; |
| 1197 | verf[1] = current->pid; |
| 1198 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1199 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1200 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1201 | p->c_arg.fh = &p->o_res.fh; |
| 1202 | p->c_arg.stateid = &p->o_res.stateid; |
| 1203 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1204 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1205 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1206 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1207 | |
| 1208 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1209 | nfs4_label_free(p->a_label); |
| 1210 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1211 | nfs4_label_free(p->f_label); |
| 1212 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1213 | kfree(p); |
| 1214 | err: |
| 1215 | dput(parent); |
| 1216 | return NULL; |
| 1217 | } |
| 1218 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1219 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1220 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1221 | struct nfs4_opendata *p = container_of(kref, |
| 1222 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1223 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1224 | |
| 1225 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1226 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1227 | if (p->state != NULL) |
| 1228 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1229 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1230 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1231 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1232 | nfs4_label_free(p->f_label); |
| 1233 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1234 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1235 | dput(p->dentry); |
| 1236 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1237 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1238 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1239 | kfree(p); |
| 1240 | } |
| 1241 | |
| 1242 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1243 | { |
| 1244 | if (p != NULL) |
| 1245 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1246 | } |
| 1247 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1248 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1249 | fmode_t fmode) |
| 1250 | { |
| 1251 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1252 | case FMODE_READ|FMODE_WRITE: |
| 1253 | return state->n_rdwr != 0; |
| 1254 | case FMODE_WRITE: |
| 1255 | return state->n_wronly != 0; |
| 1256 | case FMODE_READ: |
| 1257 | return state->n_rdonly != 0; |
| 1258 | } |
| 1259 | WARN_ON_ONCE(1); |
| 1260 | return false; |
| 1261 | } |
| 1262 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1263 | 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] | 1264 | { |
| 1265 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1266 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1267 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1268 | goto out; |
| 1269 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1270 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1271 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1272 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1273 | break; |
| 1274 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1275 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1276 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1277 | break; |
| 1278 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1279 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1280 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1281 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1282 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1283 | return ret; |
| 1284 | } |
| 1285 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1286 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1287 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1288 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1289 | if (delegation == NULL) |
| 1290 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1291 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1292 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1293 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1294 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1295 | switch (claim) { |
| 1296 | case NFS4_OPEN_CLAIM_NULL: |
| 1297 | case NFS4_OPEN_CLAIM_FH: |
| 1298 | break; |
| 1299 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1300 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1301 | break; |
| 1302 | default: |
| 1303 | return 0; |
| 1304 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1305 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1306 | return 1; |
| 1307 | } |
| 1308 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1309 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1310 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1311 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1312 | case FMODE_WRITE: |
| 1313 | state->n_wronly++; |
| 1314 | break; |
| 1315 | case FMODE_READ: |
| 1316 | state->n_rdonly++; |
| 1317 | break; |
| 1318 | case FMODE_READ|FMODE_WRITE: |
| 1319 | state->n_rdwr++; |
| 1320 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1321 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1324 | #ifdef CONFIG_NFS_V4_1 |
| 1325 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1326 | { |
| 1327 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1328 | return true; |
| 1329 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1330 | return true; |
| 1331 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1332 | return true; |
| 1333 | return false; |
| 1334 | } |
| 1335 | #endif /* CONFIG_NFS_V4_1 */ |
| 1336 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1337 | 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] | 1338 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1339 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1340 | bool need_recover = false; |
| 1341 | |
| 1342 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1343 | need_recover = true; |
| 1344 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1345 | need_recover = true; |
| 1346 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1347 | need_recover = true; |
| 1348 | if (need_recover) |
| 1349 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1350 | } |
| 1351 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1352 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1353 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1354 | { |
| 1355 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1356 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1357 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1358 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1359 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1360 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1361 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1362 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1363 | return true; |
| 1364 | return false; |
| 1365 | } |
| 1366 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1367 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1368 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1369 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1370 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1371 | if (state->n_wronly) |
| 1372 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1373 | if (state->n_rdonly) |
| 1374 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1375 | if (state->n_rdwr) |
| 1376 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1377 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1378 | } |
| 1379 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1380 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1381 | nfs4_stateid *stateid, fmode_t fmode) |
| 1382 | { |
| 1383 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1384 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1385 | case FMODE_WRITE: |
| 1386 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1387 | break; |
| 1388 | case FMODE_READ: |
| 1389 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1390 | break; |
| 1391 | case 0: |
| 1392 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1393 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1394 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1395 | } |
| 1396 | if (stateid == NULL) |
| 1397 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1398 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1399 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1400 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1401 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1402 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1403 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1404 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1405 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1406 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1407 | } |
| 1408 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1409 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1410 | nfs4_stateid *arg_stateid, |
| 1411 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1412 | { |
| 1413 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1414 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1415 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1416 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1417 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1418 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1419 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1420 | } |
| 1421 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1422 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1423 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1424 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1425 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1426 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1427 | case FMODE_READ: |
| 1428 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1429 | break; |
| 1430 | case FMODE_WRITE: |
| 1431 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1432 | break; |
| 1433 | case FMODE_READ|FMODE_WRITE: |
| 1434 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1435 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1436 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1437 | return; |
| 1438 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1439 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1440 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1441 | } |
| 1442 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1443 | static void __update_open_stateid(struct nfs4_state *state, |
| 1444 | const nfs4_stateid *open_stateid, |
| 1445 | const nfs4_stateid *deleg_stateid, |
| 1446 | fmode_t fmode, |
| 1447 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1449 | /* |
| 1450 | * Protect the call to nfs4_state_set_mode_locked and |
| 1451 | * serialise the stateid update |
| 1452 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1453 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1454 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1455 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1456 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1457 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1458 | } |
| 1459 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1460 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1461 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1462 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1463 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1466 | static int update_open_stateid(struct nfs4_state *state, |
| 1467 | const nfs4_stateid *open_stateid, |
| 1468 | const nfs4_stateid *delegation, |
| 1469 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1470 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1471 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1472 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1473 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1474 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1475 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1476 | int ret = 0; |
| 1477 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1478 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1479 | |
| 1480 | rcu_read_lock(); |
| 1481 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1482 | if (deleg_cur == NULL) |
| 1483 | goto no_delegation; |
| 1484 | |
| 1485 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1486 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1487 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1488 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1489 | goto no_delegation_unlock; |
| 1490 | |
| 1491 | if (delegation == NULL) |
| 1492 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1493 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1494 | goto no_delegation_unlock; |
| 1495 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1496 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1497 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1498 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1499 | ret = 1; |
| 1500 | no_delegation_unlock: |
| 1501 | spin_unlock(&deleg_cur->lock); |
| 1502 | no_delegation: |
| 1503 | rcu_read_unlock(); |
| 1504 | |
| 1505 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1506 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1507 | ret = 1; |
| 1508 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1509 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1510 | nfs4_schedule_state_manager(clp); |
| 1511 | if (freeme.type != 0) |
| 1512 | nfs4_test_and_free_stateid(server, &freeme, |
| 1513 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1514 | |
| 1515 | return ret; |
| 1516 | } |
| 1517 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1518 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1519 | const nfs4_stateid *stateid) |
| 1520 | { |
| 1521 | struct nfs4_state *state = lsp->ls_state; |
| 1522 | bool ret = false; |
| 1523 | |
| 1524 | spin_lock(&state->state_lock); |
| 1525 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1526 | goto out_noupdate; |
| 1527 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1528 | goto out_noupdate; |
| 1529 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1530 | ret = true; |
| 1531 | out_noupdate: |
| 1532 | spin_unlock(&state->state_lock); |
| 1533 | return ret; |
| 1534 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1535 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1536 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1537 | { |
| 1538 | struct nfs_delegation *delegation; |
| 1539 | |
| 1540 | rcu_read_lock(); |
| 1541 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1542 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1543 | rcu_read_unlock(); |
| 1544 | return; |
| 1545 | } |
| 1546 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1547 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1548 | } |
| 1549 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1550 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1551 | { |
| 1552 | struct nfs4_state *state = opendata->state; |
| 1553 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1554 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1555 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1556 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1557 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1558 | nfs4_stateid stateid; |
| 1559 | int ret = -EAGAIN; |
| 1560 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1561 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1562 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1563 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1564 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1565 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1566 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1567 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1568 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1569 | rcu_read_lock(); |
| 1570 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1571 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1572 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1573 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1574 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1575 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1576 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1577 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1578 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1579 | if (!opendata->is_recover) { |
| 1580 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1581 | if (ret != 0) |
| 1582 | goto out; |
| 1583 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1584 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1585 | |
| 1586 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1587 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1588 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1589 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1590 | out: |
| 1591 | return ERR_PTR(ret); |
| 1592 | out_return_state: |
| 1593 | atomic_inc(&state->count); |
| 1594 | return state; |
| 1595 | } |
| 1596 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1597 | static void |
| 1598 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1599 | { |
| 1600 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1601 | struct nfs_delegation *delegation; |
| 1602 | int delegation_flags = 0; |
| 1603 | |
| 1604 | rcu_read_lock(); |
| 1605 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1606 | if (delegation) |
| 1607 | delegation_flags = delegation->flags; |
| 1608 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1609 | switch (data->o_arg.claim) { |
| 1610 | default: |
| 1611 | break; |
| 1612 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1613 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1614 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1615 | "returning a delegation for " |
| 1616 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1617 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1618 | return; |
| 1619 | } |
| 1620 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1621 | nfs_inode_set_delegation(state->inode, |
| 1622 | data->owner->so_cred, |
| 1623 | &data->o_res); |
| 1624 | else |
| 1625 | nfs_inode_reclaim_delegation(state->inode, |
| 1626 | data->owner->so_cred, |
| 1627 | &data->o_res); |
| 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1632 | * and update the nfs4_state. |
| 1633 | */ |
| 1634 | static struct nfs4_state * |
| 1635 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1636 | { |
| 1637 | struct inode *inode = data->state->inode; |
| 1638 | struct nfs4_state *state = data->state; |
| 1639 | int ret; |
| 1640 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1641 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1642 | if (data->rpc_status) |
| 1643 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1644 | /* cached opens have already been processed */ |
| 1645 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1646 | } |
| 1647 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1648 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1649 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1650 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1651 | |
| 1652 | if (data->o_res.delegation_type != 0) |
| 1653 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1654 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1655 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1656 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1657 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1658 | |
| 1659 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | static struct nfs4_state * |
| 1663 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1664 | { |
| 1665 | struct inode *inode; |
| 1666 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1667 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1668 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1669 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1670 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1671 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1672 | goto out; |
| 1673 | } |
| 1674 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1675 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1676 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1677 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1678 | 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] | 1679 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1680 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1681 | goto err; |
| 1682 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1683 | state = nfs4_get_open_state(inode, data->owner); |
| 1684 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1685 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1686 | if (data->o_res.delegation_type != 0) |
| 1687 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1688 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1689 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1690 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1691 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1692 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1693 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1694 | err_put_inode: |
| 1695 | iput(inode); |
| 1696 | err: |
| 1697 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1698 | } |
| 1699 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1700 | static struct nfs4_state * |
| 1701 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1702 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1703 | struct nfs4_state *ret; |
| 1704 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1705 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1706 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1707 | else |
| 1708 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1709 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1710 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1711 | } |
| 1712 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1713 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1714 | { |
| 1715 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1716 | struct nfs_open_context *ctx; |
| 1717 | |
| 1718 | spin_lock(&state->inode->i_lock); |
| 1719 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1720 | if (ctx->state != state) |
| 1721 | continue; |
| 1722 | get_nfs_open_context(ctx); |
| 1723 | spin_unlock(&state->inode->i_lock); |
| 1724 | return ctx; |
| 1725 | } |
| 1726 | spin_unlock(&state->inode->i_lock); |
| 1727 | return ERR_PTR(-ENOENT); |
| 1728 | } |
| 1729 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1730 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1731 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1732 | { |
| 1733 | struct nfs4_opendata *opendata; |
| 1734 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1735 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1736 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1737 | if (opendata == NULL) |
| 1738 | return ERR_PTR(-ENOMEM); |
| 1739 | opendata->state = state; |
| 1740 | atomic_inc(&state->count); |
| 1741 | return opendata; |
| 1742 | } |
| 1743 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1744 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1745 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1746 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1747 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1748 | int ret; |
| 1749 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1750 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1751 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1752 | opendata->o_arg.open_flags = 0; |
| 1753 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1754 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1755 | NFS_SB(opendata->dentry->d_sb), |
| 1756 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1757 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1758 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1759 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1760 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1761 | if (ret != 0) |
| 1762 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1763 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1764 | if (IS_ERR(newstate)) |
| 1765 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1766 | if (newstate != opendata->state) |
| 1767 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1768 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1769 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1773 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1774 | int ret; |
| 1775 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1776 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1777 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1778 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1779 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1780 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1781 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1782 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1783 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1784 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1785 | if (ret != 0) |
| 1786 | return ret; |
| 1787 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1788 | if (ret != 0) |
| 1789 | return ret; |
| 1790 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1791 | if (ret != 0) |
| 1792 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1793 | /* |
| 1794 | * We may have performed cached opens for all three recoveries. |
| 1795 | * Check if we need to update the current stateid. |
| 1796 | */ |
| 1797 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1798 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1799 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1800 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1801 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1802 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1803 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1804 | return 0; |
| 1805 | } |
| 1806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | /* |
| 1808 | * OPEN_RECLAIM: |
| 1809 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1811 | 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] | 1812 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1813 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1814 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1815 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | int status; |
| 1817 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1818 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1819 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1820 | if (IS_ERR(opendata)) |
| 1821 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1822 | rcu_read_lock(); |
| 1823 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1824 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1825 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1826 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1827 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1828 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1829 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | return status; |
| 1831 | } |
| 1832 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1833 | 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] | 1834 | { |
| 1835 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1836 | struct nfs4_exception exception = { }; |
| 1837 | int err; |
| 1838 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1839 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1840 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1841 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1842 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1843 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1844 | break; |
| 1845 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | } while (exception.retry); |
| 1847 | return err; |
| 1848 | } |
| 1849 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1850 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1851 | { |
| 1852 | struct nfs_open_context *ctx; |
| 1853 | int ret; |
| 1854 | |
| 1855 | ctx = nfs4_state_find_open_context(state); |
| 1856 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1857 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1858 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1859 | put_nfs_open_context(ctx); |
| 1860 | return ret; |
| 1861 | } |
| 1862 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1863 | 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] | 1864 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1865 | switch (err) { |
| 1866 | default: |
| 1867 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1868 | "%d.\n", __func__, err); |
| 1869 | case 0: |
| 1870 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1871 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1872 | case -ESTALE: |
| 1873 | break; |
| 1874 | case -NFS4ERR_BADSESSION: |
| 1875 | case -NFS4ERR_BADSLOT: |
| 1876 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1877 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1878 | case -NFS4ERR_DEADSESSION: |
| 1879 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1880 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1881 | return -EAGAIN; |
| 1882 | case -NFS4ERR_STALE_CLIENTID: |
| 1883 | case -NFS4ERR_STALE_STATEID: |
| 1884 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1885 | /* Don't recall a delegation if it was lost */ |
| 1886 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1887 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1888 | case -NFS4ERR_MOVED: |
| 1889 | nfs4_schedule_migration_recovery(server); |
| 1890 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1891 | case -NFS4ERR_LEASE_MOVED: |
| 1892 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1893 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1894 | case -NFS4ERR_DELEG_REVOKED: |
| 1895 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1896 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1897 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1898 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1899 | nfs_inode_find_state_and_recover(state->inode, |
| 1900 | stateid); |
| 1901 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1902 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1903 | case -NFS4ERR_DELAY: |
| 1904 | case -NFS4ERR_GRACE: |
| 1905 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1906 | ssleep(1); |
| 1907 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1908 | case -ENOMEM: |
| 1909 | case -NFS4ERR_DENIED: |
| 1910 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1911 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | return err; |
| 1914 | } |
| 1915 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1916 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1917 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1918 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1919 | { |
| 1920 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1921 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1922 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1923 | |
| 1924 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1925 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1926 | if (IS_ERR(opendata)) |
| 1927 | return PTR_ERR(opendata); |
| 1928 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1929 | write_seqlock(&state->seqlock); |
| 1930 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1931 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1932 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1933 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1934 | case FMODE_READ|FMODE_WRITE: |
| 1935 | case FMODE_WRITE: |
| 1936 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1937 | if (err) |
| 1938 | break; |
| 1939 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1940 | if (err) |
| 1941 | break; |
| 1942 | case FMODE_READ: |
| 1943 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1944 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1945 | nfs4_opendata_put(opendata); |
| 1946 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1947 | } |
| 1948 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1949 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1950 | { |
| 1951 | struct nfs4_opendata *data = calldata; |
| 1952 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1953 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 1954 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1955 | } |
| 1956 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1957 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1958 | { |
| 1959 | struct nfs4_opendata *data = calldata; |
| 1960 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1961 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1962 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1963 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1964 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1965 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1966 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1967 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1968 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1969 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | static void nfs4_open_confirm_release(void *calldata) |
| 1973 | { |
| 1974 | struct nfs4_opendata *data = calldata; |
| 1975 | struct nfs4_state *state = NULL; |
| 1976 | |
| 1977 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1978 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1979 | goto out_free; |
| 1980 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1981 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1982 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1983 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1984 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1985 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1986 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1987 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1991 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1992 | .rpc_call_done = nfs4_open_confirm_done, |
| 1993 | .rpc_release = nfs4_open_confirm_release, |
| 1994 | }; |
| 1995 | |
| 1996 | /* |
| 1997 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1998 | */ |
| 1999 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2000 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2001 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2002 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2003 | struct rpc_message msg = { |
| 2004 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2005 | .rpc_argp = &data->c_arg, |
| 2006 | .rpc_resp = &data->c_res, |
| 2007 | .rpc_cred = data->owner->so_cred, |
| 2008 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2009 | struct rpc_task_setup task_setup_data = { |
| 2010 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2011 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2012 | .callback_ops = &nfs4_open_confirm_ops, |
| 2013 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2014 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2015 | .flags = RPC_TASK_ASYNC, |
| 2016 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | int status; |
| 2018 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2019 | 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] | 2020 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2021 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2022 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2023 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2024 | if (data->is_recover) |
| 2025 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2026 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2027 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2028 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2029 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2030 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2031 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2032 | smp_wmb(); |
| 2033 | } else |
| 2034 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2035 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | return status; |
| 2037 | } |
| 2038 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2039 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2041 | struct nfs4_opendata *data = calldata; |
| 2042 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2043 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2044 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2045 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2046 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2047 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2048 | /* |
| 2049 | * Check if we still need to send an OPEN call, or if we can use |
| 2050 | * a delegation instead. |
| 2051 | */ |
| 2052 | if (data->state != NULL) { |
| 2053 | struct nfs_delegation *delegation; |
| 2054 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2055 | 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] | 2056 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2057 | rcu_read_lock(); |
| 2058 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2059 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2060 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2061 | rcu_read_unlock(); |
| 2062 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2063 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2064 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2065 | switch (claim) { |
| 2066 | default: |
| 2067 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2068 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2069 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2070 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2071 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2072 | case NFS4_OPEN_CLAIM_FH: |
| 2073 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2074 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2075 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2076 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2077 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2078 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2079 | &data->o_res.seq_res, |
| 2080 | task) != 0) |
| 2081 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2082 | |
| 2083 | /* Set the create mode (note dependency on the session type) */ |
| 2084 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2085 | if (data->o_arg.open_flags & O_EXCL) { |
| 2086 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2087 | if (nfs4_has_persistent_session(clp)) |
| 2088 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2089 | else if (clp->cl_mvops->minor_version > 0) |
| 2090 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2091 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2092 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2093 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2094 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2095 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2096 | out_no_action: |
| 2097 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2098 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2099 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2100 | } |
| 2101 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2102 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2103 | { |
| 2104 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2106 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2107 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2108 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2109 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2110 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2111 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2112 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2113 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2114 | case S_IFREG: |
| 2115 | break; |
| 2116 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2117 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2118 | break; |
| 2119 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2120 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2121 | break; |
| 2122 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2123 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2124 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2125 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2126 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2127 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2128 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2129 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2130 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2131 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2132 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2133 | static void nfs4_open_release(void *calldata) |
| 2134 | { |
| 2135 | struct nfs4_opendata *data = calldata; |
| 2136 | struct nfs4_state *state = NULL; |
| 2137 | |
| 2138 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2139 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2140 | goto out_free; |
| 2141 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2142 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2143 | goto out_free; |
| 2144 | /* In case we need an open_confirm, no cleanup! */ |
| 2145 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2146 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2147 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2148 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2149 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2150 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2151 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2155 | .rpc_call_prepare = nfs4_open_prepare, |
| 2156 | .rpc_call_done = nfs4_open_done, |
| 2157 | .rpc_release = nfs4_open_release, |
| 2158 | }; |
| 2159 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2160 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2161 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2162 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2163 | struct nfs_server *server = NFS_SERVER(dir); |
| 2164 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2165 | struct nfs_openres *o_res = &data->o_res; |
| 2166 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2167 | struct rpc_message msg = { |
| 2168 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2169 | .rpc_argp = o_arg, |
| 2170 | .rpc_resp = o_res, |
| 2171 | .rpc_cred = data->owner->so_cred, |
| 2172 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2173 | struct rpc_task_setup task_setup_data = { |
| 2174 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2175 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2176 | .callback_ops = &nfs4_open_ops, |
| 2177 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2178 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2179 | .flags = RPC_TASK_ASYNC, |
| 2180 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2181 | int status; |
| 2182 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2183 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2184 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2185 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2186 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2187 | data->cancelled = false; |
| 2188 | data->is_recover = false; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2189 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2190 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2191 | data->is_recover = true; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2192 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2193 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2194 | if (IS_ERR(task)) |
| 2195 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2196 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2197 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2198 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2199 | smp_wmb(); |
| 2200 | } else |
| 2201 | status = data->rpc_status; |
| 2202 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2203 | |
| 2204 | return status; |
| 2205 | } |
| 2206 | |
| 2207 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2208 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2209 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2210 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2211 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2212 | |
| 2213 | status = nfs4_run_open_task(data, 1); |
| 2214 | if (status != 0 || !data->rpc_done) |
| 2215 | return status; |
| 2216 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2217 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2218 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2219 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2220 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2221 | |
| 2222 | return status; |
| 2223 | } |
| 2224 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2225 | /* |
| 2226 | * Additional permission checks in order to distinguish between an |
| 2227 | * open for read, and an open for execute. This works around the |
| 2228 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2229 | * the same. |
| 2230 | * Note that in the non-execute case, we want to turn off permission |
| 2231 | * checking if we just created a new file (POSIX open() semantics). |
| 2232 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2233 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2234 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2235 | struct nfs4_state *state, fmode_t fmode, |
| 2236 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2237 | { |
| 2238 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2239 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2240 | |
| 2241 | /* access call failed or for some reason the server doesn't |
| 2242 | * support any access modes -- defer access call until later */ |
| 2243 | if (opendata->o_res.access_supported == 0) |
| 2244 | return 0; |
| 2245 | |
| 2246 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2247 | /* |
| 2248 | * Use openflags to check for exec, because fmode won't |
| 2249 | * always have FMODE_EXEC set when file open for exec. |
| 2250 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2251 | if (openflags & __FMODE_EXEC) { |
| 2252 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2253 | if (S_ISDIR(state->inode->i_mode)) |
| 2254 | mask = NFS4_ACCESS_LOOKUP; |
| 2255 | else |
| 2256 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2257 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2258 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2259 | |
| 2260 | cache.cred = cred; |
| 2261 | cache.jiffies = jiffies; |
| 2262 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2263 | nfs_access_add_cache(state->inode, &cache); |
| 2264 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2265 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2266 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2267 | return 0; |
| 2268 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2269 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2270 | } |
| 2271 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2272 | /* |
| 2273 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2274 | */ |
| 2275 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2276 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2277 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2278 | struct nfs_server *server = NFS_SERVER(dir); |
| 2279 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2280 | struct nfs_openres *o_res = &data->o_res; |
| 2281 | int status; |
| 2282 | |
| 2283 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2284 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2285 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2286 | if (status != 0) { |
| 2287 | if (status == -NFS4ERR_BADNAME && |
| 2288 | !(o_arg->open_flags & O_CREAT)) |
| 2289 | return -ENOENT; |
| 2290 | return status; |
| 2291 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2292 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2293 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2294 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2295 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2296 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2297 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2298 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2299 | data->file_created = true; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2300 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2301 | update_changeattr(dir, &o_res->cinfo, |
| 2302 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2303 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2304 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2305 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2307 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2309 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2311 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2312 | nfs4_sequence_free_slot(&o_res->seq_res); |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2313 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2314 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2315 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | /* |
| 2319 | * OPEN_EXPIRED: |
| 2320 | * reclaim state on the server after a network partition. |
| 2321 | * Assumes caller holds the appropriate lock |
| 2322 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2323 | 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] | 2324 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2325 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2326 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2328 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2329 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2330 | if (IS_ERR(opendata)) |
| 2331 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2332 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2333 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2334 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2335 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2336 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2339 | 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] | 2340 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2341 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2342 | struct nfs4_exception exception = { }; |
| 2343 | int err; |
| 2344 | |
| 2345 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2346 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2347 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2348 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2349 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2350 | switch (err) { |
| 2351 | default: |
| 2352 | goto out; |
| 2353 | case -NFS4ERR_GRACE: |
| 2354 | case -NFS4ERR_DELAY: |
| 2355 | nfs4_handle_exception(server, err, &exception); |
| 2356 | err = 0; |
| 2357 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2358 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2359 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2360 | return err; |
| 2361 | } |
| 2362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2364 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2366 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2368 | ctx = nfs4_state_find_open_context(state); |
| 2369 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2370 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2371 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2372 | put_nfs_open_context(ctx); |
| 2373 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2376 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2377 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2378 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2379 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2380 | write_seqlock(&state->seqlock); |
| 2381 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2382 | write_sequnlock(&state->seqlock); |
| 2383 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2384 | } |
| 2385 | |
| 2386 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2387 | { |
| 2388 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2389 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2393 | { |
| 2394 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2395 | nfs40_clear_delegation_stateid(state); |
| 2396 | return nfs4_open_expired(sp, state); |
| 2397 | } |
| 2398 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2399 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2400 | nfs4_stateid *stateid, |
| 2401 | struct rpc_cred *cred) |
| 2402 | { |
| 2403 | return -NFS4ERR_BAD_STATEID; |
| 2404 | } |
| 2405 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2406 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2407 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2408 | nfs4_stateid *stateid, |
| 2409 | struct rpc_cred *cred) |
| 2410 | { |
| 2411 | int status; |
| 2412 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2413 | switch (stateid->type) { |
| 2414 | default: |
| 2415 | break; |
| 2416 | case NFS4_INVALID_STATEID_TYPE: |
| 2417 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2418 | return -NFS4ERR_BAD_STATEID; |
| 2419 | case NFS4_REVOKED_STATEID_TYPE: |
| 2420 | goto out_free; |
| 2421 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2422 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2423 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2424 | switch (status) { |
| 2425 | case -NFS4ERR_EXPIRED: |
| 2426 | case -NFS4ERR_ADMIN_REVOKED: |
| 2427 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2428 | break; |
| 2429 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2430 | return status; |
| 2431 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2432 | out_free: |
| 2433 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2434 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2435 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2436 | } |
| 2437 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2438 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2439 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2440 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2441 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2442 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2443 | struct rpc_cred *cred; |
| 2444 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2445 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2446 | /* Get the delegation credential for use by test/free_stateid */ |
| 2447 | rcu_read_lock(); |
| 2448 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2449 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2450 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2451 | return; |
| 2452 | } |
| 2453 | |
| 2454 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2455 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2456 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2457 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2458 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2459 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2460 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2461 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2462 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2463 | cred = get_rpccred(delegation->cred); |
| 2464 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2465 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2466 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2467 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2468 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2469 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2470 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2474 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2475 | * |
| 2476 | * @state: NFSv4 state for an inode |
| 2477 | * |
| 2478 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2479 | * Otherwise a negative NFS4ERR value is returned. |
| 2480 | */ |
| 2481 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2482 | { |
| 2483 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2484 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2485 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2486 | |
| 2487 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2488 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2489 | |
| 2490 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2491 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2492 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2493 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2494 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2495 | atomic_inc(&lsp->ls_count); |
| 2496 | spin_unlock(&state->state_lock); |
| 2497 | |
| 2498 | nfs4_put_lock_state(prev); |
| 2499 | prev = lsp; |
| 2500 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2501 | status = nfs41_test_and_free_expired_stateid(server, |
| 2502 | &lsp->ls_stateid, |
| 2503 | cred); |
| 2504 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2505 | if (status == -NFS4ERR_EXPIRED || |
| 2506 | status == -NFS4ERR_BAD_STATEID) { |
| 2507 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2508 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2509 | if (!recover_lost_locks) |
| 2510 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2511 | } else if (status != NFS_OK) { |
| 2512 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2513 | nfs4_put_lock_state(prev); |
| 2514 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2515 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2516 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2517 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2518 | } |
| 2519 | spin_unlock(&state->state_lock); |
| 2520 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2521 | out: |
| 2522 | return ret; |
| 2523 | } |
| 2524 | |
| 2525 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2526 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2527 | * |
| 2528 | * @state: NFSv4 state for an inode |
| 2529 | * |
| 2530 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2531 | * Otherwise a negative NFS4ERR value is returned. |
| 2532 | */ |
| 2533 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2534 | { |
| 2535 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2536 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2537 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2538 | int status; |
| 2539 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2540 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2541 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2542 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2543 | return NFS_OK; |
| 2544 | return -NFS4ERR_OPENMODE; |
| 2545 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2546 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2547 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2548 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2549 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2550 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2551 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2552 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2553 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2554 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2555 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2556 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2557 | if (status != NFS_OK) |
| 2558 | return status; |
| 2559 | if (nfs_open_stateid_recover_openmode(state)) |
| 2560 | return -NFS4ERR_OPENMODE; |
| 2561 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2565 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2566 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2567 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2568 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2569 | status = nfs41_check_expired_locks(state); |
| 2570 | if (status != NFS_OK) |
| 2571 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2572 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2573 | if (status != NFS_OK) |
| 2574 | status = nfs4_open_expired(sp, state); |
| 2575 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2576 | } |
| 2577 | #endif |
| 2578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2580 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2581 | * fields corresponding to attributes that were used to store the verifier. |
| 2582 | * Make sure we clobber those fields in the later setattr call |
| 2583 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2584 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2585 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2586 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2587 | const u32 *attrset = opendata->o_res.attrset; |
| 2588 | |
| 2589 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2590 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2591 | sattr->ia_valid |= ATTR_ATIME; |
| 2592 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2593 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2594 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2595 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2596 | |
| 2597 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2598 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
| 2599 | attrset[1] & FATTR4_WORD1_MODE) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2600 | sattr->ia_valid &= ~ATTR_MODE; |
| 2601 | |
| 2602 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2603 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2604 | } |
| 2605 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2606 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2607 | fmode_t fmode, |
| 2608 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2609 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2610 | { |
| 2611 | struct nfs4_state_owner *sp = opendata->owner; |
| 2612 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2613 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2614 | struct nfs4_state *state; |
| 2615 | unsigned int seq; |
| 2616 | int ret; |
| 2617 | |
| 2618 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2619 | |
| 2620 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2621 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2622 | goto out; |
| 2623 | |
| 2624 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2625 | ret = PTR_ERR(state); |
| 2626 | if (IS_ERR(state)) |
| 2627 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2628 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2629 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2630 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2631 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2632 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2633 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2634 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2635 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2636 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2637 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2638 | alias = d_exact_alias(dentry, state->inode); |
| 2639 | if (!alias) |
| 2640 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2641 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2642 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2643 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2644 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2645 | } |
| 2646 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2647 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2648 | } |
| 2649 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2650 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2651 | if (ret != 0) |
| 2652 | goto out; |
| 2653 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2654 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2655 | nfs_inode_attach_open_context(ctx); |
| 2656 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2657 | nfs4_schedule_stateid_recovery(server, state); |
| 2658 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2659 | out: |
| 2660 | return ret; |
| 2661 | } |
| 2662 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2663 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2664 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2666 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2667 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2668 | int flags, |
| 2669 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2670 | struct nfs4_label *label, |
| 2671 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | { |
| 2673 | struct nfs4_state_owner *sp; |
| 2674 | struct nfs4_state *state = NULL; |
| 2675 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2676 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2677 | struct dentry *dentry = ctx->dentry; |
| 2678 | struct rpc_cred *cred = ctx->cred; |
| 2679 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2680 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2681 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2682 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2683 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | |
| 2685 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2687 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2688 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2690 | goto out_err; |
| 2691 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2692 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2693 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2694 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2695 | if (d_really_is_positive(dentry)) |
| 2696 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2697 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2698 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2699 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2700 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2701 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2702 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2703 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2705 | if (label) { |
| 2706 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2707 | if (IS_ERR(olabel)) { |
| 2708 | status = PTR_ERR(olabel); |
| 2709 | goto err_opendata_put; |
| 2710 | } |
| 2711 | } |
| 2712 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2713 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2714 | if (!opendata->f_attr.mdsthreshold) { |
| 2715 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2716 | if (!opendata->f_attr.mdsthreshold) |
| 2717 | goto err_free_label; |
| 2718 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2719 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2720 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2721 | if (d_really_is_positive(dentry)) |
| 2722 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2723 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2724 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2725 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2726 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2727 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2728 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2729 | if ((opendata->o_arg.open_flags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL) && |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2730 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2731 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2732 | /* |
| 2733 | * send create attributes which was not set by open |
| 2734 | * with an extra setattr. |
| 2735 | */ |
| 2736 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2737 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2738 | status = nfs4_do_setattr(state->inode, cred, |
| 2739 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2740 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2741 | if (status == 0) { |
| 2742 | nfs_setattr_update_inode(state->inode, sattr, |
| 2743 | opendata->o_res.f_attr); |
| 2744 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2745 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2746 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2747 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2748 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2749 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2750 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2751 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2752 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2753 | opendata->f_attr.mdsthreshold = NULL; |
| 2754 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2755 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2756 | nfs4_label_free(olabel); |
| 2757 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2758 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2761 | err_free_label: |
| 2762 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2763 | err_opendata_put: |
| 2764 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2765 | err_put_state_owner: |
| 2766 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | return status; |
| 2769 | } |
| 2770 | |
| 2771 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2772 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2773 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2774 | int flags, |
| 2775 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2776 | struct nfs4_label *label, |
| 2777 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2779 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | struct nfs4_exception exception = { }; |
| 2781 | struct nfs4_state *res; |
| 2782 | int status; |
| 2783 | |
| 2784 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2785 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2786 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2787 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | if (status == 0) |
| 2789 | break; |
| 2790 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2791 | * book-keeping w.r.t. state-changing operations |
| 2792 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2793 | * It is actually a sign of a bug on the client or on the server. |
| 2794 | * |
| 2795 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2796 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | * have unhashed the old state_owner for us, and that we can |
| 2798 | * therefore safely retry using a new one. We should still warn |
| 2799 | * the user though... |
| 2800 | */ |
| 2801 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2802 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2803 | " returned a bad sequence-id error!\n", |
| 2804 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | exception.retry = 1; |
| 2806 | continue; |
| 2807 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2808 | /* |
| 2809 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2810 | * state before it received the OPEN_CONFIRM. |
| 2811 | * Recover by retrying the request as per the discussion |
| 2812 | * on Page 181 of RFC3530. |
| 2813 | */ |
| 2814 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2815 | exception.retry = 1; |
| 2816 | continue; |
| 2817 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2818 | if (status == -EAGAIN) { |
| 2819 | /* We must have found a delegation */ |
| 2820 | exception.retry = 1; |
| 2821 | continue; |
| 2822 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2823 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2824 | continue; |
| 2825 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | status, &exception)); |
| 2827 | } while (exception.retry); |
| 2828 | return res; |
| 2829 | } |
| 2830 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2831 | static int _nfs4_do_setattr(struct inode *inode, |
| 2832 | struct nfs_setattrargs *arg, |
| 2833 | struct nfs_setattrres *res, |
| 2834 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2835 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2836 | { |
| 2837 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2838 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2839 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2840 | .rpc_argp = arg, |
| 2841 | .rpc_resp = res, |
| 2842 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2843 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2844 | struct rpc_cred *delegation_cred = NULL; |
| 2845 | unsigned long timestamp = jiffies; |
| 2846 | fmode_t fmode; |
| 2847 | bool truncate; |
| 2848 | int status; |
| 2849 | |
| 2850 | nfs_fattr_init(res->fattr); |
| 2851 | |
| 2852 | /* Servers should only apply open mode checks for file size changes */ |
| 2853 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2854 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2855 | |
| 2856 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2857 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2858 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2859 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2860 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2861 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2862 | l_ctx = nfs_get_lock_context(ctx); |
| 2863 | if (IS_ERR(l_ctx)) |
| 2864 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2865 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2866 | &arg->stateid, &delegation_cred); |
| 2867 | nfs_put_lock_context(l_ctx); |
| 2868 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2869 | return -EBADF; |
| 2870 | } else |
| 2871 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2872 | if (delegation_cred) |
| 2873 | msg.rpc_cred = delegation_cred; |
| 2874 | |
| 2875 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2876 | |
| 2877 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2878 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2879 | renew_lease(server, timestamp); |
| 2880 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2881 | return status; |
| 2882 | } |
| 2883 | |
| 2884 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2885 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2886 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2887 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2889 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2890 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2891 | struct nfs_setattrargs arg = { |
| 2892 | .fh = NFS_FH(inode), |
| 2893 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | .server = server, |
| 2895 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2896 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2897 | }; |
| 2898 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2900 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2902 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2903 | struct nfs4_exception exception = { |
| 2904 | .state = state, |
| 2905 | .inode = inode, |
| 2906 | .stateid = &arg.stateid, |
| 2907 | }; |
| 2908 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2910 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2911 | if (ilabel) |
| 2912 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2915 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2916 | switch (err) { |
| 2917 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2918 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2919 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2920 | "applying open mode checks to " |
| 2921 | "a SETATTR that is not " |
| 2922 | "changing file size.\n", |
| 2923 | server->nfs_client->cl_hostname); |
| 2924 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2925 | if (state && !(state->state & FMODE_WRITE)) { |
| 2926 | err = -EBADF; |
| 2927 | if (sattr->ia_valid & ATTR_OPEN) |
| 2928 | err = -EACCES; |
| 2929 | goto out; |
| 2930 | } |
| 2931 | } |
| 2932 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2934 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | return err; |
| 2936 | } |
| 2937 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2938 | static bool |
| 2939 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2940 | { |
| 2941 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2942 | return false; |
| 2943 | |
| 2944 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2945 | } |
| 2946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | struct nfs4_closedata { |
| 2948 | struct inode *inode; |
| 2949 | struct nfs4_state *state; |
| 2950 | struct nfs_closeargs arg; |
| 2951 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2952 | struct { |
| 2953 | struct nfs4_layoutreturn_args arg; |
| 2954 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 2955 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2956 | u32 roc_barrier; |
| 2957 | bool roc; |
| 2958 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2959 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2960 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | }; |
| 2962 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2963 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2964 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2965 | struct nfs4_closedata *calldata = data; |
| 2966 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2967 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2968 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2969 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 2970 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 2971 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2972 | nfs4_put_open_state(calldata->state); |
| 2973 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2974 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2975 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2976 | kfree(calldata); |
| 2977 | } |
| 2978 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2979 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2981 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2984 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2986 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2987 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2988 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2989 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2990 | |
| 2991 | /* Handle Layoutreturn errors */ |
| 2992 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 2993 | switch (calldata->res.lr_ret) { |
| 2994 | default: |
| 2995 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 2996 | break; |
| 2997 | case 0: |
| 2998 | calldata->arg.lr_args = NULL; |
| 2999 | calldata->res.lr_res = NULL; |
| 3000 | break; |
| 3001 | case -NFS4ERR_ADMIN_REVOKED: |
| 3002 | case -NFS4ERR_DELEG_REVOKED: |
| 3003 | case -NFS4ERR_EXPIRED: |
| 3004 | case -NFS4ERR_BAD_STATEID: |
| 3005 | case -NFS4ERR_OLD_STATEID: |
| 3006 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3007 | case -NFS4ERR_WRONG_CRED: |
| 3008 | calldata->arg.lr_args = NULL; |
| 3009 | calldata->res.lr_res = NULL; |
| 3010 | calldata->res.lr_ret = 0; |
| 3011 | rpc_restart_call_prepare(task); |
| 3012 | return; |
| 3013 | } |
| 3014 | } |
| 3015 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3016 | /* hmm. we are done with the inode, and in the process of freeing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | * the state_owner. we keep this around to process errors |
| 3018 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | switch (task->tk_status) { |
| 3020 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3021 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3022 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3023 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3024 | case -NFS4ERR_ACCESS: |
| 3025 | if (calldata->arg.bitmask != NULL) { |
| 3026 | calldata->arg.bitmask = NULL; |
| 3027 | calldata->res.fattr = NULL; |
| 3028 | task->tk_status = 0; |
| 3029 | rpc_restart_call_prepare(task); |
| 3030 | goto out_release; |
| 3031 | |
| 3032 | } |
| 3033 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3034 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3036 | case -NFS4ERR_EXPIRED: |
| 3037 | nfs4_free_revoked_stateid(server, |
| 3038 | &calldata->arg.stateid, |
| 3039 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3040 | case -NFS4ERR_OLD_STATEID: |
| 3041 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3042 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3043 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3044 | rpc_restart_call_prepare(task); |
| 3045 | goto out_release; |
| 3046 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3047 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3048 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3050 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3051 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3052 | goto out_release; |
| 3053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3055 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3056 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3057 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3058 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3059 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3060 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3063 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3065 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3066 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3067 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3068 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3069 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3070 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3071 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3072 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3073 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3074 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3075 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3076 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3077 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3078 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3079 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3080 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3081 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3082 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3083 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3084 | if (state->n_rdonly == 0) |
| 3085 | call_close |= is_rdonly; |
| 3086 | else if (is_rdonly) |
| 3087 | calldata->arg.fmode |= FMODE_READ; |
| 3088 | if (state->n_wronly == 0) |
| 3089 | call_close |= is_wronly; |
| 3090 | else if (is_wronly) |
| 3091 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3092 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3093 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3094 | } else if (is_rdwr) |
| 3095 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3096 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3097 | if (!nfs4_valid_open_stateid(state) || |
| 3098 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3099 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3100 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3101 | |
| 3102 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3103 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3104 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3105 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3106 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3107 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3108 | nfs_release_seqid(calldata->arg.seqid); |
| 3109 | goto out_wait; |
| 3110 | } |
| 3111 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3112 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3113 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3114 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3115 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3116 | /* Close-to-open cache consistency revalidation */ |
| 3117 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3118 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3119 | else |
| 3120 | calldata->arg.bitmask = NULL; |
| 3121 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3122 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3123 | calldata->arg.share_access = |
| 3124 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3125 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3126 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3127 | if (calldata->res.fattr == NULL) |
| 3128 | calldata->arg.bitmask = NULL; |
| 3129 | else if (calldata->arg.bitmask == NULL) |
| 3130 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3131 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3132 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3133 | &calldata->arg.seq_args, |
| 3134 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3135 | task) != 0) |
| 3136 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3137 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3138 | return; |
| 3139 | out_no_action: |
| 3140 | task->tk_action = NULL; |
| 3141 | out_wait: |
| 3142 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3145 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3146 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3147 | .rpc_call_done = nfs4_close_done, |
| 3148 | .rpc_release = nfs4_free_closedata, |
| 3149 | }; |
| 3150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | /* |
| 3152 | * It is possible for data to be read/written from a mem-mapped file |
| 3153 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3154 | * This means that we can't safely call nfsv4 close on a file until |
| 3155 | * the inode is cleared. This in turn means that we are not good |
| 3156 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3157 | * share state even when we are done with one of the three share |
| 3158 | * stateid's in the inode. |
| 3159 | * |
| 3160 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3161 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3162 | 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] | 3163 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3164 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3165 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3167 | struct nfs4_state_owner *sp = state->owner; |
| 3168 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3169 | struct rpc_message msg = { |
| 3170 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3171 | .rpc_cred = state->owner->so_cred, |
| 3172 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3173 | struct rpc_task_setup task_setup_data = { |
| 3174 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3175 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3176 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3177 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3178 | .flags = RPC_TASK_ASYNC, |
| 3179 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3180 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3182 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3183 | &task_setup_data.rpc_client, &msg); |
| 3184 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3185 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3187 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3188 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3189 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3191 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3193 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3194 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3195 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3196 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3197 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3198 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3199 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3200 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3201 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3202 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3203 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3204 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3205 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3206 | if (calldata->lr.roc) { |
| 3207 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3208 | calldata->res.lr_res = &calldata->lr.res; |
| 3209 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3210 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3211 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3212 | msg.rpc_argp = &calldata->arg; |
| 3213 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3214 | task_setup_data.callback_data = calldata; |
| 3215 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3216 | if (IS_ERR(task)) |
| 3217 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3218 | status = 0; |
| 3219 | if (wait) |
| 3220 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3221 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3222 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3223 | out_free_calldata: |
| 3224 | kfree(calldata); |
| 3225 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3226 | nfs4_put_open_state(state); |
| 3227 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3228 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3231 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3232 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3233 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3236 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3237 | |
| 3238 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3240 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3241 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3242 | |
| 3243 | nfs4_label_release_security(label); |
| 3244 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3245 | if (IS_ERR(state)) |
| 3246 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3247 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3250 | 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] | 3251 | { |
| 3252 | if (ctx->state == NULL) |
| 3253 | return; |
| 3254 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3255 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3256 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3257 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3260 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3261 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3262 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3265 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3266 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3267 | struct nfs4_server_caps_arg args = { |
| 3268 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3269 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3270 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | struct nfs4_server_caps_res res = {}; |
| 3272 | struct rpc_message msg = { |
| 3273 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3274 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | .rpc_resp = &res, |
| 3276 | }; |
| 3277 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3278 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3280 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3281 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3282 | FATTR4_WORD0_LINK_SUPPORT | |
| 3283 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3284 | FATTR4_WORD0_ACLSUPPORT; |
| 3285 | if (minorversion) |
| 3286 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3287 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3288 | 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] | 3289 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3290 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3291 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3292 | case 0: |
| 3293 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3294 | res.attr_bitmask[2] = 0; |
| 3295 | break; |
| 3296 | case 1: |
| 3297 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3298 | break; |
| 3299 | case 2: |
| 3300 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3301 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3303 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3304 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3305 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3306 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3307 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3308 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3309 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3310 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | server->caps |= NFS_CAP_ACLS; |
| 3312 | if (res.has_links != 0) |
| 3313 | server->caps |= NFS_CAP_HARDLINKS; |
| 3314 | if (res.has_symlinks != 0) |
| 3315 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3316 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3317 | server->caps |= NFS_CAP_FILEID; |
| 3318 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3319 | server->caps |= NFS_CAP_MODE; |
| 3320 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3321 | server->caps |= NFS_CAP_NLINK; |
| 3322 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3323 | server->caps |= NFS_CAP_OWNER; |
| 3324 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3325 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3326 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3327 | server->caps |= NFS_CAP_ATIME; |
| 3328 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3329 | server->caps |= NFS_CAP_CTIME; |
| 3330 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3331 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3332 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3333 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3334 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3335 | #endif |
| 3336 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3337 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3338 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3339 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3340 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3341 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3342 | 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] | 3343 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3344 | |
| 3345 | /* Avoid a regression due to buggy server */ |
| 3346 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3347 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3348 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3349 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3352 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | return status; |
| 3356 | } |
| 3357 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3358 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | { |
| 3360 | struct nfs4_exception exception = { }; |
| 3361 | int err; |
| 3362 | do { |
| 3363 | err = nfs4_handle_exception(server, |
| 3364 | _nfs4_server_capabilities(server, fhandle), |
| 3365 | &exception); |
| 3366 | } while (exception.retry); |
| 3367 | return err; |
| 3368 | } |
| 3369 | |
| 3370 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3371 | struct nfs_fsinfo *info) |
| 3372 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3373 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3375 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | }; |
| 3377 | struct nfs4_lookup_res res = { |
| 3378 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3379 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | .fh = fhandle, |
| 3381 | }; |
| 3382 | struct rpc_message msg = { |
| 3383 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3384 | .rpc_argp = &args, |
| 3385 | .rpc_resp = &res, |
| 3386 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3387 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3388 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3389 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3390 | /* |
| 3391 | * Process the label in the upcoming getfattr |
| 3392 | */ |
| 3393 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3394 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3395 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3396 | 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] | 3397 | } |
| 3398 | |
| 3399 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3400 | struct nfs_fsinfo *info) |
| 3401 | { |
| 3402 | struct nfs4_exception exception = { }; |
| 3403 | int err; |
| 3404 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3405 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3406 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3407 | switch (err) { |
| 3408 | case 0: |
| 3409 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3410 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3411 | default: |
| 3412 | err = nfs4_handle_exception(server, err, &exception); |
| 3413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3415 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | return err; |
| 3417 | } |
| 3418 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3419 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3420 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3421 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3422 | struct rpc_auth_create_args auth_args = { |
| 3423 | .pseudoflavor = flavor, |
| 3424 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3425 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3426 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3427 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3428 | if (IS_ERR(auth)) |
| 3429 | return -EACCES; |
| 3430 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3433 | /* |
| 3434 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3435 | * |
| 3436 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3437 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3438 | * |
| 3439 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3440 | * negative errno value. |
| 3441 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3442 | 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] | 3443 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3445 | /* Per 3530bis 15.33.5 */ |
| 3446 | static const rpc_authflavor_t flav_array[] = { |
| 3447 | RPC_AUTH_GSS_KRB5P, |
| 3448 | RPC_AUTH_GSS_KRB5I, |
| 3449 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3450 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3451 | RPC_AUTH_NULL, |
| 3452 | }; |
| 3453 | int status = -EPERM; |
| 3454 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3456 | if (server->auth_info.flavor_len > 0) { |
| 3457 | /* try each flavor specified by user */ |
| 3458 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3459 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3460 | server->auth_info.flavors[i]); |
| 3461 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3462 | continue; |
| 3463 | break; |
| 3464 | } |
| 3465 | } else { |
| 3466 | /* no flavors specified by user, try default list */ |
| 3467 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3468 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3469 | flav_array[i]); |
| 3470 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3471 | continue; |
| 3472 | break; |
| 3473 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3474 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3475 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3476 | /* |
| 3477 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3478 | * to access the mount. It could also mean that we tried to mount |
| 3479 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3480 | * existing mount programs don't handle -EACCES very well so it should |
| 3481 | * be mapped to -EPERM instead. |
| 3482 | */ |
| 3483 | if (status == -EACCES) |
| 3484 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3485 | return status; |
| 3486 | } |
| 3487 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3488 | /** |
| 3489 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3490 | * @server: initialized nfs_server handle |
| 3491 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3492 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3493 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3494 | * |
| 3495 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3496 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3497 | 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] | 3498 | struct nfs_fsinfo *info, |
| 3499 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3500 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3501 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3502 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3503 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3504 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3505 | |
| 3506 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3507 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3508 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | if (status == 0) |
| 3511 | status = nfs4_server_capabilities(server, fhandle); |
| 3512 | if (status == 0) |
| 3513 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3514 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3515 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3518 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3519 | struct nfs_fsinfo *info) |
| 3520 | { |
| 3521 | int error; |
| 3522 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3523 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3524 | |
| 3525 | error = nfs4_server_capabilities(server, mntfh); |
| 3526 | if (error < 0) { |
| 3527 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3528 | return error; |
| 3529 | } |
| 3530 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3531 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3532 | if (IS_ERR(label)) |
| 3533 | return PTR_ERR(label); |
| 3534 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3535 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3536 | if (error < 0) { |
| 3537 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3538 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3542 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3543 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3544 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3545 | err_free_label: |
| 3546 | nfs4_label_free(label); |
| 3547 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3548 | return error; |
| 3549 | } |
| 3550 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3551 | /* |
| 3552 | * Get locations and (maybe) other attributes of a referral. |
| 3553 | * Note that we'll actually follow the referral later when |
| 3554 | * we detect fsid mismatch in inode revalidation |
| 3555 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3556 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3557 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3558 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3559 | { |
| 3560 | int status = -ENOMEM; |
| 3561 | struct page *page = NULL; |
| 3562 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3563 | |
| 3564 | page = alloc_page(GFP_KERNEL); |
| 3565 | if (page == NULL) |
| 3566 | goto out; |
| 3567 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3568 | if (locations == NULL) |
| 3569 | goto out; |
| 3570 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3571 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3572 | if (status != 0) |
| 3573 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3574 | |
| 3575 | /* |
| 3576 | * If the fsid didn't change, this is a migration event, not a |
| 3577 | * referral. Cause us to drop into the exception handler, which |
| 3578 | * will kick off migration recovery. |
| 3579 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3580 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3581 | dprintk("%s: server did not return a different fsid for" |
| 3582 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3583 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3584 | goto out; |
| 3585 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3586 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3587 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3588 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3589 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3590 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3591 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3592 | out: |
| 3593 | if (page) |
| 3594 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3595 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3596 | return status; |
| 3597 | } |
| 3598 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3599 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3600 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | { |
| 3602 | struct nfs4_getattr_arg args = { |
| 3603 | .fh = fhandle, |
| 3604 | .bitmask = server->attr_bitmask, |
| 3605 | }; |
| 3606 | struct nfs4_getattr_res res = { |
| 3607 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3608 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | .server = server, |
| 3610 | }; |
| 3611 | struct rpc_message msg = { |
| 3612 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3613 | .rpc_argp = &args, |
| 3614 | .rpc_resp = &res, |
| 3615 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3616 | |
| 3617 | args.bitmask = nfs4_bitmask(server, label); |
| 3618 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3619 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3620 | 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] | 3621 | } |
| 3622 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3623 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3624 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | { |
| 3626 | struct nfs4_exception exception = { }; |
| 3627 | int err; |
| 3628 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3629 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3630 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3631 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | &exception); |
| 3633 | } while (exception.retry); |
| 3634 | return err; |
| 3635 | } |
| 3636 | |
| 3637 | /* |
| 3638 | * The file is not closed if it is opened due to the a request to change |
| 3639 | * the size of the file. The open call will not be needed once the |
| 3640 | * VFS layer lookup-intents are implemented. |
| 3641 | * |
| 3642 | * Close is called when the inode is destroyed. |
| 3643 | * If we haven't opened the file for O_WRONLY, we |
| 3644 | * need to in the size_change case to obtain a stateid. |
| 3645 | * |
| 3646 | * Got race? |
| 3647 | * Because OPEN is always done by name in nfsv4, it is |
| 3648 | * possible that we opened a different file by the same |
| 3649 | * name. We can recognize this race condition, but we |
| 3650 | * can't do anything about it besides returning an error. |
| 3651 | * |
| 3652 | * This will be fixed with VFS changes (lookup-intent). |
| 3653 | */ |
| 3654 | static int |
| 3655 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3656 | struct iattr *sattr) |
| 3657 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3658 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3659 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3660 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3661 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | int status; |
| 3663 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3664 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3665 | sattr->ia_valid & ATTR_SIZE && |
| 3666 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3667 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3668 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3669 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3671 | /* Deal with open(O_TRUNC) */ |
| 3672 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3673 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3674 | |
| 3675 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3676 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3677 | return 0; |
| 3678 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3679 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3680 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3681 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3682 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3683 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3684 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3685 | } |
| 3686 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3687 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3688 | if (IS_ERR(label)) |
| 3689 | return PTR_ERR(label); |
| 3690 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3691 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3692 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3693 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3694 | nfs_setsecurity(inode, fattr, label); |
| 3695 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3696 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | return status; |
| 3698 | } |
| 3699 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3700 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3701 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3702 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3703 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3704 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3705 | int status; |
| 3706 | struct nfs4_lookup_arg args = { |
| 3707 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3708 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3709 | .name = name, |
| 3710 | }; |
| 3711 | struct nfs4_lookup_res res = { |
| 3712 | .server = server, |
| 3713 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3714 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3715 | .fh = fhandle, |
| 3716 | }; |
| 3717 | struct rpc_message msg = { |
| 3718 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3719 | .rpc_argp = &args, |
| 3720 | .rpc_resp = &res, |
| 3721 | }; |
| 3722 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3723 | args.bitmask = nfs4_bitmask(server, label); |
| 3724 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3725 | nfs_fattr_init(fattr); |
| 3726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3728 | 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] | 3729 | dprintk("NFS reply lookup: %d\n", status); |
| 3730 | return status; |
| 3731 | } |
| 3732 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3733 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3734 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3735 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3736 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3737 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3738 | fattr->nlink = 2; |
| 3739 | } |
| 3740 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3741 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3742 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3743 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3744 | { |
| 3745 | struct nfs4_exception exception = { }; |
| 3746 | struct rpc_clnt *client = *clnt; |
| 3747 | int err; |
| 3748 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3749 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3750 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3751 | switch (err) { |
| 3752 | case -NFS4ERR_BADNAME: |
| 3753 | err = -ENOENT; |
| 3754 | goto out; |
| 3755 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3756 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3757 | if (err == -NFS4ERR_MOVED) |
| 3758 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3759 | goto out; |
| 3760 | case -NFS4ERR_WRONGSEC: |
| 3761 | err = -EPERM; |
| 3762 | if (client != *clnt) |
| 3763 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3764 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3765 | if (IS_ERR(client)) |
| 3766 | return PTR_ERR(client); |
| 3767 | |
| 3768 | exception.retry = 1; |
| 3769 | break; |
| 3770 | default: |
| 3771 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3772 | } |
| 3773 | } while (exception.retry); |
| 3774 | |
| 3775 | out: |
| 3776 | if (err == 0) |
| 3777 | *clnt = client; |
| 3778 | else if (client != *clnt) |
| 3779 | rpc_shutdown_client(client); |
| 3780 | |
| 3781 | return err; |
| 3782 | } |
| 3783 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3784 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3785 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3786 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3788 | int status; |
| 3789 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3790 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3791 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3792 | if (client != NFS_CLIENT(dir)) { |
| 3793 | rpc_shutdown_client(client); |
| 3794 | nfs_fixup_secinfo_attributes(fattr); |
| 3795 | } |
| 3796 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3799 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3800 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3801 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3802 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3803 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3804 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3805 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3806 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3807 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3808 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3809 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3810 | } |
| 3811 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 3812 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 3813 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3814 | struct nfs4_label *label) |
| 3815 | { |
| 3816 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 3817 | struct nfs_server *server = NFS_SERVER(inode); |
| 3818 | int status; |
| 3819 | struct nfs4_lookupp_arg args = { |
| 3820 | .bitmask = server->attr_bitmask, |
| 3821 | .fh = NFS_FH(inode), |
| 3822 | }; |
| 3823 | struct nfs4_lookupp_res res = { |
| 3824 | .server = server, |
| 3825 | .fattr = fattr, |
| 3826 | .label = label, |
| 3827 | .fh = fhandle, |
| 3828 | }; |
| 3829 | struct rpc_message msg = { |
| 3830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 3831 | .rpc_argp = &args, |
| 3832 | .rpc_resp = &res, |
| 3833 | }; |
| 3834 | |
| 3835 | args.bitmask = nfs4_bitmask(server, label); |
| 3836 | |
| 3837 | nfs_fattr_init(fattr); |
| 3838 | |
| 3839 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 3840 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 3841 | &res.seq_res, 0); |
| 3842 | dprintk("NFS reply lookupp: %d\n", status); |
| 3843 | return status; |
| 3844 | } |
| 3845 | |
| 3846 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 3847 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 3848 | { |
| 3849 | struct nfs4_exception exception = { }; |
| 3850 | int err; |
| 3851 | do { |
| 3852 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 3853 | trace_nfs4_lookupp(inode, err); |
| 3854 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 3855 | &exception); |
| 3856 | } while (exception.retry); |
| 3857 | return err; |
| 3858 | } |
| 3859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3861 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3862 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | struct nfs4_accessargs args = { |
| 3864 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3865 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3867 | struct nfs4_accessres res = { |
| 3868 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3869 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | struct rpc_message msg = { |
| 3871 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3872 | .rpc_argp = &args, |
| 3873 | .rpc_resp = &res, |
| 3874 | .rpc_cred = entry->cred, |
| 3875 | }; |
| 3876 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3877 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | |
| 3879 | /* |
| 3880 | * Determine which access bits we want to ask for... |
| 3881 | */ |
| 3882 | if (mode & MAY_READ) |
| 3883 | args.access |= NFS4_ACCESS_READ; |
| 3884 | if (S_ISDIR(inode->i_mode)) { |
| 3885 | if (mode & MAY_WRITE) |
| 3886 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3887 | if (mode & MAY_EXEC) |
| 3888 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3889 | } else { |
| 3890 | if (mode & MAY_WRITE) |
| 3891 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3892 | if (mode & MAY_EXEC) |
| 3893 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3894 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3895 | |
| 3896 | res.fattr = nfs_alloc_fattr(); |
| 3897 | if (res.fattr == NULL) |
| 3898 | return -ENOMEM; |
| 3899 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3900 | 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] | 3901 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3902 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3903 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3905 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | return status; |
| 3907 | } |
| 3908 | |
| 3909 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3910 | { |
| 3911 | struct nfs4_exception exception = { }; |
| 3912 | int err; |
| 3913 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3914 | err = _nfs4_proc_access(inode, entry); |
| 3915 | trace_nfs4_access(inode, err); |
| 3916 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | &exception); |
| 3918 | } while (exception.retry); |
| 3919 | return err; |
| 3920 | } |
| 3921 | |
| 3922 | /* |
| 3923 | * TODO: For the time being, we don't try to get any attributes |
| 3924 | * along with any of the zero-copy operations READ, READDIR, |
| 3925 | * READLINK, WRITE. |
| 3926 | * |
| 3927 | * In the case of the first three, we want to put the GETATTR |
| 3928 | * after the read-type operation -- this is because it is hard |
| 3929 | * to predict the length of a GETATTR response in v4, and thus |
| 3930 | * align the READ data correctly. This means that the GETATTR |
| 3931 | * may end up partially falling into the page cache, and we should |
| 3932 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3933 | * To do this efficiently, we need to know the total length |
| 3934 | * of data received, which doesn't seem to be available outside |
| 3935 | * of the RPC layer. |
| 3936 | * |
| 3937 | * In the case of WRITE, we also want to put the GETATTR after |
| 3938 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3939 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | * |
| 3941 | * Both of these changes to the XDR layer would in fact be quite |
| 3942 | * minor, but I decided to leave them for a subsequent patch. |
| 3943 | */ |
| 3944 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3945 | unsigned int pgbase, unsigned int pglen) |
| 3946 | { |
| 3947 | struct nfs4_readlink args = { |
| 3948 | .fh = NFS_FH(inode), |
| 3949 | .pgbase = pgbase, |
| 3950 | .pglen = pglen, |
| 3951 | .pages = &page, |
| 3952 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3953 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | struct rpc_message msg = { |
| 3955 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3956 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3957 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | }; |
| 3959 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3960 | 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] | 3961 | } |
| 3962 | |
| 3963 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3964 | unsigned int pgbase, unsigned int pglen) |
| 3965 | { |
| 3966 | struct nfs4_exception exception = { }; |
| 3967 | int err; |
| 3968 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3969 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3970 | trace_nfs4_readlink(inode, err); |
| 3971 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | &exception); |
| 3973 | } while (exception.retry); |
| 3974 | return err; |
| 3975 | } |
| 3976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3978 | * 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] | 3979 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | static int |
| 3981 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3982 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3984 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3985 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3986 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | int status = 0; |
| 3989 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3990 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3991 | if (IS_ERR(ctx)) |
| 3992 | return PTR_ERR(ctx); |
| 3993 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3994 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3995 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3996 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 3997 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3998 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | if (IS_ERR(state)) { |
| 4000 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4001 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4004 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4005 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | return status; |
| 4007 | } |
| 4008 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4009 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4011 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4012 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4014 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4016 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4017 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4018 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4020 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4021 | .rpc_argp = &args, |
| 4022 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4024 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4025 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4026 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4027 | 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] | 4028 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4029 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | return status; |
| 4031 | } |
| 4032 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4033 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | { |
| 4035 | struct nfs4_exception exception = { }; |
| 4036 | int err; |
| 4037 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4038 | err = _nfs4_proc_remove(dir, name); |
| 4039 | trace_nfs4_remove(dir, name, err); |
| 4040 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | &exception); |
| 4042 | } while (exception.retry); |
| 4043 | return err; |
| 4044 | } |
| 4045 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4046 | 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] | 4047 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4048 | struct nfs_server *server = NFS_SERVER(dir); |
| 4049 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4050 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4052 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4054 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4055 | |
| 4056 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4059 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4060 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4061 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4062 | &data->args.seq_args, |
| 4063 | &data->res.seq_res, |
| 4064 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4067 | 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] | 4068 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4069 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4070 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4071 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4072 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4073 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4074 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4075 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4076 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4077 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4078 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4079 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4082 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4083 | { |
| 4084 | struct nfs_server *server = NFS_SERVER(dir); |
| 4085 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4086 | struct nfs_renameres *res = msg->rpc_resp; |
| 4087 | |
| 4088 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4089 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4090 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4091 | } |
| 4092 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4093 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4094 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4095 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4096 | &data->args.seq_args, |
| 4097 | &data->res.seq_res, |
| 4098 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4102 | struct inode *new_dir) |
| 4103 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4104 | struct nfs_renamedata *data = task->tk_calldata; |
| 4105 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4106 | |
| 4107 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4108 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4109 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4110 | return 0; |
| 4111 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4112 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4113 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4114 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4115 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4116 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4117 | return 1; |
| 4118 | } |
| 4119 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4120 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4122 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | struct nfs4_link_arg arg = { |
| 4124 | .fh = NFS_FH(inode), |
| 4125 | .dir_fh = NFS_FH(dir), |
| 4126 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4127 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4129 | struct nfs4_link_res res = { |
| 4130 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4131 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4132 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | struct rpc_message msg = { |
| 4134 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4135 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4136 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4138 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4140 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4141 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4142 | goto out; |
| 4143 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4144 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4145 | if (IS_ERR(res.label)) { |
| 4146 | status = PTR_ERR(res.label); |
| 4147 | goto out; |
| 4148 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4149 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4150 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4151 | 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] | 4152 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4153 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4154 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4155 | if (!status) |
| 4156 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4157 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4158 | |
| 4159 | |
| 4160 | nfs4_label_free(res.label); |
| 4161 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4162 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4163 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | return status; |
| 4165 | } |
| 4166 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4167 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | { |
| 4169 | struct nfs4_exception exception = { }; |
| 4170 | int err; |
| 4171 | do { |
| 4172 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4173 | _nfs4_proc_link(inode, dir, name), |
| 4174 | &exception); |
| 4175 | } while (exception.retry); |
| 4176 | return err; |
| 4177 | } |
| 4178 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4179 | struct nfs4_createdata { |
| 4180 | struct rpc_message msg; |
| 4181 | struct nfs4_create_arg arg; |
| 4182 | struct nfs4_create_res res; |
| 4183 | struct nfs_fh fh; |
| 4184 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4185 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4186 | }; |
| 4187 | |
| 4188 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4189 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4190 | { |
| 4191 | struct nfs4_createdata *data; |
| 4192 | |
| 4193 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4194 | if (data != NULL) { |
| 4195 | struct nfs_server *server = NFS_SERVER(dir); |
| 4196 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4197 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4198 | if (IS_ERR(data->label)) |
| 4199 | goto out_free; |
| 4200 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4201 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4202 | data->msg.rpc_argp = &data->arg; |
| 4203 | data->msg.rpc_resp = &data->res; |
| 4204 | data->arg.dir_fh = NFS_FH(dir); |
| 4205 | data->arg.server = server; |
| 4206 | data->arg.name = name; |
| 4207 | data->arg.attrs = sattr; |
| 4208 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4209 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4210 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4211 | data->res.server = server; |
| 4212 | data->res.fh = &data->fh; |
| 4213 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4214 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4215 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4216 | } |
| 4217 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4218 | out_free: |
| 4219 | kfree(data); |
| 4220 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4224 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4225 | 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] | 4226 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4227 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4228 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4229 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4230 | 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] | 4231 | } |
| 4232 | return status; |
| 4233 | } |
| 4234 | |
| 4235 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4236 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4237 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4238 | kfree(data); |
| 4239 | } |
| 4240 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4241 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4242 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4243 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4245 | struct nfs4_createdata *data; |
| 4246 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4248 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4249 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4250 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4251 | status = -ENOMEM; |
| 4252 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4253 | if (data == NULL) |
| 4254 | goto out; |
| 4255 | |
| 4256 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4257 | data->arg.u.symlink.pages = &page; |
| 4258 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4259 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4261 | status = nfs4_do_create(dir, dentry, data); |
| 4262 | |
| 4263 | nfs4_free_createdata(data); |
| 4264 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | return status; |
| 4266 | } |
| 4267 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4268 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4269 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | { |
| 4271 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4272 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4274 | |
| 4275 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4278 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4279 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4280 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | &exception); |
| 4282 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4283 | |
| 4284 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | return err; |
| 4286 | } |
| 4287 | |
| 4288 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4289 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4291 | struct nfs4_createdata *data; |
| 4292 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4294 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4295 | if (data == NULL) |
| 4296 | goto out; |
| 4297 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4298 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4299 | status = nfs4_do_create(dir, dentry, data); |
| 4300 | |
| 4301 | nfs4_free_createdata(data); |
| 4302 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | return status; |
| 4304 | } |
| 4305 | |
| 4306 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4307 | struct iattr *sattr) |
| 4308 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4309 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4311 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4313 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4314 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4315 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4316 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4317 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4319 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4320 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4321 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | &exception); |
| 4323 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4324 | nfs4_label_release_security(label); |
| 4325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | return err; |
| 4327 | } |
| 4328 | |
| 4329 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4330 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4332 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | struct nfs4_readdir_arg args = { |
| 4334 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4335 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | .pgbase = 0, |
| 4337 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4338 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4339 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | }; |
| 4341 | struct nfs4_readdir_res res; |
| 4342 | struct rpc_message msg = { |
| 4343 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4344 | .rpc_argp = &args, |
| 4345 | .rpc_resp = &res, |
| 4346 | .rpc_cred = cred, |
| 4347 | }; |
| 4348 | int status; |
| 4349 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4350 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4351 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4352 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4353 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4355 | 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] | 4356 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4357 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4358 | status += args.pgbase; |
| 4359 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4360 | |
| 4361 | nfs_invalidate_atime(dir); |
| 4362 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4363 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | return status; |
| 4365 | } |
| 4366 | |
| 4367 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4368 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | { |
| 4370 | struct nfs4_exception exception = { }; |
| 4371 | int err; |
| 4372 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4373 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4374 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4375 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4376 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | &exception); |
| 4378 | } while (exception.retry); |
| 4379 | return err; |
| 4380 | } |
| 4381 | |
| 4382 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4383 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4385 | struct nfs4_createdata *data; |
| 4386 | int mode = sattr->ia_mode; |
| 4387 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4389 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4390 | if (data == NULL) |
| 4391 | goto out; |
| 4392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4394 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4396 | data->arg.ftype = NF4BLK; |
| 4397 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4398 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | } |
| 4400 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4401 | data->arg.ftype = NF4CHR; |
| 4402 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4403 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4404 | } else if (!S_ISSOCK(mode)) { |
| 4405 | status = -EINVAL; |
| 4406 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4408 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4409 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4410 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4411 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4412 | nfs4_free_createdata(data); |
| 4413 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | return status; |
| 4415 | } |
| 4416 | |
| 4417 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4418 | struct iattr *sattr, dev_t rdev) |
| 4419 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4420 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4422 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4424 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4425 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4426 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4427 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4428 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4430 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4431 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4432 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | &exception); |
| 4434 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4435 | |
| 4436 | nfs4_label_release_security(label); |
| 4437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | return err; |
| 4439 | } |
| 4440 | |
| 4441 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4442 | struct nfs_fsstat *fsstat) |
| 4443 | { |
| 4444 | struct nfs4_statfs_arg args = { |
| 4445 | .fh = fhandle, |
| 4446 | .bitmask = server->attr_bitmask, |
| 4447 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4448 | struct nfs4_statfs_res res = { |
| 4449 | .fsstat = fsstat, |
| 4450 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | struct rpc_message msg = { |
| 4452 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4453 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4454 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | }; |
| 4456 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4457 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4458 | 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] | 4459 | } |
| 4460 | |
| 4461 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4462 | { |
| 4463 | struct nfs4_exception exception = { }; |
| 4464 | int err; |
| 4465 | do { |
| 4466 | err = nfs4_handle_exception(server, |
| 4467 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4468 | &exception); |
| 4469 | } while (exception.retry); |
| 4470 | return err; |
| 4471 | } |
| 4472 | |
| 4473 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4474 | struct nfs_fsinfo *fsinfo) |
| 4475 | { |
| 4476 | struct nfs4_fsinfo_arg args = { |
| 4477 | .fh = fhandle, |
| 4478 | .bitmask = server->attr_bitmask, |
| 4479 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4480 | struct nfs4_fsinfo_res res = { |
| 4481 | .fsinfo = fsinfo, |
| 4482 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | struct rpc_message msg = { |
| 4484 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4485 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4486 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | }; |
| 4488 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4489 | 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] | 4490 | } |
| 4491 | |
| 4492 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4493 | { |
| 4494 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4495 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | int err; |
| 4497 | |
| 4498 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4499 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4500 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4501 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4502 | nfs4_set_lease_period(server->nfs_client, |
| 4503 | fsinfo->lease_time * HZ, |
| 4504 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4505 | break; |
| 4506 | } |
| 4507 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | } while (exception.retry); |
| 4509 | return err; |
| 4510 | } |
| 4511 | |
| 4512 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4513 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4514 | int error; |
| 4515 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4516 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4517 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4518 | if (error == 0) { |
| 4519 | /* block layout checks this! */ |
| 4520 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4521 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4522 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4523 | |
| 4524 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4528 | struct nfs_pathconf *pathconf) |
| 4529 | { |
| 4530 | struct nfs4_pathconf_arg args = { |
| 4531 | .fh = fhandle, |
| 4532 | .bitmask = server->attr_bitmask, |
| 4533 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4534 | struct nfs4_pathconf_res res = { |
| 4535 | .pathconf = pathconf, |
| 4536 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | struct rpc_message msg = { |
| 4538 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4539 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4540 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | }; |
| 4542 | |
| 4543 | /* None of the pathconf attributes are mandatory to implement */ |
| 4544 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4545 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4546 | return 0; |
| 4547 | } |
| 4548 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4549 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4550 | 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] | 4551 | } |
| 4552 | |
| 4553 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4554 | struct nfs_pathconf *pathconf) |
| 4555 | { |
| 4556 | struct nfs4_exception exception = { }; |
| 4557 | int err; |
| 4558 | |
| 4559 | do { |
| 4560 | err = nfs4_handle_exception(server, |
| 4561 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4562 | &exception); |
| 4563 | } while (exception.retry); |
| 4564 | return err; |
| 4565 | } |
| 4566 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4567 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4568 | const struct nfs_open_context *ctx, |
| 4569 | const struct nfs_lock_context *l_ctx, |
| 4570 | fmode_t fmode) |
| 4571 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4572 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4573 | } |
| 4574 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4575 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4576 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4577 | const struct nfs_open_context *ctx, |
| 4578 | const struct nfs_lock_context *l_ctx, |
| 4579 | fmode_t fmode) |
| 4580 | { |
| 4581 | nfs4_stateid current_stateid; |
| 4582 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4583 | /* If the current stateid represents a lost lock, then exit */ |
| 4584 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4585 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4586 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4587 | } |
| 4588 | |
| 4589 | static bool nfs4_error_stateid_expired(int err) |
| 4590 | { |
| 4591 | switch (err) { |
| 4592 | case -NFS4ERR_DELEG_REVOKED: |
| 4593 | case -NFS4ERR_ADMIN_REVOKED: |
| 4594 | case -NFS4ERR_BAD_STATEID: |
| 4595 | case -NFS4ERR_STALE_STATEID: |
| 4596 | case -NFS4ERR_OLD_STATEID: |
| 4597 | case -NFS4ERR_OPENMODE: |
| 4598 | case -NFS4ERR_EXPIRED: |
| 4599 | return true; |
| 4600 | } |
| 4601 | return false; |
| 4602 | } |
| 4603 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4604 | 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] | 4605 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4606 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4608 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4609 | if (task->tk_status < 0) { |
| 4610 | struct nfs4_exception exception = { |
| 4611 | .inode = hdr->inode, |
| 4612 | .state = hdr->args.context->state, |
| 4613 | .stateid = &hdr->args.stateid, |
| 4614 | }; |
| 4615 | task->tk_status = nfs4_async_handle_exception(task, |
| 4616 | server, task->tk_status, &exception); |
| 4617 | if (exception.retry) { |
| 4618 | rpc_restart_call_prepare(task); |
| 4619 | return -EAGAIN; |
| 4620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4624 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4625 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | } |
| 4627 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4628 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4629 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4630 | { |
| 4631 | |
| 4632 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4633 | nfs4_stateid_is_current(&args->stateid, |
| 4634 | args->context, |
| 4635 | args->lock_context, |
| 4636 | FMODE_READ)) |
| 4637 | return false; |
| 4638 | rpc_restart_call_prepare(task); |
| 4639 | return true; |
| 4640 | } |
| 4641 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4642 | 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] | 4643 | { |
| 4644 | |
| 4645 | dprintk("--> %s\n", __func__); |
| 4646 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4647 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4648 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4649 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4650 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4651 | if (task->tk_status > 0) |
| 4652 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4653 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4654 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4657 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4658 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4660 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4661 | if (!hdr->pgio_done_cb) |
| 4662 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4663 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4664 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | } |
| 4666 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4667 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4668 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4669 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4670 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4671 | &hdr->args.seq_args, |
| 4672 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4673 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4674 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4675 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4676 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4677 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4678 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4679 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4680 | return -EIO; |
| 4681 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | } |
| 4683 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4684 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4685 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4686 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4687 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4688 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4689 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4690 | if (task->tk_status < 0) { |
| 4691 | struct nfs4_exception exception = { |
| 4692 | .inode = hdr->inode, |
| 4693 | .state = hdr->args.context->state, |
| 4694 | .stateid = &hdr->args.stateid, |
| 4695 | }; |
| 4696 | task->tk_status = nfs4_async_handle_exception(task, |
| 4697 | NFS_SERVER(inode), task->tk_status, |
| 4698 | &exception); |
| 4699 | if (exception.retry) { |
| 4700 | rpc_restart_call_prepare(task); |
| 4701 | return -EAGAIN; |
| 4702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4704 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4705 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4706 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4707 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4708 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 | } |
| 4710 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4711 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4712 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4713 | { |
| 4714 | |
| 4715 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4716 | nfs4_stateid_is_current(&args->stateid, |
| 4717 | args->context, |
| 4718 | args->lock_context, |
| 4719 | FMODE_WRITE)) |
| 4720 | return false; |
| 4721 | rpc_restart_call_prepare(task); |
| 4722 | return true; |
| 4723 | } |
| 4724 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4725 | 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] | 4726 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4727 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4728 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4729 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4730 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4731 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4732 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4735 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4736 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4737 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4738 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4739 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4740 | return false; |
| 4741 | /* Otherwise, request attributes if and only if we don't hold |
| 4742 | * a delegation |
| 4743 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4744 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4745 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4746 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4747 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4748 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4750 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4751 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4752 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4753 | hdr->args.bitmask = NULL; |
| 4754 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4755 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4756 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4757 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4758 | if (!hdr->pgio_done_cb) |
| 4759 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4760 | hdr->res.server = server; |
| 4761 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4763 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4764 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | } |
| 4766 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4767 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4768 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4769 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4770 | &data->args.seq_args, |
| 4771 | &data->res.seq_res, |
| 4772 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | } |
| 4774 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4775 | 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] | 4776 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4778 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4779 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4780 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4781 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4782 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4783 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4785 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4788 | 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] | 4789 | { |
| 4790 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4791 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4792 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4793 | } |
| 4794 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4795 | 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] | 4796 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4797 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4798 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4799 | if (data->commit_done_cb == NULL) |
| 4800 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4801 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4802 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4803 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | } |
| 4805 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4806 | struct nfs4_renewdata { |
| 4807 | struct nfs_client *client; |
| 4808 | unsigned long timestamp; |
| 4809 | }; |
| 4810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | /* |
| 4812 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4813 | * standalone procedure for queueing an asynchronous RENEW. |
| 4814 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4815 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4816 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4817 | struct nfs4_renewdata *data = calldata; |
| 4818 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4819 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4820 | if (atomic_read(&clp->cl_count) > 1) |
| 4821 | nfs4_schedule_state_renewal(clp); |
| 4822 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4823 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4824 | } |
| 4825 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4826 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4828 | struct nfs4_renewdata *data = calldata; |
| 4829 | struct nfs_client *clp = data->client; |
| 4830 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4832 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4833 | switch (task->tk_status) { |
| 4834 | case 0: |
| 4835 | break; |
| 4836 | case -NFS4ERR_LEASE_MOVED: |
| 4837 | nfs4_schedule_lease_moved_recovery(clp); |
| 4838 | break; |
| 4839 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4840 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4841 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4842 | return; |
| 4843 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4844 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4845 | return; |
| 4846 | } |
| 4847 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4849 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | } |
| 4851 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4852 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4853 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4854 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4855 | }; |
| 4856 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4857 | 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] | 4858 | { |
| 4859 | struct rpc_message msg = { |
| 4860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4861 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4862 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4864 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4866 | if (renew_flags == 0) |
| 4867 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4868 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4869 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4870 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 4871 | if (data == NULL) { |
| 4872 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4873 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 4874 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4875 | data->client = clp; |
| 4876 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4877 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4878 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | } |
| 4880 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4881 | 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] | 4882 | { |
| 4883 | struct rpc_message msg = { |
| 4884 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4885 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4886 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | }; |
| 4888 | unsigned long now = jiffies; |
| 4889 | int status; |
| 4890 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4891 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | if (status < 0) |
| 4893 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4894 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4895 | return 0; |
| 4896 | } |
| 4897 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4898 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4899 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4900 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4901 | } |
| 4902 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4903 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4904 | * 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] | 4905 | * the stack. |
| 4906 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4907 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4908 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4909 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4910 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4911 | { |
| 4912 | struct page *newpage, **spages; |
| 4913 | int rc = 0; |
| 4914 | size_t len; |
| 4915 | spages = pages; |
| 4916 | |
| 4917 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4918 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4919 | newpage = alloc_page(GFP_KERNEL); |
| 4920 | |
| 4921 | if (newpage == NULL) |
| 4922 | goto unwind; |
| 4923 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 4924 | buf += len; |
| 4925 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4926 | *pages++ = newpage; |
| 4927 | rc++; |
| 4928 | } while (buflen != 0); |
| 4929 | |
| 4930 | return rc; |
| 4931 | |
| 4932 | unwind: |
| 4933 | for(; rc > 0; rc--) |
| 4934 | __free_page(spages[rc-1]); |
| 4935 | return -ENOMEM; |
| 4936 | } |
| 4937 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4938 | struct nfs4_cached_acl { |
| 4939 | int cached; |
| 4940 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4941 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4942 | }; |
| 4943 | |
| 4944 | 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] | 4945 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4946 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4947 | |
| 4948 | spin_lock(&inode->i_lock); |
| 4949 | kfree(nfsi->nfs4_acl); |
| 4950 | nfsi->nfs4_acl = acl; |
| 4951 | spin_unlock(&inode->i_lock); |
| 4952 | } |
| 4953 | |
| 4954 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4955 | { |
| 4956 | nfs4_set_cached_acl(inode, NULL); |
| 4957 | } |
| 4958 | |
| 4959 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4960 | { |
| 4961 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4962 | struct nfs4_cached_acl *acl; |
| 4963 | int ret = -ENOENT; |
| 4964 | |
| 4965 | spin_lock(&inode->i_lock); |
| 4966 | acl = nfsi->nfs4_acl; |
| 4967 | if (acl == NULL) |
| 4968 | goto out; |
| 4969 | if (buf == NULL) /* user is just asking for length */ |
| 4970 | goto out_len; |
| 4971 | if (acl->cached == 0) |
| 4972 | goto out; |
| 4973 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4974 | if (acl->len > buflen) |
| 4975 | goto out; |
| 4976 | memcpy(buf, acl->data, acl->len); |
| 4977 | out_len: |
| 4978 | ret = acl->len; |
| 4979 | out: |
| 4980 | spin_unlock(&inode->i_lock); |
| 4981 | return ret; |
| 4982 | } |
| 4983 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4984 | 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] | 4985 | { |
| 4986 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4987 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4988 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4989 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4990 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4991 | if (acl == NULL) |
| 4992 | goto out; |
| 4993 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4994 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4995 | } else { |
| 4996 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4997 | if (acl == NULL) |
| 4998 | goto out; |
| 4999 | acl->cached = 0; |
| 5000 | } |
| 5001 | acl->len = acl_len; |
| 5002 | out: |
| 5003 | nfs4_set_cached_acl(inode, acl); |
| 5004 | } |
| 5005 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5006 | /* |
| 5007 | * The getxattr API returns the required buffer length when called with a |
| 5008 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5009 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5010 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5011 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5012 | * the cache. If not so, we throw away the page, and cache the required |
| 5013 | * length. The next getxattr call will then produce another round trip to |
| 5014 | * the server, this time with the input buf of the required size. |
| 5015 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5016 | 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] | 5017 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5018 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5019 | struct nfs_getaclargs args = { |
| 5020 | .fh = NFS_FH(inode), |
| 5021 | .acl_pages = pages, |
| 5022 | .acl_len = buflen, |
| 5023 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5024 | struct nfs_getaclres res = { |
| 5025 | .acl_len = buflen, |
| 5026 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5027 | struct rpc_message msg = { |
| 5028 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5029 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5030 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5031 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5032 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5033 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5034 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5035 | if (npages > ARRAY_SIZE(pages)) |
| 5036 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5037 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5038 | for (i = 0; i < npages; i++) { |
| 5039 | pages[i] = alloc_page(GFP_KERNEL); |
| 5040 | if (!pages[i]) |
| 5041 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5042 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5043 | |
| 5044 | /* for decoding across pages */ |
| 5045 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5046 | if (!res.acl_scratch) |
| 5047 | goto out_free; |
| 5048 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5049 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5050 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5051 | 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] | 5052 | __func__, buf, buflen, npages, args.acl_len); |
| 5053 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5054 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5055 | if (ret) |
| 5056 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5057 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5058 | /* Handle the case where the passed-in buffer is too short */ |
| 5059 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5060 | /* Did the user only issue a request for the acl length? */ |
| 5061 | if (buf == NULL) |
| 5062 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5063 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5064 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5065 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5066 | 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] | 5067 | if (buf) { |
| 5068 | if (res.acl_len > buflen) { |
| 5069 | ret = -ERANGE; |
| 5070 | goto out_free; |
| 5071 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5072 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5073 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5074 | out_ok: |
| 5075 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5076 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5077 | for (i = 0; i < npages; i++) |
| 5078 | if (pages[i]) |
| 5079 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5080 | if (res.acl_scratch) |
| 5081 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5082 | return ret; |
| 5083 | } |
| 5084 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5085 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5086 | { |
| 5087 | struct nfs4_exception exception = { }; |
| 5088 | ssize_t ret; |
| 5089 | do { |
| 5090 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5091 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5092 | if (ret >= 0) |
| 5093 | break; |
| 5094 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5095 | } while (exception.retry); |
| 5096 | return ret; |
| 5097 | } |
| 5098 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5099 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5100 | { |
| 5101 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5102 | int ret; |
| 5103 | |
| 5104 | if (!nfs4_server_supports_acls(server)) |
| 5105 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5106 | ret = nfs_revalidate_inode(server, inode); |
| 5107 | if (ret < 0) |
| 5108 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5109 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5110 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5111 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5112 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5113 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5114 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5115 | return ret; |
| 5116 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5117 | } |
| 5118 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5119 | 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] | 5120 | { |
| 5121 | struct nfs_server *server = NFS_SERVER(inode); |
| 5122 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5123 | struct nfs_setaclargs arg = { |
| 5124 | .fh = NFS_FH(inode), |
| 5125 | .acl_pages = pages, |
| 5126 | .acl_len = buflen, |
| 5127 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5128 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5129 | struct rpc_message msg = { |
| 5130 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5131 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5132 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5133 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5134 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5135 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5136 | |
| 5137 | if (!nfs4_server_supports_acls(server)) |
| 5138 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5139 | if (npages > ARRAY_SIZE(pages)) |
| 5140 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5141 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5142 | if (i < 0) |
| 5143 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5144 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5145 | 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] | 5146 | |
| 5147 | /* |
| 5148 | * Free each page after tx, so the only ref left is |
| 5149 | * held by the network stack |
| 5150 | */ |
| 5151 | for (; i > 0; i--) |
| 5152 | put_page(pages[i-1]); |
| 5153 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5154 | /* |
| 5155 | * Acl update can result in inode attribute update. |
| 5156 | * so mark the attribute cache invalid. |
| 5157 | */ |
| 5158 | spin_lock(&inode->i_lock); |
| 5159 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5160 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5161 | nfs_access_zap_cache(inode); |
| 5162 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5163 | return ret; |
| 5164 | } |
| 5165 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5166 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5167 | { |
| 5168 | struct nfs4_exception exception = { }; |
| 5169 | int err; |
| 5170 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5171 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5172 | trace_nfs4_set_acl(inode, err); |
| 5173 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5174 | &exception); |
| 5175 | } while (exception.retry); |
| 5176 | return err; |
| 5177 | } |
| 5178 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5179 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5180 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5181 | size_t buflen) |
| 5182 | { |
| 5183 | struct nfs_server *server = NFS_SERVER(inode); |
| 5184 | struct nfs_fattr fattr; |
| 5185 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5186 | |
| 5187 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5188 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5189 | .fh = NFS_FH(inode), |
| 5190 | .bitmask = bitmask, |
| 5191 | }; |
| 5192 | struct nfs4_getattr_res res = { |
| 5193 | .fattr = &fattr, |
| 5194 | .label = &label, |
| 5195 | .server = server, |
| 5196 | }; |
| 5197 | struct rpc_message msg = { |
| 5198 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5199 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5200 | .rpc_resp = &res, |
| 5201 | }; |
| 5202 | int ret; |
| 5203 | |
| 5204 | nfs_fattr_init(&fattr); |
| 5205 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5206 | 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] | 5207 | if (ret) |
| 5208 | return ret; |
| 5209 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5210 | return -ENOENT; |
| 5211 | if (buflen < label.len) |
| 5212 | return -ERANGE; |
| 5213 | return 0; |
| 5214 | } |
| 5215 | |
| 5216 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5217 | size_t buflen) |
| 5218 | { |
| 5219 | struct nfs4_exception exception = { }; |
| 5220 | int err; |
| 5221 | |
| 5222 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5223 | return -EOPNOTSUPP; |
| 5224 | |
| 5225 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5226 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5227 | trace_nfs4_get_security_label(inode, err); |
| 5228 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5229 | &exception); |
| 5230 | } while (exception.retry); |
| 5231 | return err; |
| 5232 | } |
| 5233 | |
| 5234 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5235 | struct nfs4_label *ilabel, |
| 5236 | struct nfs_fattr *fattr, |
| 5237 | struct nfs4_label *olabel) |
| 5238 | { |
| 5239 | |
| 5240 | struct iattr sattr = {0}; |
| 5241 | struct nfs_server *server = NFS_SERVER(inode); |
| 5242 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5243 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5244 | .fh = NFS_FH(inode), |
| 5245 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5246 | .server = server, |
| 5247 | .bitmask = bitmask, |
| 5248 | .label = ilabel, |
| 5249 | }; |
| 5250 | struct nfs_setattrres res = { |
| 5251 | .fattr = fattr, |
| 5252 | .label = olabel, |
| 5253 | .server = server, |
| 5254 | }; |
| 5255 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5257 | .rpc_argp = &arg, |
| 5258 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5259 | }; |
| 5260 | int status; |
| 5261 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5262 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5263 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5264 | 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] | 5265 | if (status) |
| 5266 | dprintk("%s failed: %d\n", __func__, status); |
| 5267 | |
| 5268 | return status; |
| 5269 | } |
| 5270 | |
| 5271 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5272 | struct nfs4_label *ilabel, |
| 5273 | struct nfs_fattr *fattr, |
| 5274 | struct nfs4_label *olabel) |
| 5275 | { |
| 5276 | struct nfs4_exception exception = { }; |
| 5277 | int err; |
| 5278 | |
| 5279 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5280 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5281 | fattr, olabel); |
| 5282 | trace_nfs4_set_security_label(inode, err); |
| 5283 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5284 | &exception); |
| 5285 | } while (exception.retry); |
| 5286 | return err; |
| 5287 | } |
| 5288 | |
| 5289 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5290 | nfs4_set_security_label(struct inode *inode, const void *buf, size_t buflen) |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5291 | { |
| 5292 | struct nfs4_label ilabel, *olabel = NULL; |
| 5293 | struct nfs_fattr fattr; |
| 5294 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5295 | int status; |
| 5296 | |
| 5297 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5298 | return -EOPNOTSUPP; |
| 5299 | |
| 5300 | nfs_fattr_init(&fattr); |
| 5301 | |
| 5302 | ilabel.pi = 0; |
| 5303 | ilabel.lfs = 0; |
| 5304 | ilabel.label = (char *)buf; |
| 5305 | ilabel.len = buflen; |
| 5306 | |
| 5307 | cred = rpc_lookup_cred(); |
| 5308 | if (IS_ERR(cred)) |
| 5309 | return PTR_ERR(cred); |
| 5310 | |
| 5311 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5312 | if (IS_ERR(olabel)) { |
| 5313 | status = -PTR_ERR(olabel); |
| 5314 | goto out; |
| 5315 | } |
| 5316 | |
| 5317 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5318 | if (status == 0) |
| 5319 | nfs_setsecurity(inode, &fattr, olabel); |
| 5320 | |
| 5321 | nfs4_label_free(olabel); |
| 5322 | out: |
| 5323 | put_rpccred(cred); |
| 5324 | return status; |
| 5325 | } |
| 5326 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5327 | |
| 5328 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5329 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5330 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5331 | { |
| 5332 | __be32 verf[2]; |
| 5333 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5334 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5335 | /* An impossible timestamp guarantees this value |
| 5336 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5337 | verf[0] = cpu_to_be32(U32_MAX); |
| 5338 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5339 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5340 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5341 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5342 | |
| 5343 | verf[0] = cpu_to_be32(ns >> 32); |
| 5344 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5345 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5346 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5347 | } |
| 5348 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5349 | static int |
| 5350 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5351 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5352 | size_t len; |
| 5353 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5354 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5355 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5356 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5357 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5358 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5359 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5360 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5361 | 1 + |
| 5362 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5363 | 1; |
| 5364 | rcu_read_unlock(); |
| 5365 | |
| 5366 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5367 | return -EINVAL; |
| 5368 | |
| 5369 | /* |
| 5370 | * Since this string is allocated at mount time, and held until the |
| 5371 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5372 | * about a memory-reclaim deadlock. |
| 5373 | */ |
| 5374 | str = kmalloc(len, GFP_KERNEL); |
| 5375 | if (!str) |
| 5376 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5377 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5378 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5379 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5380 | clp->cl_ipaddr, |
| 5381 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5382 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5383 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5384 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5385 | clp->cl_owner_id = str; |
| 5386 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5387 | } |
| 5388 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5389 | static int |
| 5390 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5391 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5392 | size_t len; |
| 5393 | char *str; |
| 5394 | |
| 5395 | len = 10 + 10 + 1 + 10 + 1 + |
| 5396 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5397 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5398 | |
| 5399 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5400 | return -EINVAL; |
| 5401 | |
| 5402 | /* |
| 5403 | * Since this string is allocated at mount time, and held until the |
| 5404 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5405 | * about a memory-reclaim deadlock. |
| 5406 | */ |
| 5407 | str = kmalloc(len, GFP_KERNEL); |
| 5408 | if (!str) |
| 5409 | return -ENOMEM; |
| 5410 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5411 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5412 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5413 | nfs4_client_id_uniquifier, |
| 5414 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5415 | clp->cl_owner_id = str; |
| 5416 | return 0; |
| 5417 | } |
| 5418 | |
| 5419 | static int |
| 5420 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5421 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5422 | size_t len; |
| 5423 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5424 | |
| 5425 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5426 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5427 | |
| 5428 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5429 | return nfs4_init_uniquifier_client_string(clp); |
| 5430 | |
| 5431 | len = 10 + 10 + 1 + 10 + 1 + |
| 5432 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5433 | |
| 5434 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5435 | return -EINVAL; |
| 5436 | |
| 5437 | /* |
| 5438 | * Since this string is allocated at mount time, and held until the |
| 5439 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5440 | * about a memory-reclaim deadlock. |
| 5441 | */ |
| 5442 | str = kmalloc(len, GFP_KERNEL); |
| 5443 | if (!str) |
| 5444 | return -ENOMEM; |
| 5445 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5446 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5447 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5448 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5449 | clp->cl_owner_id = str; |
| 5450 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5451 | } |
| 5452 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5453 | /* |
| 5454 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5455 | * services. Advertise one based on the address family of the |
| 5456 | * clientaddr. |
| 5457 | */ |
| 5458 | static unsigned int |
| 5459 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5460 | { |
| 5461 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5462 | return scnprintf(buf, len, "tcp6"); |
| 5463 | else |
| 5464 | return scnprintf(buf, len, "tcp"); |
| 5465 | } |
| 5466 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5467 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5468 | { |
| 5469 | struct nfs4_setclientid *sc = calldata; |
| 5470 | |
| 5471 | if (task->tk_status == 0) |
| 5472 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5473 | } |
| 5474 | |
| 5475 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5476 | .rpc_call_done = nfs4_setclientid_done, |
| 5477 | }; |
| 5478 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5479 | /** |
| 5480 | * nfs4_proc_setclientid - Negotiate client ID |
| 5481 | * @clp: state data structure |
| 5482 | * @program: RPC program for NFSv4 callback service |
| 5483 | * @port: IP port number for NFS4 callback service |
| 5484 | * @cred: RPC credential to use for this call |
| 5485 | * @res: where to place the result |
| 5486 | * |
| 5487 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5488 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5489 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5490 | unsigned short port, struct rpc_cred *cred, |
| 5491 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | { |
| 5493 | nfs4_verifier sc_verifier; |
| 5494 | struct nfs4_setclientid setclientid = { |
| 5495 | .sc_verifier = &sc_verifier, |
| 5496 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5497 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | }; |
| 5499 | struct rpc_message msg = { |
| 5500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5501 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5502 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5503 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5505 | struct rpc_task *task; |
| 5506 | struct rpc_task_setup task_setup_data = { |
| 5507 | .rpc_client = clp->cl_rpcclient, |
| 5508 | .rpc_message = &msg, |
| 5509 | .callback_ops = &nfs4_setclientid_ops, |
| 5510 | .callback_data = &setclientid, |
| 5511 | .flags = RPC_TASK_TIMEOUT, |
| 5512 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5513 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5515 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5516 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5517 | |
| 5518 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5519 | status = nfs4_init_uniform_client_string(clp); |
| 5520 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5521 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5522 | |
| 5523 | if (status) |
| 5524 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5525 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5526 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5527 | setclientid.sc_netid_len = |
| 5528 | nfs4_init_callback_netid(clp, |
| 5529 | setclientid.sc_netid, |
| 5530 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5531 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5532 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5534 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5535 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5536 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5537 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5538 | task = rpc_run_task(&task_setup_data); |
| 5539 | if (IS_ERR(task)) { |
| 5540 | status = PTR_ERR(task); |
| 5541 | goto out; |
| 5542 | } |
| 5543 | status = task->tk_status; |
| 5544 | if (setclientid.sc_cred) { |
| 5545 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5546 | put_rpccred(setclientid.sc_cred); |
| 5547 | } |
| 5548 | rpc_put_task(task); |
| 5549 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5550 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5551 | dprintk("NFS reply setclientid: %d\n", status); |
| 5552 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | } |
| 5554 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5555 | /** |
| 5556 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5557 | * @clp: state data structure |
| 5558 | * @res: result of a previous SETCLIENTID |
| 5559 | * @cred: RPC credential to use for this call |
| 5560 | * |
| 5561 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5562 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5563 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5564 | struct nfs4_setclientid_res *arg, |
| 5565 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | struct rpc_message msg = { |
| 5568 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5569 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5570 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | int status; |
| 5573 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5574 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5575 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5576 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5577 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5578 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5579 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | return status; |
| 5581 | } |
| 5582 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5583 | struct nfs4_delegreturndata { |
| 5584 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5585 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5586 | struct nfs_fh fh; |
| 5587 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5588 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5589 | struct { |
| 5590 | struct nfs4_layoutreturn_args arg; |
| 5591 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5592 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5593 | u32 roc_barrier; |
| 5594 | bool roc; |
| 5595 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5596 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5597 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5598 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5599 | }; |
| 5600 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5601 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5602 | { |
| 5603 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5604 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5605 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5606 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5607 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5608 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5609 | |
| 5610 | /* Handle Layoutreturn errors */ |
| 5611 | if (data->args.lr_args && task->tk_status != 0) { |
| 5612 | switch(data->res.lr_ret) { |
| 5613 | default: |
| 5614 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5615 | break; |
| 5616 | case 0: |
| 5617 | data->args.lr_args = NULL; |
| 5618 | data->res.lr_res = NULL; |
| 5619 | break; |
| 5620 | case -NFS4ERR_ADMIN_REVOKED: |
| 5621 | case -NFS4ERR_DELEG_REVOKED: |
| 5622 | case -NFS4ERR_EXPIRED: |
| 5623 | case -NFS4ERR_BAD_STATEID: |
| 5624 | case -NFS4ERR_OLD_STATEID: |
| 5625 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5626 | case -NFS4ERR_WRONG_CRED: |
| 5627 | data->args.lr_args = NULL; |
| 5628 | data->res.lr_res = NULL; |
| 5629 | data->res.lr_ret = 0; |
| 5630 | rpc_restart_call_prepare(task); |
| 5631 | return; |
| 5632 | } |
| 5633 | } |
| 5634 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5635 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5636 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5637 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5638 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5639 | case -NFS4ERR_ADMIN_REVOKED: |
| 5640 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5641 | case -NFS4ERR_EXPIRED: |
| 5642 | nfs4_free_revoked_stateid(data->res.server, |
| 5643 | data->args.stateid, |
| 5644 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5645 | case -NFS4ERR_BAD_STATEID: |
| 5646 | case -NFS4ERR_OLD_STATEID: |
| 5647 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5648 | task->tk_status = 0; |
| 5649 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5650 | case -NFS4ERR_ACCESS: |
| 5651 | if (data->args.bitmask) { |
| 5652 | data->args.bitmask = NULL; |
| 5653 | data->res.fattr = NULL; |
| 5654 | task->tk_status = 0; |
| 5655 | rpc_restart_call_prepare(task); |
| 5656 | return; |
| 5657 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5658 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5659 | if (nfs4_async_handle_error(task, data->res.server, |
| 5660 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5661 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5662 | return; |
| 5663 | } |
| 5664 | } |
| 5665 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | static void nfs4_delegreturn_release(void *calldata) |
| 5669 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5670 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5671 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5672 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5673 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5674 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5675 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5676 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5677 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5678 | nfs_iput_and_deactive(inode); |
| 5679 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5680 | kfree(calldata); |
| 5681 | } |
| 5682 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5683 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5684 | { |
| 5685 | struct nfs4_delegreturndata *d_data; |
| 5686 | |
| 5687 | d_data = (struct nfs4_delegreturndata *)data; |
| 5688 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5689 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5690 | return; |
| 5691 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5692 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5693 | &d_data->args.seq_args, |
| 5694 | &d_data->res.seq_res, |
| 5695 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5696 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5697 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5698 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5699 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5700 | .rpc_call_done = nfs4_delegreturn_done, |
| 5701 | .rpc_release = nfs4_delegreturn_release, |
| 5702 | }; |
| 5703 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5704 | 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] | 5705 | { |
| 5706 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5707 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5708 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5709 | struct rpc_message msg = { |
| 5710 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5711 | .rpc_cred = cred, |
| 5712 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5713 | struct rpc_task_setup task_setup_data = { |
| 5714 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5715 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5716 | .callback_ops = &nfs4_delegreturn_ops, |
| 5717 | .flags = RPC_TASK_ASYNC, |
| 5718 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5719 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5720 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5721 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5722 | if (data == NULL) |
| 5723 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5724 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5725 | |
| 5726 | nfs4_state_protect(server->nfs_client, |
| 5727 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5728 | &task_setup_data.rpc_client, &msg); |
| 5729 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5730 | data->args.fhandle = &data->fh; |
| 5731 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5732 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5733 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5734 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5735 | data->res.fattr = &data->fattr; |
| 5736 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5737 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5738 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5739 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5740 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5741 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5742 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, cred); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5743 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5744 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5745 | if (data->lr.roc) { |
| 5746 | data->args.lr_args = &data->lr.arg; |
| 5747 | data->res.lr_res = &data->lr.res; |
| 5748 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5749 | } else if (data->lr.roc) { |
| 5750 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5751 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5752 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5753 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5754 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5755 | msg.rpc_argp = &data->args; |
| 5756 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5757 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5758 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5759 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5760 | if (!issync) |
| 5761 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5762 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5763 | if (status != 0) |
| 5764 | goto out; |
| 5765 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5766 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5767 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5768 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | } |
| 5770 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5771 | 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] | 5772 | { |
| 5773 | struct nfs_server *server = NFS_SERVER(inode); |
| 5774 | struct nfs4_exception exception = { }; |
| 5775 | int err; |
| 5776 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5777 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5778 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5779 | switch (err) { |
| 5780 | case -NFS4ERR_STALE_STATEID: |
| 5781 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5782 | case 0: |
| 5783 | return 0; |
| 5784 | } |
| 5785 | err = nfs4_handle_exception(server, err, &exception); |
| 5786 | } while (exception.retry); |
| 5787 | return err; |
| 5788 | } |
| 5789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5790 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5791 | { |
| 5792 | struct inode *inode = state->inode; |
| 5793 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5794 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5795 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5797 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5798 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5799 | struct nfs_lockt_res res = { |
| 5800 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5801 | }; |
| 5802 | struct rpc_message msg = { |
| 5803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5804 | .rpc_argp = &arg, |
| 5805 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | .rpc_cred = state->owner->so_cred, |
| 5807 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | struct nfs4_lock_state *lsp; |
| 5809 | int status; |
| 5810 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5811 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5812 | status = nfs4_set_lock_state(state, request); |
| 5813 | if (status != 0) |
| 5814 | goto out; |
| 5815 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5816 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5817 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5818 | 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] | 5819 | switch (status) { |
| 5820 | case 0: |
| 5821 | request->fl_type = F_UNLCK; |
| 5822 | break; |
| 5823 | case -NFS4ERR_DENIED: |
| 5824 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5826 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5827 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5828 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | return status; |
| 5830 | } |
| 5831 | |
| 5832 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5833 | { |
| 5834 | struct nfs4_exception exception = { }; |
| 5835 | int err; |
| 5836 | |
| 5837 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5838 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5839 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5840 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | &exception); |
| 5842 | } while (exception.retry); |
| 5843 | return err; |
| 5844 | } |
| 5845 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5846 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5847 | struct nfs_locku_args arg; |
| 5848 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5849 | struct nfs4_lock_state *lsp; |
| 5850 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5851 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5852 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5853 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5854 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5855 | }; |
| 5856 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5857 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5858 | struct nfs_open_context *ctx, |
| 5859 | struct nfs4_lock_state *lsp, |
| 5860 | struct nfs_seqid *seqid) |
| 5861 | { |
| 5862 | struct nfs4_unlockdata *p; |
| 5863 | struct inode *inode = lsp->ls_state->inode; |
| 5864 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5865 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5866 | if (p == NULL) |
| 5867 | return NULL; |
| 5868 | p->arg.fh = NFS_FH(inode); |
| 5869 | p->arg.fl = &p->fl; |
| 5870 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5871 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5872 | p->lsp = lsp; |
| 5873 | atomic_inc(&lsp->ls_count); |
| 5874 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5875 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5876 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5877 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5878 | p->server = NFS_SERVER(inode); |
| 5879 | return p; |
| 5880 | } |
| 5881 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5882 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5883 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5884 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5885 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5886 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5887 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5888 | put_nfs_open_context(calldata->ctx); |
| 5889 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5892 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5893 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5894 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5895 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5896 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5897 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5898 | switch (task->tk_status) { |
| 5899 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5900 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5901 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5902 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5903 | &calldata->res.stateid)) |
| 5904 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5905 | case -NFS4ERR_ADMIN_REVOKED: |
| 5906 | case -NFS4ERR_EXPIRED: |
| 5907 | nfs4_free_revoked_stateid(calldata->server, |
| 5908 | &calldata->arg.stateid, |
| 5909 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5910 | case -NFS4ERR_BAD_STATEID: |
| 5911 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5912 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5913 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5914 | &calldata->lsp->ls_stateid)) |
| 5915 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5916 | break; |
| 5917 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5918 | if (nfs4_async_handle_error(task, calldata->server, |
| 5919 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5920 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5921 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5922 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5925 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5926 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5927 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5928 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5929 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 5930 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 5931 | return; |
| 5932 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5933 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5934 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5935 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5936 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5937 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5938 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5939 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5940 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5941 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5942 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5943 | &calldata->res.seq_res, |
| 5944 | task) != 0) |
| 5945 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5946 | return; |
| 5947 | out_no_action: |
| 5948 | task->tk_action = NULL; |
| 5949 | out_wait: |
| 5950 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5951 | } |
| 5952 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5953 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5954 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5955 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5956 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5957 | }; |
| 5958 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5959 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5960 | struct nfs_open_context *ctx, |
| 5961 | struct nfs4_lock_state *lsp, |
| 5962 | struct nfs_seqid *seqid) |
| 5963 | { |
| 5964 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5965 | struct rpc_message msg = { |
| 5966 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5967 | .rpc_cred = ctx->cred, |
| 5968 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5969 | struct rpc_task_setup task_setup_data = { |
| 5970 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5971 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5972 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5973 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5974 | .flags = RPC_TASK_ASYNC, |
| 5975 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5976 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5977 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5978 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5979 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5980 | /* Ensure this is an unlock - when canceling a lock, the |
| 5981 | * canceled lock is passed in, and it won't be an unlock. |
| 5982 | */ |
| 5983 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5984 | if (fl->fl_flags & FL_CLOSE) |
| 5985 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5986 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5987 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5988 | if (data == NULL) { |
| 5989 | nfs_free_seqid(seqid); |
| 5990 | return ERR_PTR(-ENOMEM); |
| 5991 | } |
| 5992 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5993 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5994 | msg.rpc_argp = &data->arg; |
| 5995 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5996 | task_setup_data.callback_data = data; |
| 5997 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5998 | } |
| 5999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6000 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6001 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6002 | struct inode *inode = state->inode; |
| 6003 | struct nfs4_state_owner *sp = state->owner; |
| 6004 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6005 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6006 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6007 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6008 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6009 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6010 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6011 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6012 | status = nfs4_set_lock_state(state, request); |
| 6013 | /* Unlock _before_ we do the RPC call */ |
| 6014 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6015 | /* Exclude nfs_delegation_claim_locks() */ |
| 6016 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6017 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6018 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6019 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6020 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6021 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6022 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6023 | } |
| 6024 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6025 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6026 | if (status != 0) |
| 6027 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6028 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6029 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6030 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6031 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6032 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6033 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6034 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6035 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6036 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6037 | 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] | 6038 | status = PTR_ERR(task); |
| 6039 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6040 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6041 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6042 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6043 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6044 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6045 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6046 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6047 | } |
| 6048 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6049 | struct nfs4_lockdata { |
| 6050 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6051 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6052 | struct nfs4_lock_state *lsp; |
| 6053 | struct nfs_open_context *ctx; |
| 6054 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6055 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6056 | int rpc_status; |
| 6057 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6058 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6059 | }; |
| 6060 | |
| 6061 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6062 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6063 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6064 | { |
| 6065 | struct nfs4_lockdata *p; |
| 6066 | struct inode *inode = lsp->ls_state->inode; |
| 6067 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6068 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6069 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6070 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6071 | if (p == NULL) |
| 6072 | return NULL; |
| 6073 | |
| 6074 | p->arg.fh = NFS_FH(inode); |
| 6075 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6076 | 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] | 6077 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6078 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6079 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6080 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6081 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6082 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6083 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6084 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6085 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6086 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6087 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6088 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6089 | atomic_inc(&lsp->ls_count); |
| 6090 | p->ctx = get_nfs_open_context(ctx); |
| 6091 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6092 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6093 | out_free_seqid: |
| 6094 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6095 | out_free: |
| 6096 | kfree(p); |
| 6097 | return NULL; |
| 6098 | } |
| 6099 | |
| 6100 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6101 | { |
| 6102 | struct nfs4_lockdata *data = calldata; |
| 6103 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6104 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6105 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6106 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6107 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6108 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6109 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6110 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6111 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6112 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6113 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6114 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6115 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6116 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6117 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6118 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6119 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6120 | &data->lsp->ls_stateid); |
| 6121 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6122 | if (!nfs4_valid_open_stateid(state)) { |
| 6123 | data->rpc_status = -EBADF; |
| 6124 | task->tk_action = NULL; |
| 6125 | goto out_release_open_seqid; |
| 6126 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6127 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6128 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6129 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6130 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6131 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6132 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6133 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6134 | nfs_release_seqid(data->arg.open_seqid); |
| 6135 | out_release_lock_seqid: |
| 6136 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6137 | out_wait: |
| 6138 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6139 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6140 | } |
| 6141 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6142 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6143 | { |
| 6144 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6145 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6146 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6147 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6148 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6149 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6150 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6151 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6152 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6153 | switch (task->tk_status) { |
| 6154 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6155 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6156 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6157 | if (data->arg.new_lock) { |
| 6158 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6159 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6160 | rpc_restart_call_prepare(task); |
| 6161 | break; |
| 6162 | } |
| 6163 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6164 | if (data->arg.new_lock_owner != 0) { |
| 6165 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6166 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6167 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6168 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6169 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6170 | break; |
| 6171 | case -NFS4ERR_BAD_STATEID: |
| 6172 | case -NFS4ERR_OLD_STATEID: |
| 6173 | case -NFS4ERR_STALE_STATEID: |
| 6174 | case -NFS4ERR_EXPIRED: |
| 6175 | if (data->arg.new_lock_owner != 0) { |
| 6176 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6177 | &lsp->ls_state->open_stateid)) |
| 6178 | rpc_restart_call_prepare(task); |
| 6179 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6180 | &lsp->ls_stateid)) |
| 6181 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6182 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6183 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | static void nfs4_lock_release(void *calldata) |
| 6187 | { |
| 6188 | struct nfs4_lockdata *data = calldata; |
| 6189 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6190 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6191 | nfs_free_seqid(data->arg.open_seqid); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6192 | if (data->cancelled) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6193 | struct rpc_task *task; |
| 6194 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6195 | data->arg.lock_seqid); |
| 6196 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6197 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6198 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6199 | } else |
| 6200 | nfs_free_seqid(data->arg.lock_seqid); |
| 6201 | nfs4_put_lock_state(data->lsp); |
| 6202 | put_nfs_open_context(data->ctx); |
| 6203 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6204 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6208 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6209 | .rpc_call_done = nfs4_lock_done, |
| 6210 | .rpc_release = nfs4_lock_release, |
| 6211 | }; |
| 6212 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6213 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6214 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6215 | switch (error) { |
| 6216 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6217 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6218 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6219 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6220 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6221 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6222 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6223 | break; |
| 6224 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6225 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6226 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6227 | }; |
| 6228 | } |
| 6229 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6230 | 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] | 6231 | { |
| 6232 | struct nfs4_lockdata *data; |
| 6233 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6234 | struct rpc_message msg = { |
| 6235 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6236 | .rpc_cred = state->owner->so_cred, |
| 6237 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6238 | struct rpc_task_setup task_setup_data = { |
| 6239 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6240 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6241 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6242 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6243 | .flags = RPC_TASK_ASYNC, |
| 6244 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6245 | int ret; |
| 6246 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6247 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6248 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6249 | fl->fl_u.nfs4_fl.owner, |
| 6250 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6251 | if (data == NULL) |
| 6252 | return -ENOMEM; |
| 6253 | if (IS_SETLKW(cmd)) |
| 6254 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6255 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6256 | msg.rpc_argp = &data->arg; |
| 6257 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6258 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6259 | if (recovery_type > NFS_LOCK_NEW) { |
| 6260 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6261 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6262 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6263 | } else |
| 6264 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6265 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6266 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6267 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6268 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6269 | if (ret == 0) { |
| 6270 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6271 | if (ret) |
| 6272 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6273 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6274 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6275 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6276 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6277 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6278 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6279 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6283 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6284 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6285 | struct nfs4_exception exception = { |
| 6286 | .inode = state->inode, |
| 6287 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6288 | int err; |
| 6289 | |
| 6290 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6291 | /* Cache the lock if possible... */ |
| 6292 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6293 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6294 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6295 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6296 | break; |
| 6297 | nfs4_handle_exception(server, err, &exception); |
| 6298 | } while (exception.retry); |
| 6299 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | } |
| 6301 | |
| 6302 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6303 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6304 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6305 | struct nfs4_exception exception = { |
| 6306 | .inode = state->inode, |
| 6307 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6308 | int err; |
| 6309 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6310 | err = nfs4_set_lock_state(state, request); |
| 6311 | if (err != 0) |
| 6312 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6313 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6314 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6315 | return 0; |
| 6316 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6317 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6318 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6319 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6320 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6321 | switch (err) { |
| 6322 | default: |
| 6323 | goto out; |
| 6324 | case -NFS4ERR_GRACE: |
| 6325 | case -NFS4ERR_DELAY: |
| 6326 | nfs4_handle_exception(server, err, &exception); |
| 6327 | err = 0; |
| 6328 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6329 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6330 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6331 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6332 | } |
| 6333 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6334 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6335 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6336 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6337 | struct nfs4_lock_state *lsp; |
| 6338 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6339 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6340 | status = nfs4_set_lock_state(state, request); |
| 6341 | if (status != 0) |
| 6342 | return status; |
| 6343 | lsp = request->fl_u.nfs4_fl.owner; |
| 6344 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6345 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6346 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6347 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6348 | } |
| 6349 | #endif |
| 6350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6352 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6353 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6354 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6355 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6356 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6357 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6358 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6359 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6360 | if (status < 0) |
| 6361 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6362 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6363 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6364 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6365 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6366 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6367 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6368 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6369 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6370 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6371 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6372 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6373 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6374 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6375 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6376 | out: |
| 6377 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6378 | return status; |
| 6379 | } |
| 6380 | |
| 6381 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6382 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6383 | struct nfs4_exception exception = { |
| 6384 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6385 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6386 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6387 | int err; |
| 6388 | |
| 6389 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6390 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6391 | if (err == -NFS4ERR_DENIED) |
| 6392 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6393 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6394 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6395 | } while (exception.retry); |
| 6396 | return err; |
| 6397 | } |
| 6398 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6399 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6400 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6401 | |
| 6402 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6403 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6404 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6405 | { |
| 6406 | int status = -ERESTARTSYS; |
| 6407 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6408 | |
| 6409 | while(!signalled()) { |
| 6410 | status = nfs4_proc_setlk(state, cmd, request); |
| 6411 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6412 | break; |
| 6413 | freezable_schedule_timeout_interruptible(timeout); |
| 6414 | timeout *= 2; |
| 6415 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6416 | status = -ERESTARTSYS; |
| 6417 | } |
| 6418 | return status; |
| 6419 | } |
| 6420 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6421 | #ifdef CONFIG_NFS_V4_1 |
| 6422 | struct nfs4_lock_waiter { |
| 6423 | struct task_struct *task; |
| 6424 | struct inode *inode; |
| 6425 | struct nfs_lowner *owner; |
| 6426 | bool notified; |
| 6427 | }; |
| 6428 | |
| 6429 | static int |
| 6430 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6431 | { |
| 6432 | int ret; |
| 6433 | struct cb_notify_lock_args *cbnl = key; |
| 6434 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6435 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6436 | *wowner = waiter->owner; |
| 6437 | |
| 6438 | /* Only wake if the callback was for the same owner */ |
| 6439 | if (lowner->clientid != wowner->clientid || |
| 6440 | lowner->id != wowner->id || |
| 6441 | lowner->s_dev != wowner->s_dev) |
| 6442 | return 0; |
| 6443 | |
| 6444 | /* Make sure it's for the right inode */ |
| 6445 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6446 | return 0; |
| 6447 | |
| 6448 | waiter->notified = true; |
| 6449 | |
| 6450 | /* override "private" so we can use default_wake_function */ |
| 6451 | wait->private = waiter->task; |
| 6452 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6453 | wait->private = waiter; |
| 6454 | return ret; |
| 6455 | } |
| 6456 | |
| 6457 | static int |
| 6458 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6459 | { |
| 6460 | int status = -ERESTARTSYS; |
| 6461 | unsigned long flags; |
| 6462 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6463 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6464 | struct nfs_client *clp = server->nfs_client; |
| 6465 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6466 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6467 | .id = lsp->ls_seqid.owner_id, |
| 6468 | .s_dev = server->s_dev }; |
| 6469 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6470 | .inode = state->inode, |
| 6471 | .owner = &owner, |
| 6472 | .notified = false }; |
| 6473 | wait_queue_t wait; |
| 6474 | |
| 6475 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6476 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6477 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6478 | |
| 6479 | init_wait(&wait); |
| 6480 | wait.private = &waiter; |
| 6481 | wait.func = nfs4_wake_lock_waiter; |
| 6482 | add_wait_queue(q, &wait); |
| 6483 | |
| 6484 | while(!signalled()) { |
| 6485 | status = nfs4_proc_setlk(state, cmd, request); |
| 6486 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6487 | break; |
| 6488 | |
| 6489 | status = -ERESTARTSYS; |
| 6490 | spin_lock_irqsave(&q->lock, flags); |
| 6491 | if (waiter.notified) { |
| 6492 | spin_unlock_irqrestore(&q->lock, flags); |
| 6493 | continue; |
| 6494 | } |
| 6495 | set_current_state(TASK_INTERRUPTIBLE); |
| 6496 | spin_unlock_irqrestore(&q->lock, flags); |
| 6497 | |
Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6498 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | finish_wait(q, &wait); |
| 6502 | return status; |
| 6503 | } |
| 6504 | #else /* !CONFIG_NFS_V4_1 */ |
| 6505 | static inline int |
| 6506 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6507 | { |
| 6508 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6509 | } |
| 6510 | #endif |
| 6511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6512 | static int |
| 6513 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6514 | { |
| 6515 | struct nfs_open_context *ctx; |
| 6516 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6517 | int status; |
| 6518 | |
| 6519 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6520 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6521 | state = ctx->state; |
| 6522 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6523 | if (IS_GETLK(cmd)) { |
| 6524 | if (state != NULL) |
| 6525 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6526 | return 0; |
| 6527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6528 | |
| 6529 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6530 | return -EINVAL; |
| 6531 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6532 | if (request->fl_type == F_UNLCK) { |
| 6533 | if (state != NULL) |
| 6534 | return nfs4_proc_unlck(state, cmd, request); |
| 6535 | return 0; |
| 6536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6537 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6538 | if (state == NULL) |
| 6539 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6540 | |
| 6541 | if ((request->fl_flags & FL_POSIX) && |
| 6542 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6543 | return -ENOLCK; |
| 6544 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6545 | status = nfs4_set_lock_state(state, request); |
| 6546 | if (status != 0) |
| 6547 | return status; |
| 6548 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6549 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6550 | } |
| 6551 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6552 | 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] | 6553 | { |
| 6554 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6555 | int err; |
| 6556 | |
| 6557 | err = nfs4_set_lock_state(state, fl); |
| 6558 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6559 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6560 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6561 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6562 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6563 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6564 | struct nfs_release_lockowner_data { |
| 6565 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6566 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6567 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6568 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6569 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6570 | }; |
| 6571 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6572 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6573 | { |
| 6574 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6575 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6576 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6577 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6578 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6579 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6580 | } |
| 6581 | |
| 6582 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6583 | { |
| 6584 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6585 | struct nfs_server *server = data->server; |
| 6586 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6587 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6588 | |
| 6589 | switch (task->tk_status) { |
| 6590 | case 0: |
| 6591 | renew_lease(server, data->timestamp); |
| 6592 | break; |
| 6593 | case -NFS4ERR_STALE_CLIENTID: |
| 6594 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6595 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6596 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6597 | case -NFS4ERR_LEASE_MOVED: |
| 6598 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6599 | if (nfs4_async_handle_error(task, server, |
| 6600 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6601 | rpc_restart_call_prepare(task); |
| 6602 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6603 | } |
| 6604 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6605 | static void nfs4_release_lockowner_release(void *calldata) |
| 6606 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6607 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6608 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6609 | kfree(calldata); |
| 6610 | } |
| 6611 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6612 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6613 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6614 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6615 | .rpc_release = nfs4_release_lockowner_release, |
| 6616 | }; |
| 6617 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6618 | static void |
| 6619 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6620 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6621 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6622 | struct rpc_message msg = { |
| 6623 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6624 | }; |
| 6625 | |
| 6626 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6627 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6628 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6629 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6630 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6631 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6632 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6633 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6634 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6635 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6636 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6637 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6638 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6639 | msg.rpc_resp = &data->res; |
| 6640 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6641 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6642 | } |
| 6643 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6644 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6645 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6646 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6647 | struct dentry *unused, struct inode *inode, |
| 6648 | const char *key, const void *buf, |
| 6649 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6650 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6651 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6652 | } |
| 6653 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6654 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6655 | struct dentry *unused, struct inode *inode, |
| 6656 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6657 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6658 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6659 | } |
| 6660 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6661 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6662 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6663 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6664 | } |
| 6665 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6666 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6667 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6668 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6669 | struct dentry *unused, struct inode *inode, |
| 6670 | const char *key, const void *buf, |
| 6671 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6672 | { |
| 6673 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6674 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6675 | |
| 6676 | return -EOPNOTSUPP; |
| 6677 | } |
| 6678 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6679 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6680 | struct dentry *unused, struct inode *inode, |
| 6681 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6682 | { |
| 6683 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6684 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6685 | return -EOPNOTSUPP; |
| 6686 | } |
| 6687 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6688 | static ssize_t |
| 6689 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6690 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6691 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6692 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6693 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6694 | len = security_inode_listsecurity(inode, list, list_len); |
| 6695 | if (list_len && len > list_len) |
| 6696 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6697 | } |
| 6698 | return len; |
| 6699 | } |
| 6700 | |
| 6701 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6702 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6703 | .get = nfs4_xattr_get_nfs4_label, |
| 6704 | .set = nfs4_xattr_set_nfs4_label, |
| 6705 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6706 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6707 | #else |
| 6708 | |
| 6709 | static ssize_t |
| 6710 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6711 | { |
| 6712 | return 0; |
| 6713 | } |
| 6714 | |
| 6715 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6716 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6717 | /* |
| 6718 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6719 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6720 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6721 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6722 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6723 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6724 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6725 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6726 | return; |
| 6727 | |
| 6728 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6729 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6730 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6731 | fattr->nlink = 2; |
| 6732 | } |
| 6733 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6734 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6735 | const struct qstr *name, |
| 6736 | struct nfs4_fs_locations *fs_locations, |
| 6737 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6738 | { |
| 6739 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6740 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6741 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6742 | }; |
| 6743 | struct nfs4_fs_locations_arg args = { |
| 6744 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6745 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6746 | .page = page, |
| 6747 | .bitmask = bitmask, |
| 6748 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6749 | struct nfs4_fs_locations_res res = { |
| 6750 | .fs_locations = fs_locations, |
| 6751 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6752 | struct rpc_message msg = { |
| 6753 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6754 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6755 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6756 | }; |
| 6757 | int status; |
| 6758 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6759 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6760 | |
| 6761 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6762 | * is not supported */ |
| 6763 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6764 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6765 | else |
| 6766 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6767 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6768 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6769 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6770 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6771 | 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] | 6772 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6773 | return status; |
| 6774 | } |
| 6775 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6776 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6777 | const struct qstr *name, |
| 6778 | struct nfs4_fs_locations *fs_locations, |
| 6779 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6780 | { |
| 6781 | struct nfs4_exception exception = { }; |
| 6782 | int err; |
| 6783 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6784 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6785 | fs_locations, page); |
| 6786 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6787 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6788 | &exception); |
| 6789 | } while (exception.retry); |
| 6790 | return err; |
| 6791 | } |
| 6792 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6793 | /* |
| 6794 | * This operation also signals the server that this client is |
| 6795 | * performing migration recovery. The server can stop returning |
| 6796 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6797 | * appended to this compound to identify the client ID which is |
| 6798 | * performing recovery. |
| 6799 | */ |
| 6800 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6801 | struct nfs4_fs_locations *locations, |
| 6802 | struct page *page, struct rpc_cred *cred) |
| 6803 | { |
| 6804 | struct nfs_server *server = NFS_SERVER(inode); |
| 6805 | struct rpc_clnt *clnt = server->client; |
| 6806 | u32 bitmask[2] = { |
| 6807 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6808 | }; |
| 6809 | struct nfs4_fs_locations_arg args = { |
| 6810 | .clientid = server->nfs_client->cl_clientid, |
| 6811 | .fh = NFS_FH(inode), |
| 6812 | .page = page, |
| 6813 | .bitmask = bitmask, |
| 6814 | .migration = 1, /* skip LOOKUP */ |
| 6815 | .renew = 1, /* append RENEW */ |
| 6816 | }; |
| 6817 | struct nfs4_fs_locations_res res = { |
| 6818 | .fs_locations = locations, |
| 6819 | .migration = 1, |
| 6820 | .renew = 1, |
| 6821 | }; |
| 6822 | struct rpc_message msg = { |
| 6823 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6824 | .rpc_argp = &args, |
| 6825 | .rpc_resp = &res, |
| 6826 | .rpc_cred = cred, |
| 6827 | }; |
| 6828 | unsigned long now = jiffies; |
| 6829 | int status; |
| 6830 | |
| 6831 | nfs_fattr_init(&locations->fattr); |
| 6832 | locations->server = server; |
| 6833 | locations->nlocations = 0; |
| 6834 | |
| 6835 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6836 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6837 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6838 | &args.seq_args, &res.seq_res); |
| 6839 | if (status) |
| 6840 | return status; |
| 6841 | |
| 6842 | renew_lease(server, now); |
| 6843 | return 0; |
| 6844 | } |
| 6845 | |
| 6846 | #ifdef CONFIG_NFS_V4_1 |
| 6847 | |
| 6848 | /* |
| 6849 | * This operation also signals the server that this client is |
| 6850 | * performing migration recovery. The server can stop asserting |
| 6851 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6852 | * performing this operation is identified in the SEQUENCE |
| 6853 | * operation in this compound. |
| 6854 | * |
| 6855 | * When the client supports GETATTR(fs_locations_info), it can |
| 6856 | * be plumbed in here. |
| 6857 | */ |
| 6858 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6859 | struct nfs4_fs_locations *locations, |
| 6860 | struct page *page, struct rpc_cred *cred) |
| 6861 | { |
| 6862 | struct nfs_server *server = NFS_SERVER(inode); |
| 6863 | struct rpc_clnt *clnt = server->client; |
| 6864 | u32 bitmask[2] = { |
| 6865 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6866 | }; |
| 6867 | struct nfs4_fs_locations_arg args = { |
| 6868 | .fh = NFS_FH(inode), |
| 6869 | .page = page, |
| 6870 | .bitmask = bitmask, |
| 6871 | .migration = 1, /* skip LOOKUP */ |
| 6872 | }; |
| 6873 | struct nfs4_fs_locations_res res = { |
| 6874 | .fs_locations = locations, |
| 6875 | .migration = 1, |
| 6876 | }; |
| 6877 | struct rpc_message msg = { |
| 6878 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6879 | .rpc_argp = &args, |
| 6880 | .rpc_resp = &res, |
| 6881 | .rpc_cred = cred, |
| 6882 | }; |
| 6883 | int status; |
| 6884 | |
| 6885 | nfs_fattr_init(&locations->fattr); |
| 6886 | locations->server = server; |
| 6887 | locations->nlocations = 0; |
| 6888 | |
| 6889 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6890 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6891 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6892 | &args.seq_args, &res.seq_res); |
| 6893 | if (status == NFS4_OK && |
| 6894 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6895 | status = -NFS4ERR_LEASE_MOVED; |
| 6896 | return status; |
| 6897 | } |
| 6898 | |
| 6899 | #endif /* CONFIG_NFS_V4_1 */ |
| 6900 | |
| 6901 | /** |
| 6902 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6903 | * @inode: inode on FSID that is migrating |
| 6904 | * @locations: result of query |
| 6905 | * @page: buffer |
| 6906 | * @cred: credential to use for this operation |
| 6907 | * |
| 6908 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6909 | * operation failed, or a negative errno if a local error occurred. |
| 6910 | * |
| 6911 | * On success, "locations" is filled in, but if the server has |
| 6912 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6913 | * asserted. |
| 6914 | * |
| 6915 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6916 | * from this client that require migration recovery. |
| 6917 | */ |
| 6918 | int nfs4_proc_get_locations(struct inode *inode, |
| 6919 | struct nfs4_fs_locations *locations, |
| 6920 | struct page *page, struct rpc_cred *cred) |
| 6921 | { |
| 6922 | struct nfs_server *server = NFS_SERVER(inode); |
| 6923 | struct nfs_client *clp = server->nfs_client; |
| 6924 | const struct nfs4_mig_recovery_ops *ops = |
| 6925 | clp->cl_mvops->mig_recovery_ops; |
| 6926 | struct nfs4_exception exception = { }; |
| 6927 | int status; |
| 6928 | |
| 6929 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6930 | (unsigned long long)server->fsid.major, |
| 6931 | (unsigned long long)server->fsid.minor, |
| 6932 | clp->cl_hostname); |
| 6933 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6934 | |
| 6935 | do { |
| 6936 | status = ops->get_locations(inode, locations, page, cred); |
| 6937 | if (status != -NFS4ERR_DELAY) |
| 6938 | break; |
| 6939 | nfs4_handle_exception(server, status, &exception); |
| 6940 | } while (exception.retry); |
| 6941 | return status; |
| 6942 | } |
| 6943 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6944 | /* |
| 6945 | * This operation also signals the server that this client is |
| 6946 | * performing "lease moved" recovery. The server can stop |
| 6947 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6948 | * is appended to this compound to identify the client ID which is |
| 6949 | * performing recovery. |
| 6950 | */ |
| 6951 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6952 | { |
| 6953 | struct nfs_server *server = NFS_SERVER(inode); |
| 6954 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6955 | struct rpc_clnt *clnt = server->client; |
| 6956 | struct nfs4_fsid_present_arg args = { |
| 6957 | .fh = NFS_FH(inode), |
| 6958 | .clientid = clp->cl_clientid, |
| 6959 | .renew = 1, /* append RENEW */ |
| 6960 | }; |
| 6961 | struct nfs4_fsid_present_res res = { |
| 6962 | .renew = 1, |
| 6963 | }; |
| 6964 | struct rpc_message msg = { |
| 6965 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6966 | .rpc_argp = &args, |
| 6967 | .rpc_resp = &res, |
| 6968 | .rpc_cred = cred, |
| 6969 | }; |
| 6970 | unsigned long now = jiffies; |
| 6971 | int status; |
| 6972 | |
| 6973 | res.fh = nfs_alloc_fhandle(); |
| 6974 | if (res.fh == NULL) |
| 6975 | return -ENOMEM; |
| 6976 | |
| 6977 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6978 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6979 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6980 | &args.seq_args, &res.seq_res); |
| 6981 | nfs_free_fhandle(res.fh); |
| 6982 | if (status) |
| 6983 | return status; |
| 6984 | |
| 6985 | do_renew_lease(clp, now); |
| 6986 | return 0; |
| 6987 | } |
| 6988 | |
| 6989 | #ifdef CONFIG_NFS_V4_1 |
| 6990 | |
| 6991 | /* |
| 6992 | * This operation also signals the server that this client is |
| 6993 | * performing "lease moved" recovery. The server can stop asserting |
| 6994 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6995 | * this operation is identified in the SEQUENCE operation in this |
| 6996 | * compound. |
| 6997 | */ |
| 6998 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6999 | { |
| 7000 | struct nfs_server *server = NFS_SERVER(inode); |
| 7001 | struct rpc_clnt *clnt = server->client; |
| 7002 | struct nfs4_fsid_present_arg args = { |
| 7003 | .fh = NFS_FH(inode), |
| 7004 | }; |
| 7005 | struct nfs4_fsid_present_res res = { |
| 7006 | }; |
| 7007 | struct rpc_message msg = { |
| 7008 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7009 | .rpc_argp = &args, |
| 7010 | .rpc_resp = &res, |
| 7011 | .rpc_cred = cred, |
| 7012 | }; |
| 7013 | int status; |
| 7014 | |
| 7015 | res.fh = nfs_alloc_fhandle(); |
| 7016 | if (res.fh == NULL) |
| 7017 | return -ENOMEM; |
| 7018 | |
| 7019 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7020 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7021 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7022 | &args.seq_args, &res.seq_res); |
| 7023 | nfs_free_fhandle(res.fh); |
| 7024 | if (status == NFS4_OK && |
| 7025 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7026 | status = -NFS4ERR_LEASE_MOVED; |
| 7027 | return status; |
| 7028 | } |
| 7029 | |
| 7030 | #endif /* CONFIG_NFS_V4_1 */ |
| 7031 | |
| 7032 | /** |
| 7033 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7034 | * @inode: inode on FSID to check |
| 7035 | * @cred: credential to use for this operation |
| 7036 | * |
| 7037 | * Server indicates whether the FSID is present, moved, or not |
| 7038 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7039 | * condition for this client ID. |
| 7040 | * |
| 7041 | * Returns NFS4_OK if the FSID is present on this server, |
| 7042 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7043 | * NFS4ERR code if some error occurred on the server, or a |
| 7044 | * negative errno if a local failure occurred. |
| 7045 | */ |
| 7046 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7047 | { |
| 7048 | struct nfs_server *server = NFS_SERVER(inode); |
| 7049 | struct nfs_client *clp = server->nfs_client; |
| 7050 | const struct nfs4_mig_recovery_ops *ops = |
| 7051 | clp->cl_mvops->mig_recovery_ops; |
| 7052 | struct nfs4_exception exception = { }; |
| 7053 | int status; |
| 7054 | |
| 7055 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7056 | (unsigned long long)server->fsid.major, |
| 7057 | (unsigned long long)server->fsid.minor, |
| 7058 | clp->cl_hostname); |
| 7059 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7060 | |
| 7061 | do { |
| 7062 | status = ops->fsid_present(inode, cred); |
| 7063 | if (status != -NFS4ERR_DELAY) |
| 7064 | break; |
| 7065 | nfs4_handle_exception(server, status, &exception); |
| 7066 | } while (exception.retry); |
| 7067 | return status; |
| 7068 | } |
| 7069 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7070 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7071 | * If 'use_integrity' is true and the state managment nfs_client |
| 7072 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7073 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7074 | * Considerations sections. Otherwise, just use the user cred with the |
| 7075 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7076 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7077 | 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] | 7078 | { |
| 7079 | int status; |
| 7080 | struct nfs4_secinfo_arg args = { |
| 7081 | .dir_fh = NFS_FH(dir), |
| 7082 | .name = name, |
| 7083 | }; |
| 7084 | struct nfs4_secinfo_res res = { |
| 7085 | .flavors = flavors, |
| 7086 | }; |
| 7087 | struct rpc_message msg = { |
| 7088 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7089 | .rpc_argp = &args, |
| 7090 | .rpc_resp = &res, |
| 7091 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7092 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7093 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7094 | |
| 7095 | if (use_integrity) { |
| 7096 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7097 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7098 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7099 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7100 | |
| 7101 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7102 | |
| 7103 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7104 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7105 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7106 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7107 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7108 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7109 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7110 | if (cred) |
| 7111 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7112 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7113 | return status; |
| 7114 | } |
| 7115 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7116 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7117 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7118 | { |
| 7119 | struct nfs4_exception exception = { }; |
| 7120 | int err; |
| 7121 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7122 | err = -NFS4ERR_WRONGSEC; |
| 7123 | |
| 7124 | /* try to use integrity protection with machine cred */ |
| 7125 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7126 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7127 | |
| 7128 | /* |
| 7129 | * if unable to use integrity protection, or SECINFO with |
| 7130 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7131 | * disallowed by spec, but exists in deployed servers) use |
| 7132 | * the current filesystem's rpc_client and the user cred. |
| 7133 | */ |
| 7134 | if (err == -NFS4ERR_WRONGSEC) |
| 7135 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7136 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7137 | trace_nfs4_secinfo(dir, name, err); |
| 7138 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7139 | &exception); |
| 7140 | } while (exception.retry); |
| 7141 | return err; |
| 7142 | } |
| 7143 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7144 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7145 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7146 | * Check the exchange flags returned by the server for invalid flags, having |
| 7147 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7148 | * DS flags set. |
| 7149 | */ |
| 7150 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7151 | { |
| 7152 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7153 | goto out_inval; |
| 7154 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7155 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7156 | goto out_inval; |
| 7157 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7158 | goto out_inval; |
| 7159 | return NFS_OK; |
| 7160 | out_inval: |
| 7161 | return -NFS4ERR_INVAL; |
| 7162 | } |
| 7163 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7164 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7165 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7166 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7167 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7168 | if (a->server_scope_sz != b->server_scope_sz) |
| 7169 | return false; |
| 7170 | return memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7171 | } |
| 7172 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7173 | static void |
| 7174 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7175 | { |
| 7176 | } |
| 7177 | |
| 7178 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7179 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7180 | }; |
| 7181 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7182 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7183 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7184 | * |
| 7185 | * The 4.1 client currently uses the same TCP connection for the |
| 7186 | * fore and backchannel. |
| 7187 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7188 | static |
| 7189 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7190 | struct rpc_xprt *xprt, |
| 7191 | struct nfs_client *clp, |
| 7192 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7193 | { |
| 7194 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7195 | struct nfs41_bind_conn_to_session_args args = { |
| 7196 | .client = clp, |
| 7197 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7198 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7199 | struct nfs41_bind_conn_to_session_res res; |
| 7200 | struct rpc_message msg = { |
| 7201 | .rpc_proc = |
| 7202 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7203 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7204 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7205 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7206 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7207 | struct rpc_task_setup task_setup_data = { |
| 7208 | .rpc_client = clnt, |
| 7209 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7210 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7211 | .rpc_message = &msg, |
| 7212 | .flags = RPC_TASK_TIMEOUT, |
| 7213 | }; |
| 7214 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7215 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7216 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7217 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7218 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7219 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7220 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7221 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7222 | args.dir = NFS4_CDFC4_FORE; |
| 7223 | |
| 7224 | task = rpc_run_task(&task_setup_data); |
| 7225 | if (!IS_ERR(task)) { |
| 7226 | status = task->tk_status; |
| 7227 | rpc_put_task(task); |
| 7228 | } else |
| 7229 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7230 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7231 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7232 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7233 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7234 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7235 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7236 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7237 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7238 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7239 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7240 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7241 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7242 | 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] | 7243 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7244 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7245 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7246 | } |
| 7247 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7248 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7249 | return status; |
| 7250 | } |
| 7251 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7252 | struct rpc_bind_conn_calldata { |
| 7253 | struct nfs_client *clp; |
| 7254 | struct rpc_cred *cred; |
| 7255 | }; |
| 7256 | |
| 7257 | static int |
| 7258 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7259 | struct rpc_xprt *xprt, |
| 7260 | void *calldata) |
| 7261 | { |
| 7262 | struct rpc_bind_conn_calldata *p = calldata; |
| 7263 | |
| 7264 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7265 | } |
| 7266 | |
| 7267 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7268 | { |
| 7269 | struct rpc_bind_conn_calldata data = { |
| 7270 | .clp = clp, |
| 7271 | .cred = cred, |
| 7272 | }; |
| 7273 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7274 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7275 | } |
| 7276 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7277 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7278 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7279 | * 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] | 7280 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7281 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7282 | .how = SP4_MACH_CRED, |
| 7283 | .enforce.u.words = { |
| 7284 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7285 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7286 | 1 << (OP_CREATE_SESSION - 32) | |
| 7287 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7288 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7289 | }, |
| 7290 | .allow.u.words = { |
| 7291 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7292 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7293 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7294 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7295 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7296 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7297 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7298 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7299 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7300 | 1 << (OP_FREE_STATEID - 32) | |
| 7301 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7302 | } |
| 7303 | }; |
| 7304 | |
| 7305 | /* |
| 7306 | * Select the state protection mode for client `clp' given the server results |
| 7307 | * from exchange_id in `sp'. |
| 7308 | * |
| 7309 | * Returns 0 on success, negative errno otherwise. |
| 7310 | */ |
| 7311 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7312 | struct nfs41_state_protection *sp) |
| 7313 | { |
| 7314 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7315 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7316 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7317 | 1 << (OP_CREATE_SESSION - 32) | |
| 7318 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7319 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7320 | }; |
| 7321 | unsigned int i; |
| 7322 | |
| 7323 | if (sp->how == SP4_MACH_CRED) { |
| 7324 | /* Print state protect result */ |
| 7325 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7326 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7327 | if (test_bit(i, sp->enforce.u.longs)) |
| 7328 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7329 | if (test_bit(i, sp->allow.u.longs)) |
| 7330 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7331 | } |
| 7332 | |
| 7333 | /* make sure nothing is on enforce list that isn't supported */ |
| 7334 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7335 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7336 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7337 | return -EINVAL; |
| 7338 | } |
| 7339 | } |
| 7340 | |
| 7341 | /* |
| 7342 | * Minimal mode - state operations are allowed to use machine |
| 7343 | * credential. Note this already happens by default, so the |
| 7344 | * client doesn't have to do anything more than the negotiation. |
| 7345 | * |
| 7346 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7347 | * we're already using the machine cred for exchange_id |
| 7348 | * and will never use a different cred. |
| 7349 | */ |
| 7350 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7351 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7352 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7353 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7354 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7355 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7356 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7357 | } else { |
| 7358 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7359 | return -EINVAL; |
| 7360 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7361 | |
| 7362 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7363 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7364 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7365 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7366 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7367 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7368 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7369 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7370 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7371 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7372 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7373 | &clp->cl_sp4_flags); |
| 7374 | } |
| 7375 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7376 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7377 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7378 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7379 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7380 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7381 | |
| 7382 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7383 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7384 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7385 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7386 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7387 | |
| 7388 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7389 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7390 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7391 | } |
| 7392 | |
| 7393 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7394 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7395 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7396 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7397 | } |
| 7398 | |
| 7399 | return 0; |
| 7400 | } |
| 7401 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7402 | struct nfs41_exchange_id_data { |
| 7403 | struct nfs41_exchange_id_res res; |
| 7404 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7405 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7406 | int rpc_status; |
| 7407 | }; |
| 7408 | |
| 7409 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7410 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7411 | struct nfs41_exchange_id_data *cdata = |
| 7412 | (struct nfs41_exchange_id_data *)data; |
| 7413 | struct nfs_client *clp = cdata->args.client; |
| 7414 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7415 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7416 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7417 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7418 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7419 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7420 | |
| 7421 | if (cdata->xprt && status == 0) { |
| 7422 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7423 | cdata->xprt); |
| 7424 | goto out; |
| 7425 | } |
| 7426 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7427 | if (status == 0) |
| 7428 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7429 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7430 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7431 | clp->cl_clientid = cdata->res.clientid; |
| 7432 | clp->cl_exchange_flags = cdata->res.flags; |
Chuck Lever | 838edb9 | 2017-06-08 11:52:52 -0400 | [diff] [blame] | 7433 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7434 | /* Client ID is not confirmed */ |
Chuck Lever | 838edb9 | 2017-06-08 11:52:52 -0400 | [diff] [blame] | 7435 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7436 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Chuck Lever | 838edb9 | 2017-06-08 11:52:52 -0400 | [diff] [blame] | 7437 | &clp->cl_session->session_state); |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7438 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7439 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7440 | clp->cl_serverowner = cdata->res.server_owner; |
| 7441 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7442 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7443 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7444 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7445 | clp->cl_implid = cdata->res.impl_id; |
| 7446 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7447 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7448 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7449 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7450 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7451 | dprintk("%s: server_scope mismatch detected\n", |
| 7452 | __func__); |
| 7453 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7454 | kfree(clp->cl_serverscope); |
| 7455 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7456 | } |
| 7457 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7458 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7459 | clp->cl_serverscope = cdata->res.server_scope; |
| 7460 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7461 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7462 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame^] | 7463 | memcpy(clp->cl_confirm.data, cdata->args.verifier.data, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7464 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7465 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7466 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7467 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7468 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7469 | } |
| 7470 | |
| 7471 | static void nfs4_exchange_id_release(void *data) |
| 7472 | { |
| 7473 | struct nfs41_exchange_id_data *cdata = |
| 7474 | (struct nfs41_exchange_id_data *)data; |
| 7475 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7476 | if (cdata->xprt) { |
| 7477 | xprt_put(cdata->xprt); |
| 7478 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7479 | } |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7480 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7481 | kfree(cdata->res.impl_id); |
| 7482 | kfree(cdata->res.server_scope); |
| 7483 | kfree(cdata->res.server_owner); |
| 7484 | kfree(cdata); |
| 7485 | } |
| 7486 | |
| 7487 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7488 | .rpc_call_done = nfs4_exchange_id_done, |
| 7489 | .rpc_release = nfs4_exchange_id_release, |
| 7490 | }; |
| 7491 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7492 | /* |
| 7493 | * _nfs4_proc_exchange_id() |
| 7494 | * |
| 7495 | * Wrapper for EXCHANGE_ID operation. |
| 7496 | */ |
| 7497 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7498 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7499 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7500 | struct rpc_message msg = { |
| 7501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7502 | .rpc_cred = cred, |
| 7503 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7504 | struct rpc_task_setup task_setup_data = { |
| 7505 | .rpc_client = clp->cl_rpcclient, |
| 7506 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7507 | .rpc_message = &msg, |
| 7508 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7509 | }; |
| 7510 | struct nfs41_exchange_id_data *calldata; |
| 7511 | struct rpc_task *task; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7512 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7513 | |
| 7514 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7515 | return -EIO; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7516 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7517 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 7518 | if (!calldata) { |
| 7519 | nfs_put_client(clp); |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7520 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 7521 | } |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7522 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame^] | 7523 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7524 | |
| 7525 | status = nfs4_init_uniform_client_string(clp); |
| 7526 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7527 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7528 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7529 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7530 | GFP_NOFS); |
| 7531 | status = -ENOMEM; |
| 7532 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7533 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7534 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7535 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7536 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7537 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7538 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7539 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7540 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7541 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7542 | goto out_server_scope; |
| 7543 | |
| 7544 | switch (sp4_how) { |
| 7545 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7546 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7547 | break; |
| 7548 | |
| 7549 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7550 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7551 | break; |
| 7552 | |
| 7553 | default: |
| 7554 | /* unsupported! */ |
| 7555 | WARN_ON_ONCE(1); |
| 7556 | status = -EINVAL; |
| 7557 | goto out_impl_id; |
| 7558 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7559 | if (xprt) { |
| 7560 | calldata->xprt = xprt; |
| 7561 | task_setup_data.rpc_xprt = xprt; |
| 7562 | task_setup_data.flags = |
| 7563 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame^] | 7564 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 7565 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7566 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7567 | calldata->args.client = clp; |
| 7568 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7569 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7570 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7571 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7572 | #else |
| 7573 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7574 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7575 | #endif |
| 7576 | msg.rpc_argp = &calldata->args; |
| 7577 | msg.rpc_resp = &calldata->res; |
| 7578 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7579 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7580 | task = rpc_run_task(&task_setup_data); |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7581 | if (IS_ERR(task)) |
| 7582 | return PTR_ERR(task); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7583 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7584 | if (!xprt) { |
| 7585 | status = rpc_wait_for_completion_task(task); |
| 7586 | if (!status) |
| 7587 | status = calldata->rpc_status; |
| 7588 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7589 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7590 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7591 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7592 | out: |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7593 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7594 | |
| 7595 | out_impl_id: |
| 7596 | kfree(calldata->res.impl_id); |
| 7597 | out_server_scope: |
| 7598 | kfree(calldata->res.server_scope); |
| 7599 | out_server_owner: |
| 7600 | kfree(calldata->res.server_owner); |
| 7601 | out_calldata: |
| 7602 | kfree(calldata); |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7603 | nfs_put_client(clp); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7604 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7605 | } |
| 7606 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7607 | /* |
| 7608 | * nfs4_proc_exchange_id() |
| 7609 | * |
| 7610 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7611 | * |
| 7612 | * Since the clientid has expired, all compounds using sessions |
| 7613 | * associated with the stale clientid will be returning |
| 7614 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7615 | * be in some phase of session reset. |
| 7616 | * |
| 7617 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7618 | */ |
| 7619 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7620 | { |
| 7621 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7622 | int status; |
| 7623 | |
| 7624 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7625 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7626 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7627 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7628 | if (!status) |
| 7629 | return 0; |
| 7630 | } |
| 7631 | |
| 7632 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7633 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7634 | } |
| 7635 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7636 | /** |
| 7637 | * nfs4_test_session_trunk |
| 7638 | * |
| 7639 | * This is an add_xprt_test() test function called from |
| 7640 | * rpc_clnt_setup_test_and_add_xprt. |
| 7641 | * |
| 7642 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7643 | * and is dereferrenced in nfs4_exchange_id_release |
| 7644 | * |
| 7645 | * Upon success, add the new transport to the rpc_clnt |
| 7646 | * |
| 7647 | * @clnt: struct rpc_clnt to get new transport |
| 7648 | * @xprt: the rpc_xprt to test |
| 7649 | * @data: call data for _nfs4_proc_exchange_id. |
| 7650 | */ |
| 7651 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7652 | void *data) |
| 7653 | { |
| 7654 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7655 | u32 sp4_how; |
| 7656 | |
| 7657 | dprintk("--> %s try %s\n", __func__, |
| 7658 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7659 | |
| 7660 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7661 | |
| 7662 | /* Test connection for session trunking. Async exchange_id call */ |
| 7663 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7664 | } |
| 7665 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7666 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7667 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7668 | struct rpc_cred *cred) |
| 7669 | { |
| 7670 | struct rpc_message msg = { |
| 7671 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7672 | .rpc_argp = clp, |
| 7673 | .rpc_cred = cred, |
| 7674 | }; |
| 7675 | int status; |
| 7676 | |
| 7677 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7678 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7679 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7680 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7681 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7682 | return status; |
| 7683 | } |
| 7684 | |
| 7685 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7686 | struct rpc_cred *cred) |
| 7687 | { |
| 7688 | unsigned int loop; |
| 7689 | int ret; |
| 7690 | |
| 7691 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7692 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7693 | switch (ret) { |
| 7694 | case -NFS4ERR_DELAY: |
| 7695 | case -NFS4ERR_CLIENTID_BUSY: |
| 7696 | ssleep(1); |
| 7697 | break; |
| 7698 | default: |
| 7699 | return ret; |
| 7700 | } |
| 7701 | } |
| 7702 | return 0; |
| 7703 | } |
| 7704 | |
| 7705 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7706 | { |
| 7707 | struct rpc_cred *cred; |
| 7708 | int ret = 0; |
| 7709 | |
| 7710 | if (clp->cl_mvops->minor_version < 1) |
| 7711 | goto out; |
| 7712 | if (clp->cl_exchange_flags == 0) |
| 7713 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7714 | if (clp->cl_preserve_clid) |
| 7715 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7716 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7717 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7718 | if (cred) |
| 7719 | put_rpccred(cred); |
| 7720 | switch (ret) { |
| 7721 | case 0: |
| 7722 | case -NFS4ERR_STALE_CLIENTID: |
| 7723 | clp->cl_exchange_flags = 0; |
| 7724 | } |
| 7725 | out: |
| 7726 | return ret; |
| 7727 | } |
| 7728 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7729 | struct nfs4_get_lease_time_data { |
| 7730 | struct nfs4_get_lease_time_args *args; |
| 7731 | struct nfs4_get_lease_time_res *res; |
| 7732 | struct nfs_client *clp; |
| 7733 | }; |
| 7734 | |
| 7735 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7736 | void *calldata) |
| 7737 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7738 | struct nfs4_get_lease_time_data *data = |
| 7739 | (struct nfs4_get_lease_time_data *)calldata; |
| 7740 | |
| 7741 | dprintk("--> %s\n", __func__); |
| 7742 | /* just setup sequence, do not trigger session recovery |
| 7743 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7744 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7745 | &data->args->la_seq_args, |
| 7746 | &data->res->lr_seq_res, |
| 7747 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7748 | dprintk("<-- %s\n", __func__); |
| 7749 | } |
| 7750 | |
| 7751 | /* |
| 7752 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7753 | * from sequence operation or clientid errors. |
| 7754 | */ |
| 7755 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7756 | { |
| 7757 | struct nfs4_get_lease_time_data *data = |
| 7758 | (struct nfs4_get_lease_time_data *)calldata; |
| 7759 | |
| 7760 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7761 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7762 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7763 | switch (task->tk_status) { |
| 7764 | case -NFS4ERR_DELAY: |
| 7765 | case -NFS4ERR_GRACE: |
| 7766 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7767 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7768 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7769 | /* fall through */ |
| 7770 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7771 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7772 | return; |
| 7773 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7774 | dprintk("<-- %s\n", __func__); |
| 7775 | } |
| 7776 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7777 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7778 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7779 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7780 | }; |
| 7781 | |
| 7782 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7783 | { |
| 7784 | struct rpc_task *task; |
| 7785 | struct nfs4_get_lease_time_args args; |
| 7786 | struct nfs4_get_lease_time_res res = { |
| 7787 | .lr_fsinfo = fsinfo, |
| 7788 | }; |
| 7789 | struct nfs4_get_lease_time_data data = { |
| 7790 | .args = &args, |
| 7791 | .res = &res, |
| 7792 | .clp = clp, |
| 7793 | }; |
| 7794 | struct rpc_message msg = { |
| 7795 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7796 | .rpc_argp = &args, |
| 7797 | .rpc_resp = &res, |
| 7798 | }; |
| 7799 | struct rpc_task_setup task_setup = { |
| 7800 | .rpc_client = clp->cl_rpcclient, |
| 7801 | .rpc_message = &msg, |
| 7802 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7803 | .callback_data = &data, |
| 7804 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7805 | }; |
| 7806 | int status; |
| 7807 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7808 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7809 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7810 | task = rpc_run_task(&task_setup); |
| 7811 | |
| 7812 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7813 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7814 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7815 | status = task->tk_status; |
| 7816 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7817 | return status; |
| 7818 | } |
| 7819 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7820 | /* |
| 7821 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7822 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7823 | * use them. |
| 7824 | * |
| 7825 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7826 | * always set csa_cachethis to FALSE because the current implementation |
| 7827 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7828 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7829 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7830 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7831 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7832 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7833 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7834 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7835 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7836 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7837 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7838 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7839 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7840 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7841 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7842 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7843 | |
| 7844 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7845 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7846 | __func__, |
| 7847 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7848 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7849 | |
| 7850 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7851 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7852 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7853 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7854 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7855 | args->bc_attrs.max_reqs = min_t(unsigned short, max_session_cb_slots, 1); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7856 | |
| 7857 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7858 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7859 | __func__, |
| 7860 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7861 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7862 | args->bc_attrs.max_reqs); |
| 7863 | } |
| 7864 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7865 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7866 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7867 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7868 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7869 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7870 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7871 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7872 | return -EINVAL; |
| 7873 | /* |
| 7874 | * Our requested max_ops is the minimum we need; we're not |
| 7875 | * prepared to break up compounds into smaller pieces than that. |
| 7876 | * So, no point even trying to continue if the server won't |
| 7877 | * cooperate: |
| 7878 | */ |
| 7879 | if (rcvd->max_ops < sent->max_ops) |
| 7880 | return -EINVAL; |
| 7881 | if (rcvd->max_reqs == 0) |
| 7882 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7883 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7884 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7885 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7886 | } |
| 7887 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7888 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7889 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7890 | { |
| 7891 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7892 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7893 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7894 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7895 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7896 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7897 | return -EINVAL; |
| 7898 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7899 | return -EINVAL; |
| 7900 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7901 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7902 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7903 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7904 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7905 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7906 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7907 | return 0; |
| 7908 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7909 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7910 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7911 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7912 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7913 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7914 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7915 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7916 | if (ret) |
| 7917 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7918 | return nfs4_verify_back_channel_attrs(args, res); |
| 7919 | } |
| 7920 | |
| 7921 | static void nfs4_update_session(struct nfs4_session *session, |
| 7922 | struct nfs41_create_session_res *res) |
| 7923 | { |
| 7924 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7925 | /* Mark client id and session as being confirmed */ |
| 7926 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7927 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7928 | session->flags = res->flags; |
| 7929 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7930 | if (res->flags & SESSION4_BACK_CHAN) |
| 7931 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7932 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7933 | } |
| 7934 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7935 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7936 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7937 | { |
| 7938 | struct nfs4_session *session = clp->cl_session; |
| 7939 | struct nfs41_create_session_args args = { |
| 7940 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7941 | .clientid = clp->cl_clientid, |
| 7942 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7943 | .cb_program = NFS4_CALLBACK, |
| 7944 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7945 | struct nfs41_create_session_res res; |
| 7946 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7947 | struct rpc_message msg = { |
| 7948 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7949 | .rpc_argp = &args, |
| 7950 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7951 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7952 | }; |
| 7953 | int status; |
| 7954 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7955 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7956 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7957 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7958 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7959 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7960 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7961 | switch (status) { |
| 7962 | case -NFS4ERR_STALE_CLIENTID: |
| 7963 | case -NFS4ERR_DELAY: |
| 7964 | case -ETIMEDOUT: |
| 7965 | case -EACCES: |
| 7966 | case -EAGAIN: |
| 7967 | goto out; |
| 7968 | }; |
| 7969 | |
| 7970 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7971 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7972 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7973 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7974 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7975 | if (status) |
| 7976 | goto out; |
| 7977 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7978 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7979 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7980 | return status; |
| 7981 | } |
| 7982 | |
| 7983 | /* |
| 7984 | * Issues a CREATE_SESSION operation to the server. |
| 7985 | * It is the responsibility of the caller to verify the session is |
| 7986 | * expired before calling this routine. |
| 7987 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7988 | 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] | 7989 | { |
| 7990 | int status; |
| 7991 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7992 | struct nfs4_session *session = clp->cl_session; |
| 7993 | |
| 7994 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7995 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7996 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7997 | if (status) |
| 7998 | goto out; |
| 7999 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8000 | /* Init or reset the session slot tables */ |
| 8001 | status = nfs4_setup_session_slot_tables(session); |
| 8002 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8003 | if (status) |
| 8004 | goto out; |
| 8005 | |
| 8006 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8007 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8008 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8009 | out: |
| 8010 | dprintk("<-- %s\n", __func__); |
| 8011 | return status; |
| 8012 | } |
| 8013 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8014 | /* |
| 8015 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8016 | * The caller must serialize access to this routine. |
| 8017 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8018 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8019 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8020 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8021 | struct rpc_message msg = { |
| 8022 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8023 | .rpc_argp = session, |
| 8024 | .rpc_cred = cred, |
| 8025 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8026 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8027 | |
| 8028 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8029 | |
| 8030 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8031 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8032 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8033 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8034 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8035 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8036 | |
| 8037 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8038 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8039 | "Session has been destroyed regardless...\n", status); |
| 8040 | |
| 8041 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8042 | return status; |
| 8043 | } |
| 8044 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8045 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8046 | * Renew the cl_session lease. |
| 8047 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8048 | struct nfs4_sequence_data { |
| 8049 | struct nfs_client *clp; |
| 8050 | struct nfs4_sequence_args args; |
| 8051 | struct nfs4_sequence_res res; |
| 8052 | }; |
| 8053 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8054 | static void nfs41_sequence_release(void *data) |
| 8055 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8056 | struct nfs4_sequence_data *calldata = data; |
| 8057 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8058 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8059 | if (atomic_read(&clp->cl_count) > 1) |
| 8060 | nfs4_schedule_state_renewal(clp); |
| 8061 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8062 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8063 | } |
| 8064 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8065 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8066 | { |
| 8067 | switch(task->tk_status) { |
| 8068 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8069 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8070 | return -EAGAIN; |
| 8071 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8072 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8073 | } |
| 8074 | return 0; |
| 8075 | } |
| 8076 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8077 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8078 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8079 | struct nfs4_sequence_data *calldata = data; |
| 8080 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8081 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8082 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8083 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8084 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8085 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8086 | if (task->tk_status < 0) { |
| 8087 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8088 | if (atomic_read(&clp->cl_count) == 1) |
| 8089 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8090 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8091 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8092 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8093 | return; |
| 8094 | } |
| 8095 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8096 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8097 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8098 | dprintk("<-- %s\n", __func__); |
| 8099 | } |
| 8100 | |
| 8101 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8102 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8103 | struct nfs4_sequence_data *calldata = data; |
| 8104 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8105 | struct nfs4_sequence_args *args; |
| 8106 | struct nfs4_sequence_res *res; |
| 8107 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8108 | args = task->tk_msg.rpc_argp; |
| 8109 | res = task->tk_msg.rpc_resp; |
| 8110 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8111 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8112 | } |
| 8113 | |
| 8114 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8115 | .rpc_call_done = nfs41_sequence_call_done, |
| 8116 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8117 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8118 | }; |
| 8119 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8120 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8121 | struct rpc_cred *cred, |
| 8122 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8123 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8124 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8125 | struct rpc_message msg = { |
| 8126 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8127 | .rpc_cred = cred, |
| 8128 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8129 | struct rpc_task_setup task_setup_data = { |
| 8130 | .rpc_client = clp->cl_rpcclient, |
| 8131 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8132 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8133 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8134 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8135 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8136 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8137 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8138 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8139 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8140 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8141 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8142 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8143 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8144 | if (is_privileged) |
| 8145 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8146 | msg.rpc_argp = &calldata->args; |
| 8147 | msg.rpc_resp = &calldata->res; |
| 8148 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8149 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8150 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8151 | return rpc_run_task(&task_setup_data); |
| 8152 | } |
| 8153 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8154 | 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] | 8155 | { |
| 8156 | struct rpc_task *task; |
| 8157 | int ret = 0; |
| 8158 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8159 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8160 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8161 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8162 | if (IS_ERR(task)) |
| 8163 | ret = PTR_ERR(task); |
| 8164 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8165 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8166 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8167 | return ret; |
| 8168 | } |
| 8169 | |
| 8170 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8171 | { |
| 8172 | struct rpc_task *task; |
| 8173 | int ret; |
| 8174 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8175 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8176 | if (IS_ERR(task)) { |
| 8177 | ret = PTR_ERR(task); |
| 8178 | goto out; |
| 8179 | } |
| 8180 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8181 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8182 | ret = task->tk_status; |
| 8183 | rpc_put_task(task); |
| 8184 | out: |
| 8185 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8186 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8187 | } |
| 8188 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8189 | struct nfs4_reclaim_complete_data { |
| 8190 | struct nfs_client *clp; |
| 8191 | struct nfs41_reclaim_complete_args arg; |
| 8192 | struct nfs41_reclaim_complete_res res; |
| 8193 | }; |
| 8194 | |
| 8195 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8196 | { |
| 8197 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8198 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8199 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8200 | &calldata->arg.seq_args, |
| 8201 | &calldata->res.seq_res, |
| 8202 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8203 | } |
| 8204 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8205 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8206 | { |
| 8207 | switch(task->tk_status) { |
| 8208 | case 0: |
| 8209 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8210 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8211 | break; |
| 8212 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8213 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8214 | /* fall through */ |
| 8215 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8216 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8217 | case -NFS4ERR_BADSESSION: |
| 8218 | case -NFS4ERR_DEADSESSION: |
| 8219 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8220 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8221 | task->tk_status); |
| 8222 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8223 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8224 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8225 | } |
| 8226 | return 0; |
| 8227 | } |
| 8228 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8229 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8230 | { |
| 8231 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8232 | struct nfs_client *clp = calldata->clp; |
| 8233 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8234 | |
| 8235 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8236 | if (!nfs41_sequence_done(task, res)) |
| 8237 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8238 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8239 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8240 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8241 | rpc_restart_call_prepare(task); |
| 8242 | return; |
| 8243 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8244 | dprintk("<-- %s\n", __func__); |
| 8245 | } |
| 8246 | |
| 8247 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8248 | { |
| 8249 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8250 | |
| 8251 | kfree(calldata); |
| 8252 | } |
| 8253 | |
| 8254 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8255 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8256 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8257 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8258 | }; |
| 8259 | |
| 8260 | /* |
| 8261 | * Issue a global reclaim complete. |
| 8262 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8263 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8264 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8265 | { |
| 8266 | struct nfs4_reclaim_complete_data *calldata; |
| 8267 | struct rpc_task *task; |
| 8268 | struct rpc_message msg = { |
| 8269 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8270 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8271 | }; |
| 8272 | struct rpc_task_setup task_setup_data = { |
| 8273 | .rpc_client = clp->cl_rpcclient, |
| 8274 | .rpc_message = &msg, |
| 8275 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8276 | .flags = RPC_TASK_ASYNC, |
| 8277 | }; |
| 8278 | int status = -ENOMEM; |
| 8279 | |
| 8280 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8281 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8282 | if (calldata == NULL) |
| 8283 | goto out; |
| 8284 | calldata->clp = clp; |
| 8285 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8286 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8287 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8288 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8289 | msg.rpc_argp = &calldata->arg; |
| 8290 | msg.rpc_resp = &calldata->res; |
| 8291 | task_setup_data.callback_data = calldata; |
| 8292 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8293 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8294 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8295 | goto out; |
| 8296 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8297 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8298 | if (status == 0) |
| 8299 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8300 | rpc_put_task(task); |
| 8301 | out: |
| 8302 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8303 | return status; |
| 8304 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8305 | |
| 8306 | static void |
| 8307 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8308 | { |
| 8309 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8310 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8311 | |
| 8312 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8313 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8314 | &lgp->res.seq_res, task); |
| 8315 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8316 | } |
| 8317 | |
| 8318 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8319 | { |
| 8320 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8321 | |
| 8322 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8323 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8324 | dprintk("<-- %s\n", __func__); |
| 8325 | } |
| 8326 | |
| 8327 | static int |
| 8328 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8329 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8330 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8331 | struct inode *inode = lgp->args.inode; |
| 8332 | struct nfs_server *server = NFS_SERVER(inode); |
| 8333 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8334 | int nfs4err = task->tk_status; |
| 8335 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8336 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8337 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8338 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8339 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8340 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8341 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8342 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8343 | |
| 8344 | /* |
| 8345 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8346 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8347 | * retry go inband. |
| 8348 | */ |
| 8349 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8350 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8351 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8352 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8353 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8354 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8355 | */ |
| 8356 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8357 | status = -EOVERFLOW; |
| 8358 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8359 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8360 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8361 | * (or clients) writing to the same RAID stripe except when |
| 8362 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8363 | * |
| 8364 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8365 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8366 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8367 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8368 | if (lgp->args.minlength == 0) { |
| 8369 | status = -EOVERFLOW; |
| 8370 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8371 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8372 | status = -EBUSY; |
| 8373 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8374 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8375 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8376 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8377 | case -NFS4ERR_DELEG_REVOKED: |
| 8378 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8379 | case -NFS4ERR_EXPIRED: |
| 8380 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8381 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8382 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8383 | lo = NFS_I(inode)->layout; |
| 8384 | /* If the open stateid was bad, then recover it. */ |
| 8385 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8386 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8387 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8388 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8389 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8390 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8391 | break; |
| 8392 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8393 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8394 | /* |
| 8395 | * Mark the bad layout state as invalid, then retry |
| 8396 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8397 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8398 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8399 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8400 | pnfs_free_lseg_list(&head); |
| 8401 | status = -EAGAIN; |
| 8402 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8403 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8404 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8405 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8406 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8407 | if (!status) { |
| 8408 | if (exception->retry) |
| 8409 | status = -EAGAIN; |
| 8410 | else |
| 8411 | status = err; |
| 8412 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8413 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8414 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8415 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8416 | } |
| 8417 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8418 | static size_t max_response_pages(struct nfs_server *server) |
| 8419 | { |
| 8420 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8421 | return nfs_page_array_len(0, max_resp_sz); |
| 8422 | } |
| 8423 | |
| 8424 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8425 | { |
| 8426 | int i; |
| 8427 | |
| 8428 | if (!pages) |
| 8429 | return; |
| 8430 | |
| 8431 | for (i = 0; i < size; i++) { |
| 8432 | if (!pages[i]) |
| 8433 | break; |
| 8434 | __free_page(pages[i]); |
| 8435 | } |
| 8436 | kfree(pages); |
| 8437 | } |
| 8438 | |
| 8439 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8440 | { |
| 8441 | struct page **pages; |
| 8442 | int i; |
| 8443 | |
| 8444 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8445 | if (!pages) { |
| 8446 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8447 | return NULL; |
| 8448 | } |
| 8449 | |
| 8450 | for (i = 0; i < size; i++) { |
| 8451 | pages[i] = alloc_page(gfp_flags); |
| 8452 | if (!pages[i]) { |
| 8453 | dprintk("%s: failed to allocate page\n", __func__); |
| 8454 | nfs4_free_pages(pages, size); |
| 8455 | return NULL; |
| 8456 | } |
| 8457 | } |
| 8458 | |
| 8459 | return pages; |
| 8460 | } |
| 8461 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8462 | static void nfs4_layoutget_release(void *calldata) |
| 8463 | { |
| 8464 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8465 | struct inode *inode = lgp->args.inode; |
| 8466 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8467 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8468 | |
| 8469 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8470 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8471 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8472 | put_nfs_open_context(lgp->args.ctx); |
| 8473 | kfree(calldata); |
| 8474 | dprintk("<-- %s\n", __func__); |
| 8475 | } |
| 8476 | |
| 8477 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8478 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8479 | .rpc_call_done = nfs4_layoutget_done, |
| 8480 | .rpc_release = nfs4_layoutget_release, |
| 8481 | }; |
| 8482 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8483 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8484 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8485 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8486 | struct inode *inode = lgp->args.inode; |
| 8487 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8488 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8489 | struct rpc_task *task; |
| 8490 | struct rpc_message msg = { |
| 8491 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8492 | .rpc_argp = &lgp->args, |
| 8493 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8494 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8495 | }; |
| 8496 | struct rpc_task_setup task_setup_data = { |
| 8497 | .rpc_client = server->client, |
| 8498 | .rpc_message = &msg, |
| 8499 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8500 | .callback_data = lgp, |
| 8501 | .flags = RPC_TASK_ASYNC, |
| 8502 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8503 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8504 | struct nfs4_exception exception = { |
| 8505 | .inode = inode, |
| 8506 | .timeout = *timeout, |
| 8507 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8508 | int status = 0; |
| 8509 | |
| 8510 | dprintk("--> %s\n", __func__); |
| 8511 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8512 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8513 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8514 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8515 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8516 | if (!lgp->args.layout.pages) { |
| 8517 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8518 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8519 | } |
| 8520 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8521 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8522 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8523 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8524 | 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] | 8525 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8526 | task = rpc_run_task(&task_setup_data); |
| 8527 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8528 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8529 | status = rpc_wait_for_completion_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8530 | if (status == 0) { |
| 8531 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8532 | *timeout = exception.timeout; |
| 8533 | } |
| 8534 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8535 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8536 | &lgp->args.range, |
| 8537 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8538 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8539 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8540 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8541 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8542 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8543 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8544 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8545 | rpc_put_task(task); |
| 8546 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8547 | if (status) |
| 8548 | return ERR_PTR(status); |
| 8549 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8550 | } |
| 8551 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8552 | static void |
| 8553 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8554 | { |
| 8555 | struct nfs4_layoutreturn *lrp = calldata; |
| 8556 | |
| 8557 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8558 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8559 | &lrp->args.seq_args, |
| 8560 | &lrp->res.seq_res, |
| 8561 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8562 | } |
| 8563 | |
| 8564 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8565 | { |
| 8566 | struct nfs4_layoutreturn *lrp = calldata; |
| 8567 | struct nfs_server *server; |
| 8568 | |
| 8569 | dprintk("--> %s\n", __func__); |
| 8570 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8571 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8572 | return; |
| 8573 | |
| 8574 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8575 | switch (task->tk_status) { |
| 8576 | default: |
| 8577 | task->tk_status = 0; |
| 8578 | case 0: |
| 8579 | break; |
| 8580 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8581 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8582 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8583 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8584 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8585 | return; |
| 8586 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8587 | dprintk("<-- %s\n", __func__); |
| 8588 | } |
| 8589 | |
| 8590 | static void nfs4_layoutreturn_release(void *calldata) |
| 8591 | { |
| 8592 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8593 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8594 | |
| 8595 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8596 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8597 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8598 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8599 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8600 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8601 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8602 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8603 | kfree(calldata); |
| 8604 | dprintk("<-- %s\n", __func__); |
| 8605 | } |
| 8606 | |
| 8607 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8608 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8609 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8610 | .rpc_release = nfs4_layoutreturn_release, |
| 8611 | }; |
| 8612 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8613 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8614 | { |
| 8615 | struct rpc_task *task; |
| 8616 | struct rpc_message msg = { |
| 8617 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8618 | .rpc_argp = &lrp->args, |
| 8619 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8620 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8621 | }; |
| 8622 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8623 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8624 | .rpc_message = &msg, |
| 8625 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8626 | .callback_data = lrp, |
| 8627 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8628 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8629 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8630 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8631 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8632 | &task_setup_data.rpc_client, &msg); |
| 8633 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8634 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8635 | if (!sync) { |
| 8636 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8637 | if (!lrp->inode) { |
| 8638 | nfs4_layoutreturn_release(lrp); |
| 8639 | return -EAGAIN; |
| 8640 | } |
| 8641 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8642 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8643 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8644 | task = rpc_run_task(&task_setup_data); |
| 8645 | if (IS_ERR(task)) |
| 8646 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8647 | if (sync) |
| 8648 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8649 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8650 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8651 | rpc_put_task(task); |
| 8652 | return status; |
| 8653 | } |
| 8654 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8655 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8656 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8657 | struct pnfs_device *pdev, |
| 8658 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8659 | { |
| 8660 | struct nfs4_getdeviceinfo_args args = { |
| 8661 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8662 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8663 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8664 | }; |
| 8665 | struct nfs4_getdeviceinfo_res res = { |
| 8666 | .pdev = pdev, |
| 8667 | }; |
| 8668 | struct rpc_message msg = { |
| 8669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8670 | .rpc_argp = &args, |
| 8671 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8672 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8673 | }; |
| 8674 | int status; |
| 8675 | |
| 8676 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8677 | 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] | 8678 | if (res.notification & ~args.notify_types) |
| 8679 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8680 | if (res.notification != args.notify_types) |
| 8681 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8682 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8683 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8684 | |
| 8685 | return status; |
| 8686 | } |
| 8687 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8688 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8689 | struct pnfs_device *pdev, |
| 8690 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8691 | { |
| 8692 | struct nfs4_exception exception = { }; |
| 8693 | int err; |
| 8694 | |
| 8695 | do { |
| 8696 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8697 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8698 | &exception); |
| 8699 | } while (exception.retry); |
| 8700 | return err; |
| 8701 | } |
| 8702 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8703 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8704 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8705 | { |
| 8706 | struct nfs4_layoutcommit_data *data = calldata; |
| 8707 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8708 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8709 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8710 | &data->args.seq_args, |
| 8711 | &data->res.seq_res, |
| 8712 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8713 | } |
| 8714 | |
| 8715 | static void |
| 8716 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8717 | { |
| 8718 | struct nfs4_layoutcommit_data *data = calldata; |
| 8719 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8720 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8721 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8722 | return; |
| 8723 | |
| 8724 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8725 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8726 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8727 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8728 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8729 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8730 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8731 | break; |
| 8732 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8733 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8734 | rpc_restart_call_prepare(task); |
| 8735 | return; |
| 8736 | } |
| 8737 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8738 | } |
| 8739 | |
| 8740 | static void nfs4_layoutcommit_release(void *calldata) |
| 8741 | { |
| 8742 | struct nfs4_layoutcommit_data *data = calldata; |
| 8743 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8744 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8745 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8746 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8747 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8748 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8749 | kfree(data); |
| 8750 | } |
| 8751 | |
| 8752 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8753 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8754 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8755 | .rpc_release = nfs4_layoutcommit_release, |
| 8756 | }; |
| 8757 | |
| 8758 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8759 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8760 | { |
| 8761 | struct rpc_message msg = { |
| 8762 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8763 | .rpc_argp = &data->args, |
| 8764 | .rpc_resp = &data->res, |
| 8765 | .rpc_cred = data->cred, |
| 8766 | }; |
| 8767 | struct rpc_task_setup task_setup_data = { |
| 8768 | .task = &data->task, |
| 8769 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8770 | .rpc_message = &msg, |
| 8771 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8772 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8773 | }; |
| 8774 | struct rpc_task *task; |
| 8775 | int status = 0; |
| 8776 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8777 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8778 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8779 | data->args.lastbytewritten, |
| 8780 | data->args.inode->i_ino); |
| 8781 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8782 | if (!sync) { |
| 8783 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8784 | if (data->inode == NULL) { |
| 8785 | nfs4_layoutcommit_release(data); |
| 8786 | return -EAGAIN; |
| 8787 | } |
| 8788 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8789 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8790 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8791 | task = rpc_run_task(&task_setup_data); |
| 8792 | if (IS_ERR(task)) |
| 8793 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8794 | if (sync) |
| 8795 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8796 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8797 | dprintk("%s: status %d\n", __func__, status); |
| 8798 | rpc_put_task(task); |
| 8799 | return status; |
| 8800 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8801 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8802 | /** |
| 8803 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8804 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8805 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8806 | static int |
| 8807 | _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] | 8808 | struct nfs_fsinfo *info, |
| 8809 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8810 | { |
| 8811 | struct nfs41_secinfo_no_name_args args = { |
| 8812 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8813 | }; |
| 8814 | struct nfs4_secinfo_res res = { |
| 8815 | .flavors = flavors, |
| 8816 | }; |
| 8817 | struct rpc_message msg = { |
| 8818 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8819 | .rpc_argp = &args, |
| 8820 | .rpc_resp = &res, |
| 8821 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8822 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8823 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8824 | int status; |
| 8825 | |
| 8826 | if (use_integrity) { |
| 8827 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8828 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8829 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8830 | } |
| 8831 | |
| 8832 | dprintk("--> %s\n", __func__); |
| 8833 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8834 | &res.seq_res, 0); |
| 8835 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8836 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8837 | if (cred) |
| 8838 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8839 | |
| 8840 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8841 | } |
| 8842 | |
| 8843 | static int |
| 8844 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8845 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8846 | { |
| 8847 | struct nfs4_exception exception = { }; |
| 8848 | int err; |
| 8849 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8850 | /* first try using integrity protection */ |
| 8851 | err = -NFS4ERR_WRONGSEC; |
| 8852 | |
| 8853 | /* try to use integrity protection with machine cred */ |
| 8854 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8855 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8856 | flavors, true); |
| 8857 | |
| 8858 | /* |
| 8859 | * if unable to use integrity protection, or SECINFO with |
| 8860 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8861 | * disallowed by spec, but exists in deployed servers) use |
| 8862 | * the current filesystem's rpc_client and the user cred. |
| 8863 | */ |
| 8864 | if (err == -NFS4ERR_WRONGSEC) |
| 8865 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8866 | flavors, false); |
| 8867 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8868 | switch (err) { |
| 8869 | case 0: |
| 8870 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8871 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8872 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8873 | default: |
| 8874 | err = nfs4_handle_exception(server, err, &exception); |
| 8875 | } |
| 8876 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8877 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8878 | return err; |
| 8879 | } |
| 8880 | |
| 8881 | static int |
| 8882 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8883 | struct nfs_fsinfo *info) |
| 8884 | { |
| 8885 | int err; |
| 8886 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8887 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8888 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8889 | struct nfs4_secinfo4 *secinfo; |
| 8890 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8891 | |
| 8892 | page = alloc_page(GFP_KERNEL); |
| 8893 | if (!page) { |
| 8894 | err = -ENOMEM; |
| 8895 | goto out; |
| 8896 | } |
| 8897 | |
| 8898 | flavors = page_address(page); |
| 8899 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8900 | |
| 8901 | /* |
| 8902 | * Fall back on "guess and check" method if |
| 8903 | * the server doesn't support SECINFO_NO_NAME |
| 8904 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8905 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8906 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8907 | goto out_freepage; |
| 8908 | } |
| 8909 | if (err) |
| 8910 | goto out_freepage; |
| 8911 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8912 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8913 | secinfo = &flavors->flavors[i]; |
| 8914 | |
| 8915 | switch (secinfo->flavor) { |
| 8916 | case RPC_AUTH_NULL: |
| 8917 | case RPC_AUTH_UNIX: |
| 8918 | case RPC_AUTH_GSS: |
| 8919 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8920 | &secinfo->flavor_info); |
| 8921 | break; |
| 8922 | default: |
| 8923 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8924 | break; |
| 8925 | } |
| 8926 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8927 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8928 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8929 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8930 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8931 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8932 | info, flavor); |
| 8933 | if (!err) |
| 8934 | break; |
| 8935 | } |
| 8936 | } |
| 8937 | |
| 8938 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8939 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8940 | |
| 8941 | out_freepage: |
| 8942 | put_page(page); |
| 8943 | if (err == -EACCES) |
| 8944 | return -EPERM; |
| 8945 | out: |
| 8946 | return err; |
| 8947 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8948 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8949 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8950 | nfs4_stateid *stateid, |
| 8951 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8952 | { |
| 8953 | int status; |
| 8954 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8955 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8956 | }; |
| 8957 | struct nfs41_test_stateid_res res; |
| 8958 | struct rpc_message msg = { |
| 8959 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8960 | .rpc_argp = &args, |
| 8961 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8962 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8963 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8964 | struct rpc_clnt *rpc_client = server->client; |
| 8965 | |
| 8966 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8967 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8968 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8969 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8970 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8971 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8972 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8973 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8974 | if (status != NFS_OK) { |
| 8975 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8976 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8977 | } |
| 8978 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8979 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8980 | } |
| 8981 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8982 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8983 | int err, struct nfs4_exception *exception) |
| 8984 | { |
| 8985 | exception->retry = 0; |
| 8986 | switch(err) { |
| 8987 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 8988 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8989 | nfs4_handle_exception(server, err, exception); |
| 8990 | break; |
| 8991 | case -NFS4ERR_BADSESSION: |
| 8992 | case -NFS4ERR_BADSLOT: |
| 8993 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8994 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8995 | case -NFS4ERR_DEADSESSION: |
| 8996 | nfs4_do_handle_exception(server, err, exception); |
| 8997 | } |
| 8998 | } |
| 8999 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9000 | /** |
| 9001 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9002 | * |
| 9003 | * @server: server / transport on which to perform the operation |
| 9004 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9005 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9006 | * |
| 9007 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9008 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9009 | * failed or the state ID is not currently valid. |
| 9010 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9011 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9012 | nfs4_stateid *stateid, |
| 9013 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9014 | { |
| 9015 | struct nfs4_exception exception = { }; |
| 9016 | int err; |
| 9017 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9018 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9019 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9020 | } while (exception.retry); |
| 9021 | return err; |
| 9022 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9023 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9024 | struct nfs_free_stateid_data { |
| 9025 | struct nfs_server *server; |
| 9026 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9027 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9028 | }; |
| 9029 | |
| 9030 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9031 | { |
| 9032 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9033 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9034 | &data->args.seq_args, |
| 9035 | &data->res.seq_res, |
| 9036 | task); |
| 9037 | } |
| 9038 | |
| 9039 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9040 | { |
| 9041 | struct nfs_free_stateid_data *data = calldata; |
| 9042 | |
| 9043 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9044 | |
| 9045 | switch (task->tk_status) { |
| 9046 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9047 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9048 | rpc_restart_call_prepare(task); |
| 9049 | } |
| 9050 | } |
| 9051 | |
| 9052 | static void nfs41_free_stateid_release(void *calldata) |
| 9053 | { |
| 9054 | kfree(calldata); |
| 9055 | } |
| 9056 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9057 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9058 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9059 | .rpc_call_done = nfs41_free_stateid_done, |
| 9060 | .rpc_release = nfs41_free_stateid_release, |
| 9061 | }; |
| 9062 | |
| 9063 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9064 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9065 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9066 | bool privileged) |
| 9067 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9068 | struct rpc_message msg = { |
| 9069 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9070 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9071 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9072 | struct rpc_task_setup task_setup = { |
| 9073 | .rpc_client = server->client, |
| 9074 | .rpc_message = &msg, |
| 9075 | .callback_ops = &nfs41_free_stateid_ops, |
| 9076 | .flags = RPC_TASK_ASYNC, |
| 9077 | }; |
| 9078 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9079 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9080 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9081 | &task_setup.rpc_client, &msg); |
| 9082 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9083 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9084 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9085 | if (!data) |
| 9086 | return ERR_PTR(-ENOMEM); |
| 9087 | data->server = server; |
| 9088 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9089 | |
| 9090 | task_setup.callback_data = data; |
| 9091 | |
| 9092 | msg.rpc_argp = &data->args; |
| 9093 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9094 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9095 | if (privileged) |
| 9096 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9097 | |
| 9098 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9099 | } |
| 9100 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9101 | /** |
| 9102 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9103 | * |
| 9104 | * @server: server / transport on which to perform the operation |
| 9105 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9106 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9107 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9108 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9109 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9110 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9111 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9112 | const nfs4_stateid *stateid, |
| 9113 | struct rpc_cred *cred, |
| 9114 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9115 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9116 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9117 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9118 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9119 | if (IS_ERR(task)) |
| 9120 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9121 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9122 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9123 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9124 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9125 | static void |
| 9126 | 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] | 9127 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9128 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9129 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9130 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9131 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9132 | } |
| 9133 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9134 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9135 | const nfs4_stateid *s2) |
| 9136 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9137 | if (s1->type != s2->type) |
| 9138 | return false; |
| 9139 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9140 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9141 | return false; |
| 9142 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9143 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9144 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9145 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9146 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9147 | } |
| 9148 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9149 | #endif /* CONFIG_NFS_V4_1 */ |
| 9150 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9151 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9152 | const nfs4_stateid *s2) |
| 9153 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9154 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9155 | } |
| 9156 | |
| 9157 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9158 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9159 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9160 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9161 | .recover_open = nfs4_open_reclaim, |
| 9162 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9163 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9164 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9165 | }; |
| 9166 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9167 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9168 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9169 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9170 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9171 | .recover_open = nfs4_open_reclaim, |
| 9172 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9173 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9174 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9175 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9176 | }; |
| 9177 | #endif /* CONFIG_NFS_V4_1 */ |
| 9178 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9179 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9180 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9181 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9182 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9183 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9184 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9185 | }; |
| 9186 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9187 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9188 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9189 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9190 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9191 | .recover_open = nfs41_open_expired, |
| 9192 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9193 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9194 | }; |
| 9195 | #endif /* CONFIG_NFS_V4_1 */ |
| 9196 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9197 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9198 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9199 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9200 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9201 | }; |
| 9202 | |
| 9203 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9204 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9205 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9206 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9207 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9208 | }; |
| 9209 | #endif |
| 9210 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9211 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9212 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9213 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9214 | }; |
| 9215 | |
| 9216 | #if defined(CONFIG_NFS_V4_1) |
| 9217 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9218 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9219 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9220 | }; |
| 9221 | #endif /* CONFIG_NFS_V4_1 */ |
| 9222 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9223 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9224 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9225 | .init_caps = NFS_CAP_READDIRPLUS |
| 9226 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9227 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9228 | .init_client = nfs40_init_client, |
| 9229 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9230 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9231 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9232 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9233 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9234 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9235 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9236 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9237 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9238 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9239 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9240 | }; |
| 9241 | |
| 9242 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9243 | static struct nfs_seqid * |
| 9244 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9245 | { |
| 9246 | return NULL; |
| 9247 | } |
| 9248 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9249 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9250 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9251 | .init_caps = NFS_CAP_READDIRPLUS |
| 9252 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9253 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9254 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9255 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9256 | .init_client = nfs41_init_client, |
| 9257 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9258 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9259 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9260 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9261 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9262 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9263 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9264 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9265 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9266 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9267 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9268 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9269 | }; |
| 9270 | #endif |
| 9271 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9272 | #if defined(CONFIG_NFS_V4_2) |
| 9273 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9274 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9275 | .init_caps = NFS_CAP_READDIRPLUS |
| 9276 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9277 | | NFS_CAP_POSIX_LOCK |
| 9278 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9279 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9280 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9281 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9282 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9283 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9284 | | NFS_CAP_LAYOUTSTATS |
| 9285 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9286 | .init_client = nfs41_init_client, |
| 9287 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9288 | .match_stateid = nfs41_match_stateid, |
| 9289 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9290 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9291 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9292 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9293 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9294 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9295 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9296 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9297 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9298 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9299 | }; |
| 9300 | #endif |
| 9301 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9302 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9303 | [0] = &nfs_v4_0_minor_ops, |
| 9304 | #if defined(CONFIG_NFS_V4_1) |
| 9305 | [1] = &nfs_v4_1_minor_ops, |
| 9306 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9307 | #if defined(CONFIG_NFS_V4_2) |
| 9308 | [2] = &nfs_v4_2_minor_ops, |
| 9309 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9310 | }; |
| 9311 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9312 | static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9313 | { |
| 9314 | ssize_t error, error2; |
| 9315 | |
| 9316 | error = generic_listxattr(dentry, list, size); |
| 9317 | if (error < 0) |
| 9318 | return error; |
| 9319 | if (list) { |
| 9320 | list += error; |
| 9321 | size -= error; |
| 9322 | } |
| 9323 | |
| 9324 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9325 | if (error2 < 0) |
| 9326 | return error2; |
| 9327 | return error + error2; |
| 9328 | } |
| 9329 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9330 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9331 | .create = nfs_create, |
| 9332 | .lookup = nfs_lookup, |
| 9333 | .atomic_open = nfs_atomic_open, |
| 9334 | .link = nfs_link, |
| 9335 | .unlink = nfs_unlink, |
| 9336 | .symlink = nfs_symlink, |
| 9337 | .mkdir = nfs_mkdir, |
| 9338 | .rmdir = nfs_rmdir, |
| 9339 | .mknod = nfs_mknod, |
| 9340 | .rename = nfs_rename, |
| 9341 | .permission = nfs_permission, |
| 9342 | .getattr = nfs_getattr, |
| 9343 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9344 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9345 | }; |
| 9346 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9347 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9348 | .permission = nfs_permission, |
| 9349 | .getattr = nfs_getattr, |
| 9350 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9351 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9352 | }; |
| 9353 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9354 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9355 | .version = 4, /* protocol version */ |
| 9356 | .dentry_ops = &nfs4_dentry_operations, |
| 9357 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9358 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9359 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9360 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9361 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9362 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9363 | .getattr = nfs4_proc_getattr, |
| 9364 | .setattr = nfs4_proc_setattr, |
| 9365 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9366 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9367 | .access = nfs4_proc_access, |
| 9368 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9369 | .create = nfs4_proc_create, |
| 9370 | .remove = nfs4_proc_remove, |
| 9371 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9372 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9373 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9374 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9375 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9376 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9377 | .link = nfs4_proc_link, |
| 9378 | .symlink = nfs4_proc_symlink, |
| 9379 | .mkdir = nfs4_proc_mkdir, |
| 9380 | .rmdir = nfs4_proc_remove, |
| 9381 | .readdir = nfs4_proc_readdir, |
| 9382 | .mknod = nfs4_proc_mknod, |
| 9383 | .statfs = nfs4_proc_statfs, |
| 9384 | .fsinfo = nfs4_proc_fsinfo, |
| 9385 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9386 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9387 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9388 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9389 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9390 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9391 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9392 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9393 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9394 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9395 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9396 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9397 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9398 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9399 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9400 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9401 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9402 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9403 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9404 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9405 | .create_server = nfs4_create_server, |
| 9406 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9407 | }; |
| 9408 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9409 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9410 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9411 | .list = nfs4_xattr_list_nfs4_acl, |
| 9412 | .get = nfs4_xattr_get_nfs4_acl, |
| 9413 | .set = nfs4_xattr_set_nfs4_acl, |
| 9414 | }; |
| 9415 | |
| 9416 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9417 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9418 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9419 | &nfs4_xattr_nfs4_label_handler, |
| 9420 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9421 | NULL |
| 9422 | }; |
| 9423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9424 | /* |
| 9425 | * Local variables: |
| 9426 | * c-basic-offset: 8 |
| 9427 | * End: |
| 9428 | */ |