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> |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 57 | #include <linux/iversion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 76 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 77 | /* file attributes which can be mapped to nfs attributes */ |
| 78 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 79 | | ATTR_UID \ |
| 80 | | ATTR_GID \ |
| 81 | | ATTR_SIZE \ |
| 82 | | ATTR_ATIME \ |
| 83 | | ATTR_MTIME \ |
| 84 | | ATTR_CTIME \ |
| 85 | | ATTR_ATIME_SET \ |
| 86 | | ATTR_MTIME_SET) |
| 87 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 88 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 89 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 90 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | 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] | 92 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 93 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 94 | 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] | 95 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 96 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 97 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 98 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 100 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 101 | struct rpc_cred *cred, |
| 102 | struct nfs4_slot *slot, |
| 103 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 104 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 105 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 106 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 107 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 108 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 109 | |
| 110 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 111 | static inline struct nfs4_label * |
| 112 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 113 | struct iattr *sattr, struct nfs4_label *label) |
| 114 | { |
| 115 | int err; |
| 116 | |
| 117 | if (label == NULL) |
| 118 | return NULL; |
| 119 | |
| 120 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 121 | return NULL; |
| 122 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 123 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 124 | &dentry->d_name, (void **)&label->label, &label->len); |
| 125 | if (err == 0) |
| 126 | return label; |
| 127 | |
| 128 | return NULL; |
| 129 | } |
| 130 | static inline void |
| 131 | nfs4_label_release_security(struct nfs4_label *label) |
| 132 | { |
| 133 | if (label) |
| 134 | security_release_secctx(label->label, label->len); |
| 135 | } |
| 136 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 137 | { |
| 138 | if (label) |
| 139 | return server->attr_bitmask; |
| 140 | |
| 141 | return server->attr_bitmask_nl; |
| 142 | } |
| 143 | #else |
| 144 | static inline struct nfs4_label * |
| 145 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 146 | struct iattr *sattr, struct nfs4_label *l) |
| 147 | { return NULL; } |
| 148 | static inline void |
| 149 | nfs4_label_release_security(struct nfs4_label *label) |
| 150 | { return; } |
| 151 | static inline u32 * |
| 152 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 153 | { return server->attr_bitmask; } |
| 154 | #endif |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 157 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 159 | if (err >= -1000) |
| 160 | return err; |
| 161 | switch (err) { |
| 162 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 163 | case -NFS4ERR_LAYOUTTRYLATER: |
| 164 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 165 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 166 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 167 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 168 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 169 | case -NFS4ERR_BADOWNER: |
| 170 | case -NFS4ERR_BADNAME: |
| 171 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 172 | case -NFS4ERR_SHARE_DENIED: |
| 173 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 174 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 175 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 176 | case -NFS4ERR_FILE_OPEN: |
| 177 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 178 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 180 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 181 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 183 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /* |
| 187 | * This is our standard bitmap for GETATTR requests. |
| 188 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 189 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | FATTR4_WORD0_TYPE |
| 191 | | FATTR4_WORD0_CHANGE |
| 192 | | FATTR4_WORD0_SIZE |
| 193 | | FATTR4_WORD0_FSID |
| 194 | | FATTR4_WORD0_FILEID, |
| 195 | FATTR4_WORD1_MODE |
| 196 | | FATTR4_WORD1_NUMLINKS |
| 197 | | FATTR4_WORD1_OWNER |
| 198 | | FATTR4_WORD1_OWNER_GROUP |
| 199 | | FATTR4_WORD1_RAWDEV |
| 200 | | FATTR4_WORD1_SPACE_USED |
| 201 | | FATTR4_WORD1_TIME_ACCESS |
| 202 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 203 | | FATTR4_WORD1_TIME_MODIFY |
| 204 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 205 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 206 | FATTR4_WORD2_SECURITY_LABEL |
| 207 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 210 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 211 | FATTR4_WORD0_TYPE |
| 212 | | FATTR4_WORD0_CHANGE |
| 213 | | FATTR4_WORD0_SIZE |
| 214 | | FATTR4_WORD0_FSID |
| 215 | | FATTR4_WORD0_FILEID, |
| 216 | FATTR4_WORD1_MODE |
| 217 | | FATTR4_WORD1_NUMLINKS |
| 218 | | FATTR4_WORD1_OWNER |
| 219 | | FATTR4_WORD1_OWNER_GROUP |
| 220 | | FATTR4_WORD1_RAWDEV |
| 221 | | FATTR4_WORD1_SPACE_USED |
| 222 | | FATTR4_WORD1_TIME_ACCESS |
| 223 | | FATTR4_WORD1_TIME_METADATA |
| 224 | | FATTR4_WORD1_TIME_MODIFY, |
| 225 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 226 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 227 | | FATTR4_WORD2_SECURITY_LABEL |
| 228 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 229 | }; |
| 230 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 231 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 232 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 233 | | FATTR4_WORD0_FILEID, |
| 234 | }; |
| 235 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 236 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | FATTR4_WORD0_FILES_AVAIL |
| 238 | | FATTR4_WORD0_FILES_FREE |
| 239 | | FATTR4_WORD0_FILES_TOTAL, |
| 240 | FATTR4_WORD1_SPACE_AVAIL |
| 241 | | FATTR4_WORD1_SPACE_FREE |
| 242 | | FATTR4_WORD1_SPACE_TOTAL |
| 243 | }; |
| 244 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 245 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | FATTR4_WORD0_MAXLINK |
| 247 | | FATTR4_WORD0_MAXNAME, |
| 248 | 0 |
| 249 | }; |
| 250 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 251 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | | FATTR4_WORD0_MAXREAD |
| 253 | | FATTR4_WORD0_MAXWRITE |
| 254 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 255 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 256 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 257 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 258 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | }; |
| 260 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 261 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 262 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 263 | | FATTR4_WORD0_SIZE |
| 264 | | FATTR4_WORD0_FSID |
| 265 | | FATTR4_WORD0_FILEID |
| 266 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 267 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 268 | | FATTR4_WORD1_OWNER_GROUP |
| 269 | | FATTR4_WORD1_RAWDEV |
| 270 | | FATTR4_WORD1_SPACE_USED |
| 271 | | FATTR4_WORD1_TIME_ACCESS |
| 272 | | FATTR4_WORD1_TIME_METADATA |
| 273 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 274 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 277 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct nfs4_readdir_arg *readdir) |
| 279 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 280 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 281 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 284 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | readdir->cookie = 0; |
| 290 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 291 | if (cookie == 2) |
| 292 | return; |
| 293 | |
| 294 | /* |
| 295 | * NFSv4 servers do not return entries for '.' and '..' |
| 296 | * Therefore, we fake these entries here. We let '.' |
| 297 | * have cookie 0 and '..' have cookie 1. Note that |
| 298 | * when talking to the server, we always send cookie 0 |
| 299 | * instead of 1 or 2. |
| 300 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 301 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | if (cookie == 0) { |
| 304 | *p++ = xdr_one; /* next */ |
| 305 | *p++ = xdr_zero; /* cookie, first word */ |
| 306 | *p++ = xdr_one; /* cookie, second word */ |
| 307 | *p++ = xdr_one; /* entry len */ |
| 308 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 309 | p++; |
| 310 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 311 | *p++ = htonl(attrs); /* bitmap */ |
| 312 | *p++ = htonl(12); /* attribute buffer length */ |
| 313 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 314 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | *p++ = xdr_one; /* next */ |
| 318 | *p++ = xdr_zero; /* cookie, first word */ |
| 319 | *p++ = xdr_two; /* cookie, second word */ |
| 320 | *p++ = xdr_two; /* entry len */ |
| 321 | memcpy(p, "..\0\0", 4); /* entry */ |
| 322 | p++; |
| 323 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 324 | *p++ = htonl(attrs); /* bitmap */ |
| 325 | *p++ = htonl(12); /* attribute buffer length */ |
| 326 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 327 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | readdir->pgbase = (char *)p - (char *)start; |
| 330 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 331 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 334 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 335 | nfs4_stateid *stateid, |
| 336 | struct rpc_cred *cred) |
| 337 | { |
| 338 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 339 | |
| 340 | ops->test_and_free_expired(server, stateid, cred); |
| 341 | } |
| 342 | |
| 343 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 344 | nfs4_stateid *stateid, |
| 345 | struct rpc_cred *cred) |
| 346 | { |
| 347 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 348 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 349 | } |
| 350 | |
| 351 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 352 | const nfs4_stateid *stateid, |
| 353 | struct rpc_cred *cred) |
| 354 | { |
| 355 | nfs4_stateid tmp; |
| 356 | |
| 357 | nfs4_stateid_copy(&tmp, stateid); |
| 358 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 359 | } |
| 360 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 361 | static long nfs4_update_delay(long *timeout) |
| 362 | { |
| 363 | long ret; |
| 364 | if (!timeout) |
| 365 | return NFS4_POLL_RETRY_MAX; |
| 366 | if (*timeout <= 0) |
| 367 | *timeout = NFS4_POLL_RETRY_MIN; |
| 368 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 369 | *timeout = NFS4_POLL_RETRY_MAX; |
| 370 | ret = *timeout; |
| 371 | *timeout <<= 1; |
| 372 | return ret; |
| 373 | } |
| 374 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 375 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 376 | { |
| 377 | int res = 0; |
| 378 | |
| 379 | might_sleep(); |
| 380 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 381 | freezable_schedule_timeout_killable_unsafe( |
| 382 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 383 | if (fatal_signal_pending(current)) |
| 384 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 385 | return res; |
| 386 | } |
| 387 | |
| 388 | /* This is the error handling routine for processes that are allowed |
| 389 | * to sleep. |
| 390 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 391 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 392 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 393 | { |
| 394 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 395 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 396 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 397 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 398 | int ret = errorcode; |
| 399 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 400 | exception->delay = 0; |
| 401 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 402 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 403 | |
| 404 | if (stateid == NULL && state != NULL) |
| 405 | stateid = &state->stateid; |
| 406 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 407 | switch(errorcode) { |
| 408 | case 0: |
| 409 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 410 | case -NFS4ERR_DELEG_REVOKED: |
| 411 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 412 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 413 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 414 | if (inode != NULL && stateid != NULL) { |
| 415 | nfs_inode_find_state_and_recover(inode, |
| 416 | stateid); |
| 417 | goto wait_on_recovery; |
| 418 | } |
| 419 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 420 | if (inode) { |
| 421 | int err; |
| 422 | |
| 423 | err = nfs_async_inode_return_delegation(inode, |
| 424 | stateid); |
| 425 | if (err == 0) |
| 426 | goto wait_on_recovery; |
| 427 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 428 | exception->retry = 1; |
| 429 | break; |
| 430 | } |
| 431 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 432 | if (state == NULL) |
| 433 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 434 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 435 | if (ret < 0) |
| 436 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 437 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 438 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 439 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 440 | nfs4_schedule_lease_recovery(clp); |
| 441 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 442 | case -NFS4ERR_MOVED: |
| 443 | ret = nfs4_schedule_migration_recovery(server); |
| 444 | if (ret < 0) |
| 445 | break; |
| 446 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 447 | case -NFS4ERR_LEASE_MOVED: |
| 448 | nfs4_schedule_lease_moved_recovery(clp); |
| 449 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 450 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 451 | case -NFS4ERR_BADSESSION: |
| 452 | case -NFS4ERR_BADSLOT: |
| 453 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 454 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 455 | case -NFS4ERR_DEADSESSION: |
| 456 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 457 | case -NFS4ERR_SEQ_MISORDERED: |
| 458 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 459 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 460 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 461 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 462 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 463 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 464 | if (exception->timeout > HZ) { |
| 465 | /* We have retried a decent amount, time to |
| 466 | * fail |
| 467 | */ |
| 468 | ret = -EBUSY; |
| 469 | break; |
| 470 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 471 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 472 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 473 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 474 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 475 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 476 | exception->delay = 1; |
| 477 | return 0; |
| 478 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 479 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 480 | case -NFS4ERR_OLD_STATEID: |
| 481 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 482 | break; |
| 483 | case -NFS4ERR_BADOWNER: |
| 484 | /* The following works around a Linux server bug! */ |
| 485 | case -NFS4ERR_BADNAME: |
| 486 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 487 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 488 | exception->retry = 1; |
| 489 | printk(KERN_WARNING "NFS: v4 server %s " |
| 490 | "does not accept raw " |
| 491 | "uid/gids. " |
| 492 | "Reenabling the idmapper.\n", |
| 493 | server->nfs_client->cl_hostname); |
| 494 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 495 | } |
| 496 | /* We failed to handle the error */ |
| 497 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 498 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 499 | exception->recovering = 1; |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | /* This is the error handling routine for processes that are allowed |
| 504 | * to sleep. |
| 505 | */ |
| 506 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 507 | { |
| 508 | struct nfs_client *clp = server->nfs_client; |
| 509 | int ret; |
| 510 | |
| 511 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 512 | if (exception->delay) { |
| 513 | ret = nfs4_delay(server->client, &exception->timeout); |
| 514 | goto out_retry; |
| 515 | } |
| 516 | if (exception->recovering) { |
| 517 | ret = nfs4_wait_clnt_recover(clp); |
| 518 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 519 | return -EIO; |
| 520 | goto out_retry; |
| 521 | } |
| 522 | return ret; |
| 523 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 524 | if (ret == 0) |
| 525 | exception->retry = 1; |
| 526 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 527 | } |
| 528 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 529 | static int |
| 530 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 531 | int errorcode, struct nfs4_exception *exception) |
| 532 | { |
| 533 | struct nfs_client *clp = server->nfs_client; |
| 534 | int ret; |
| 535 | |
| 536 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 537 | if (exception->delay) { |
| 538 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 539 | goto out_retry; |
| 540 | } |
| 541 | if (exception->recovering) { |
| 542 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 543 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 544 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 545 | goto out_retry; |
| 546 | } |
| 547 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 548 | ret = -EIO; |
| 549 | return ret; |
| 550 | out_retry: |
| 551 | if (ret == 0) |
| 552 | exception->retry = 1; |
| 553 | return ret; |
| 554 | } |
| 555 | |
| 556 | static int |
| 557 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 558 | struct nfs4_state *state, long *timeout) |
| 559 | { |
| 560 | struct nfs4_exception exception = { |
| 561 | .state = state, |
| 562 | }; |
| 563 | |
| 564 | if (task->tk_status >= 0) |
| 565 | return 0; |
| 566 | if (timeout) |
| 567 | exception.timeout = *timeout; |
| 568 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 569 | task->tk_status, |
| 570 | &exception); |
| 571 | if (exception.delay && timeout) |
| 572 | *timeout = exception.timeout; |
| 573 | if (exception.retry) |
| 574 | return -EAGAIN; |
| 575 | return 0; |
| 576 | } |
| 577 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 578 | /* |
| 579 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 580 | * or 'false' otherwise. |
| 581 | */ |
| 582 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 583 | { |
| 584 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 585 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 586 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 587 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 588 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | spin_lock(&clp->cl_lock); |
| 591 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 592 | clp->cl_last_renewal = timestamp; |
| 593 | spin_unlock(&clp->cl_lock); |
| 594 | } |
| 595 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 596 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 597 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 598 | struct nfs_client *clp = server->nfs_client; |
| 599 | |
| 600 | if (!nfs4_has_session(clp)) |
| 601 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 602 | } |
| 603 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 604 | struct nfs4_call_sync_data { |
| 605 | const struct nfs_server *seq_server; |
| 606 | struct nfs4_sequence_args *seq_args; |
| 607 | struct nfs4_sequence_res *seq_res; |
| 608 | }; |
| 609 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 610 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 611 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 612 | { |
| 613 | args->sa_slot = NULL; |
| 614 | args->sa_cache_this = cache_reply; |
| 615 | args->sa_privileged = 0; |
| 616 | |
| 617 | res->sr_slot = NULL; |
| 618 | } |
| 619 | |
| 620 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 621 | { |
| 622 | args->sa_privileged = 1; |
| 623 | } |
| 624 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 625 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 626 | { |
| 627 | struct nfs4_slot *slot = res->sr_slot; |
| 628 | struct nfs4_slot_table *tbl; |
| 629 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 630 | tbl = slot->table; |
| 631 | spin_lock(&tbl->slot_tbl_lock); |
| 632 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 633 | nfs4_free_slot(tbl, slot); |
| 634 | spin_unlock(&tbl->slot_tbl_lock); |
| 635 | |
| 636 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | static int nfs40_sequence_done(struct rpc_task *task, |
| 640 | struct nfs4_sequence_res *res) |
| 641 | { |
| 642 | if (res->sr_slot != NULL) |
| 643 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 644 | return 1; |
| 645 | } |
| 646 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 647 | #if defined(CONFIG_NFS_V4_1) |
| 648 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 649 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 650 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 651 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 652 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 653 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 654 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 655 | if (!slot) |
| 656 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 657 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 658 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 659 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 660 | /* Bump the slot sequence number */ |
| 661 | if (slot->seq_done) |
| 662 | slot->seq_nr++; |
| 663 | slot->seq_done = 0; |
| 664 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 665 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 666 | /* Be nice to the server: try to ensure that the last transmitted |
| 667 | * value for highest_user_slotid <= target_highest_slotid |
| 668 | */ |
| 669 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 670 | send_new_highest_used_slotid = true; |
| 671 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 672 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 673 | send_new_highest_used_slotid = false; |
| 674 | goto out_unlock; |
| 675 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 676 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 677 | |
| 678 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 679 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 680 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 681 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 682 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 683 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 684 | if (waitqueue_active(&tbl->slot_waitq)) |
| 685 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 686 | } |
| 687 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 688 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 689 | { |
| 690 | nfs41_release_slot(res->sr_slot); |
| 691 | res->sr_slot = NULL; |
| 692 | } |
| 693 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 694 | static int nfs41_sequence_process(struct rpc_task *task, |
| 695 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 696 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 697 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 698 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 699 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 700 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 701 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 702 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 703 | if (slot == NULL) |
| 704 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 705 | /* don't increment the sequence number if the task wasn't sent */ |
| 706 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 707 | goto out; |
| 708 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 709 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 710 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 711 | if (slot->interrupted) { |
Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 712 | if (res->sr_status != -NFS4ERR_DELAY) |
| 713 | slot->interrupted = 0; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 714 | interrupted = true; |
| 715 | } |
| 716 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 717 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 718 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 719 | switch (res->sr_status) { |
| 720 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 721 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 722 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 723 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 724 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 725 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 726 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 727 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 728 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 729 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 730 | case 1: |
| 731 | /* |
| 732 | * sr_status remains 1 if an RPC level error occurred. |
| 733 | * The server may or may not have processed the sequence |
| 734 | * operation.. |
| 735 | * Mark the slot as having hosted an interrupted RPC call. |
| 736 | */ |
| 737 | slot->interrupted = 1; |
| 738 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 739 | case -NFS4ERR_DELAY: |
| 740 | /* The server detected a resend of the RPC call and |
| 741 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 742 | * of RFC5661. |
| 743 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 744 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 745 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 746 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 747 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 748 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 749 | case -NFS4ERR_BADSLOT: |
| 750 | /* |
| 751 | * The slot id we used was probably retired. Try again |
| 752 | * using a different slot id. |
| 753 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 754 | if (slot->seq_nr < slot->table->target_highest_slotid) |
| 755 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 756 | goto retry_nowait; |
| 757 | case -NFS4ERR_SEQ_MISORDERED: |
| 758 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 759 | * Was the last operation on this sequence interrupted? |
| 760 | * If so, retry after bumping the sequence number. |
| 761 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 762 | if (interrupted) |
| 763 | goto retry_new_seq; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 764 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 765 | * Could this slot have been previously retired? |
| 766 | * If so, then the server may be expecting seq_nr = 1! |
| 767 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 768 | if (slot->seq_nr != 1) { |
| 769 | slot->seq_nr = 1; |
| 770 | goto retry_nowait; |
| 771 | } |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 772 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 773 | case -NFS4ERR_SEQ_FALSE_RETRY: |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 774 | if (interrupted) |
| 775 | goto retry_new_seq; |
| 776 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 777 | default: |
| 778 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 779 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 780 | } |
| 781 | out: |
| 782 | /* The session may be reset by one of the error handlers. */ |
| 783 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 784 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 785 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 786 | session_recover: |
| 787 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 788 | goto retry_nowait; |
| 789 | retry_new_seq: |
| 790 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 791 | retry_nowait: |
| 792 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 793 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 794 | task->tk_status = 0; |
| 795 | ret = 0; |
| 796 | } |
| 797 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 798 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 799 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 800 | goto out; |
| 801 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 802 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 803 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 804 | |
| 805 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 806 | { |
| 807 | if (!nfs41_sequence_process(task, res)) |
| 808 | return 0; |
| 809 | if (res->sr_slot != NULL) |
| 810 | nfs41_sequence_free_slot(res); |
| 811 | return 1; |
| 812 | |
| 813 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 814 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 815 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 816 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 817 | { |
| 818 | if (res->sr_slot == NULL) |
| 819 | return 1; |
| 820 | if (res->sr_slot->table->session != NULL) |
| 821 | return nfs41_sequence_process(task, res); |
| 822 | return nfs40_sequence_done(task, res); |
| 823 | } |
| 824 | |
| 825 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 826 | { |
| 827 | if (res->sr_slot != NULL) { |
| 828 | if (res->sr_slot->table->session != NULL) |
| 829 | nfs41_sequence_free_slot(res); |
| 830 | else |
| 831 | nfs40_sequence_free_slot(res); |
| 832 | } |
| 833 | } |
| 834 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 835 | 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] | 836 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 837 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 838 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 839 | if (!res->sr_slot->table->session) |
| 840 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 841 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 842 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 843 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 844 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 845 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 846 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 847 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 848 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 849 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 850 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 851 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 852 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 853 | } |
| 854 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 855 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 856 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 857 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 858 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 859 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 860 | } |
| 861 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 862 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 863 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 864 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 865 | }; |
| 866 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 867 | static void |
| 868 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 869 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 870 | { |
| 871 | struct rpc_task *task; |
| 872 | |
| 873 | task = _nfs41_proc_sequence(client, cred, slot, true); |
| 874 | if (!IS_ERR(task)) |
| 875 | rpc_put_task_async(task); |
| 876 | } |
| 877 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 878 | #else /* !CONFIG_NFS_V4_1 */ |
| 879 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 880 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 881 | { |
| 882 | return nfs40_sequence_done(task, res); |
| 883 | } |
| 884 | |
| 885 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 886 | { |
| 887 | if (res->sr_slot != NULL) |
| 888 | nfs40_sequence_free_slot(res); |
| 889 | } |
| 890 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 891 | int nfs4_sequence_done(struct rpc_task *task, |
| 892 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 893 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 894 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 895 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 896 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 897 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 898 | static void |
| 899 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 900 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 901 | { |
| 902 | WARN_ON_ONCE(1); |
| 903 | slot->interrupted = 0; |
| 904 | } |
| 905 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 906 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 907 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 908 | static |
| 909 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 910 | struct nfs4_sequence_res *res, |
| 911 | struct nfs4_slot *slot) |
| 912 | { |
| 913 | if (!slot) |
| 914 | return; |
| 915 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 916 | args->sa_slot = slot; |
| 917 | |
| 918 | res->sr_slot = slot; |
| 919 | res->sr_timestamp = jiffies; |
| 920 | res->sr_status_flags = 0; |
| 921 | res->sr_status = 1; |
| 922 | |
| 923 | } |
| 924 | |
| 925 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 926 | struct nfs4_sequence_args *args, |
| 927 | struct nfs4_sequence_res *res, |
| 928 | struct rpc_task *task) |
| 929 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 930 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 931 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 932 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 933 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 934 | /* slot already allocated? */ |
| 935 | if (res->sr_slot != NULL) |
| 936 | goto out_start; |
| 937 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 938 | if (session) { |
| 939 | tbl = &session->fc_slot_table; |
| 940 | task->tk_timeout = 0; |
| 941 | } |
| 942 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 943 | for (;;) { |
| 944 | spin_lock(&tbl->slot_tbl_lock); |
| 945 | /* The state manager will wait until the slot table is empty */ |
| 946 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 947 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 948 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 949 | slot = nfs4_alloc_slot(tbl); |
| 950 | if (IS_ERR(slot)) { |
| 951 | /* Try again in 1/4 second */ |
| 952 | if (slot == ERR_PTR(-ENOMEM)) |
| 953 | task->tk_timeout = HZ >> 2; |
| 954 | goto out_sleep; |
| 955 | } |
| 956 | spin_unlock(&tbl->slot_tbl_lock); |
| 957 | |
| 958 | if (likely(!slot->interrupted)) |
| 959 | break; |
| 960 | nfs4_sequence_process_interrupted(client, |
| 961 | slot, task->tk_msg.rpc_cred); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 962 | } |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 963 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 964 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 965 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 966 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 967 | out_start: |
| 968 | rpc_call_start(task); |
| 969 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 970 | |
| 971 | out_sleep: |
| 972 | if (args->sa_privileged) |
| 973 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 974 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 975 | else |
| 976 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 977 | spin_unlock(&tbl->slot_tbl_lock); |
| 978 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 979 | } |
| 980 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 981 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 982 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 983 | { |
| 984 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 985 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 986 | data->seq_args, data->seq_res, task); |
| 987 | } |
| 988 | |
| 989 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 990 | { |
| 991 | struct nfs4_call_sync_data *data = calldata; |
| 992 | nfs4_sequence_done(task, data->seq_res); |
| 993 | } |
| 994 | |
| 995 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 996 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 997 | .rpc_call_done = nfs40_call_sync_done, |
| 998 | }; |
| 999 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1000 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1001 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1002 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1003 | struct nfs4_sequence_args *args, |
| 1004 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1005 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1006 | int ret; |
| 1007 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1008 | struct nfs_client *clp = server->nfs_client; |
| 1009 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1010 | .seq_server = server, |
| 1011 | .seq_args = args, |
| 1012 | .seq_res = res, |
| 1013 | }; |
| 1014 | struct rpc_task_setup task_setup = { |
| 1015 | .rpc_client = clnt, |
| 1016 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1017 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1018 | .callback_data = &data |
| 1019 | }; |
| 1020 | |
| 1021 | task = rpc_run_task(&task_setup); |
| 1022 | if (IS_ERR(task)) |
| 1023 | ret = PTR_ERR(task); |
| 1024 | else { |
| 1025 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1026 | rpc_put_task(task); |
| 1027 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1028 | return ret; |
| 1029 | } |
| 1030 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1031 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1032 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1033 | struct rpc_message *msg, |
| 1034 | struct nfs4_sequence_args *args, |
| 1035 | struct nfs4_sequence_res *res, |
| 1036 | int cache_reply) |
| 1037 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1038 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1039 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1040 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1042 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1043 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | { |
| 1045 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1046 | |
| 1047 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1048 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1049 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(dir)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1050 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1051 | nfsi->attrtimeo_timestamp = jiffies; |
| 1052 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | nfs_force_lookup_revalidate(dir); |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1054 | if (cinfo->before != inode_peek_iversion_raw(dir)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1055 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1056 | NFS_INO_INVALID_ACL; |
| 1057 | } |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1058 | inode_set_iversion_raw(dir, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1059 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1060 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1061 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | spin_unlock(&dir->i_lock); |
| 1063 | } |
| 1064 | |
| 1065 | struct nfs4_opendata { |
| 1066 | struct kref kref; |
| 1067 | struct nfs_openargs o_arg; |
| 1068 | struct nfs_openres o_res; |
| 1069 | struct nfs_open_confirmargs c_arg; |
| 1070 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1071 | struct nfs4_string owner_name; |
| 1072 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1073 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1075 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1077 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | struct nfs4_state_owner *owner; |
| 1079 | struct nfs4_state *state; |
| 1080 | struct iattr attrs; |
| 1081 | unsigned long timestamp; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1082 | bool rpc_done; |
| 1083 | bool file_created; |
| 1084 | bool is_recover; |
| 1085 | bool cancelled; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1086 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1088 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1089 | struct nfs4_open_createattrs { |
| 1090 | struct nfs4_label *label; |
| 1091 | struct iattr *sattr; |
| 1092 | const __u32 verf[2]; |
| 1093 | }; |
| 1094 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1095 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1096 | int err, struct nfs4_exception *exception) |
| 1097 | { |
| 1098 | if (err != -EINVAL) |
| 1099 | return false; |
| 1100 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1101 | return false; |
| 1102 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1103 | exception->retry = 1; |
| 1104 | return true; |
| 1105 | } |
| 1106 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1107 | static u32 |
| 1108 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1109 | fmode_t fmode, int openflags) |
| 1110 | { |
| 1111 | u32 res = 0; |
| 1112 | |
| 1113 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1114 | case FMODE_READ: |
| 1115 | res = NFS4_SHARE_ACCESS_READ; |
| 1116 | break; |
| 1117 | case FMODE_WRITE: |
| 1118 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1119 | break; |
| 1120 | case FMODE_READ|FMODE_WRITE: |
| 1121 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1122 | } |
| 1123 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1124 | goto out; |
| 1125 | /* Want no delegation if we're using O_DIRECT */ |
| 1126 | if (openflags & O_DIRECT) |
| 1127 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1128 | out: |
| 1129 | return res; |
| 1130 | } |
| 1131 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1132 | static enum open_claim_type4 |
| 1133 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1134 | enum open_claim_type4 claim) |
| 1135 | { |
| 1136 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1137 | return claim; |
| 1138 | switch (claim) { |
| 1139 | default: |
| 1140 | return claim; |
| 1141 | case NFS4_OPEN_CLAIM_FH: |
| 1142 | return NFS4_OPEN_CLAIM_NULL; |
| 1143 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1144 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1145 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1146 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1147 | } |
| 1148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
| 1150 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1151 | { |
| 1152 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1153 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1154 | p->o_res.seqid = p->o_arg.seqid; |
| 1155 | p->c_res.seqid = p->c_arg.seqid; |
| 1156 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1157 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1158 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1159 | 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] | 1160 | } |
| 1161 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1162 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1163 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1164 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1165 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1166 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1167 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1168 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1169 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1170 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1171 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1172 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1173 | struct nfs4_opendata *p; |
| 1174 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1175 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1176 | if (p == NULL) |
| 1177 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1178 | |
| 1179 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1180 | if (IS_ERR(p->f_label)) |
| 1181 | goto err_free_p; |
| 1182 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1183 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1184 | if (IS_ERR(p->a_label)) |
| 1185 | goto err_free_f; |
| 1186 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1187 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1188 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1189 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1190 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1191 | nfs_sb_active(dentry->d_sb); |
| 1192 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1193 | p->dir = parent; |
| 1194 | p->owner = sp; |
| 1195 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1196 | p->o_arg.open_flags = flags; |
| 1197 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1198 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1199 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1200 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1201 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1202 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1203 | * will return permission denied for all bits until close */ |
| 1204 | if (!(flags & O_EXCL)) { |
| 1205 | /* ask server to check for all possible rights as results |
| 1206 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1207 | switch (p->o_arg.claim) { |
| 1208 | default: |
| 1209 | break; |
| 1210 | case NFS4_OPEN_CLAIM_NULL: |
| 1211 | case NFS4_OPEN_CLAIM_FH: |
| 1212 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1213 | NFS4_ACCESS_MODIFY | |
| 1214 | NFS4_ACCESS_EXTEND | |
| 1215 | NFS4_ACCESS_EXECUTE; |
| 1216 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1217 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1218 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1219 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1220 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1221 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1222 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1223 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1224 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1225 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1226 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1227 | case NFS4_OPEN_CLAIM_NULL: |
| 1228 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1229 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1230 | p->o_arg.fh = NFS_FH(dir); |
| 1231 | break; |
| 1232 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1233 | case NFS4_OPEN_CLAIM_FH: |
| 1234 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1235 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1236 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1237 | } |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1238 | if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1239 | p->o_arg.u.attrs = &p->attrs; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1240 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1241 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1242 | memcpy(p->o_arg.u.verifier.data, c->verf, |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1243 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1244 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1245 | p->c_arg.fh = &p->o_res.fh; |
| 1246 | p->c_arg.stateid = &p->o_res.stateid; |
| 1247 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1248 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1249 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1250 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1251 | |
| 1252 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1253 | nfs4_label_free(p->a_label); |
| 1254 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1255 | nfs4_label_free(p->f_label); |
| 1256 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1257 | kfree(p); |
| 1258 | err: |
| 1259 | dput(parent); |
| 1260 | return NULL; |
| 1261 | } |
| 1262 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1263 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1264 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1265 | struct nfs4_opendata *p = container_of(kref, |
| 1266 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1267 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1268 | |
| 1269 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1270 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1271 | if (p->state != NULL) |
| 1272 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1273 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1274 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1275 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1276 | nfs4_label_free(p->f_label); |
| 1277 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1278 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1279 | dput(p->dentry); |
| 1280 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1281 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1282 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1283 | kfree(p); |
| 1284 | } |
| 1285 | |
| 1286 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1287 | { |
| 1288 | if (p != NULL) |
| 1289 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1290 | } |
| 1291 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1292 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1293 | fmode_t fmode) |
| 1294 | { |
| 1295 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1296 | case FMODE_READ|FMODE_WRITE: |
| 1297 | return state->n_rdwr != 0; |
| 1298 | case FMODE_WRITE: |
| 1299 | return state->n_wronly != 0; |
| 1300 | case FMODE_READ: |
| 1301 | return state->n_rdonly != 0; |
| 1302 | } |
| 1303 | WARN_ON_ONCE(1); |
| 1304 | return false; |
| 1305 | } |
| 1306 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1307 | 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] | 1308 | { |
| 1309 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1310 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1311 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1312 | goto out; |
| 1313 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1314 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1315 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1316 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1317 | break; |
| 1318 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1319 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1320 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1321 | break; |
| 1322 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1323 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1324 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1325 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1326 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1327 | return ret; |
| 1328 | } |
| 1329 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1330 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1331 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1332 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1333 | if (delegation == NULL) |
| 1334 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1335 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1336 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1337 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1338 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1339 | switch (claim) { |
| 1340 | case NFS4_OPEN_CLAIM_NULL: |
| 1341 | case NFS4_OPEN_CLAIM_FH: |
| 1342 | break; |
| 1343 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1344 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1345 | break; |
| 1346 | default: |
| 1347 | return 0; |
| 1348 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1349 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1350 | return 1; |
| 1351 | } |
| 1352 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1353 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1354 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1356 | case FMODE_WRITE: |
| 1357 | state->n_wronly++; |
| 1358 | break; |
| 1359 | case FMODE_READ: |
| 1360 | state->n_rdonly++; |
| 1361 | break; |
| 1362 | case FMODE_READ|FMODE_WRITE: |
| 1363 | state->n_rdwr++; |
| 1364 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1365 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1368 | #ifdef CONFIG_NFS_V4_1 |
| 1369 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1370 | { |
| 1371 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1372 | return true; |
| 1373 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1374 | return true; |
| 1375 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1376 | return true; |
| 1377 | return false; |
| 1378 | } |
| 1379 | #endif /* CONFIG_NFS_V4_1 */ |
| 1380 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1381 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1382 | { |
| 1383 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1384 | wake_up_all(&state->waitq); |
| 1385 | } |
| 1386 | |
| 1387 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
| 1388 | const nfs4_stateid *stateid) |
| 1389 | { |
| 1390 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
| 1391 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
| 1392 | |
| 1393 | if (stateid_seqid == state_seqid + 1U || |
| 1394 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
| 1395 | nfs_state_log_update_open_stateid(state); |
| 1396 | else |
| 1397 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 1398 | } |
| 1399 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1400 | 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] | 1401 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1402 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1403 | bool need_recover = false; |
| 1404 | |
| 1405 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1406 | need_recover = true; |
| 1407 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1408 | need_recover = true; |
| 1409 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1410 | need_recover = true; |
| 1411 | if (need_recover) |
| 1412 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1413 | } |
| 1414 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1415 | /* |
| 1416 | * Check for whether or not the caller may update the open stateid |
| 1417 | * to the value passed in by stateid. |
| 1418 | * |
| 1419 | * Note: This function relies heavily on the server implementing |
| 1420 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1421 | * correctly. |
| 1422 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1423 | * are then incremented on every state transition. |
| 1424 | */ |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1425 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1426 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1427 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1428 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
| 1429 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1430 | if (stateid->seqid == cpu_to_be32(1)) |
| 1431 | nfs_state_log_update_open_stateid(state); |
| 1432 | else |
| 1433 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1434 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1435 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1436 | |
| 1437 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1438 | nfs_state_log_out_of_order_open_stateid(state, stateid); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1439 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1440 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1441 | return false; |
| 1442 | } |
| 1443 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1444 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1445 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1446 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1447 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1448 | if (state->n_wronly) |
| 1449 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1450 | if (state->n_rdonly) |
| 1451 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1452 | if (state->n_rdwr) |
| 1453 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1454 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1455 | } |
| 1456 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1457 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1458 | nfs4_stateid *stateid, fmode_t fmode) |
| 1459 | { |
| 1460 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1461 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1462 | case FMODE_WRITE: |
| 1463 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1464 | break; |
| 1465 | case FMODE_READ: |
| 1466 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1467 | break; |
| 1468 | case 0: |
| 1469 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1470 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1471 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1472 | } |
| 1473 | if (stateid == NULL) |
| 1474 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1475 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1476 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1477 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1478 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1479 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1480 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1481 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1482 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1483 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1484 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1485 | out: |
| 1486 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1487 | } |
| 1488 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1489 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1490 | nfs4_stateid *arg_stateid, |
| 1491 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1492 | { |
| 1493 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1494 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1495 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1496 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1497 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1498 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1499 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1500 | } |
| 1501 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1502 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1503 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1504 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1505 | DEFINE_WAIT(wait); |
| 1506 | int status = 0; |
| 1507 | for (;;) { |
| 1508 | |
| 1509 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1510 | return; |
| 1511 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1512 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1513 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1514 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1515 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1516 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1517 | break; |
| 1518 | |
| 1519 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1520 | /* |
| 1521 | * Ensure we process the state changes in the same order |
| 1522 | * in which the server processed them by delaying the |
| 1523 | * update of the stateid until we are in sequence. |
| 1524 | */ |
| 1525 | write_sequnlock(&state->seqlock); |
| 1526 | spin_unlock(&state->owner->so_lock); |
| 1527 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1528 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1529 | if (!signal_pending(current)) { |
| 1530 | if (schedule_timeout(5*HZ) == 0) |
| 1531 | status = -EAGAIN; |
| 1532 | else |
| 1533 | status = 0; |
| 1534 | } else |
| 1535 | status = -EINTR; |
| 1536 | finish_wait(&state->waitq, &wait); |
| 1537 | rcu_read_lock(); |
| 1538 | spin_lock(&state->owner->so_lock); |
| 1539 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1540 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1541 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1542 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1543 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1544 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1545 | nfs_test_and_clear_all_open_stateid(state); |
| 1546 | } |
| 1547 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1548 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1549 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1550 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1551 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1552 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1555 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1556 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1557 | fmode_t fmode, |
| 1558 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1560 | /* |
| 1561 | * Protect the call to nfs4_state_set_mode_locked and |
| 1562 | * serialise the stateid update |
| 1563 | */ |
| 1564 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1565 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1566 | switch (fmode) { |
| 1567 | case FMODE_READ: |
| 1568 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1569 | break; |
| 1570 | case FMODE_WRITE: |
| 1571 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1572 | break; |
| 1573 | case FMODE_READ|FMODE_WRITE: |
| 1574 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1575 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1576 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1577 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1581 | const nfs4_stateid *deleg_stateid, |
| 1582 | fmode_t fmode) |
| 1583 | { |
| 1584 | /* |
| 1585 | * Protect the call to nfs4_state_set_mode_locked and |
| 1586 | * serialise the stateid update |
| 1587 | */ |
| 1588 | write_seqlock(&state->seqlock); |
| 1589 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1590 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1591 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1594 | static int update_open_stateid(struct nfs4_state *state, |
| 1595 | const nfs4_stateid *open_stateid, |
| 1596 | const nfs4_stateid *delegation, |
| 1597 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1598 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1599 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1600 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1601 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1602 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1603 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1604 | int ret = 0; |
| 1605 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1606 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1607 | |
| 1608 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1609 | spin_lock(&state->owner->so_lock); |
| 1610 | if (open_stateid != NULL) { |
| 1611 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1612 | ret = 1; |
| 1613 | } |
| 1614 | |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1615 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1616 | if (deleg_cur == NULL) |
| 1617 | goto no_delegation; |
| 1618 | |
| 1619 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1620 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1621 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1622 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1623 | goto no_delegation_unlock; |
| 1624 | |
| 1625 | if (delegation == NULL) |
| 1626 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1627 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1628 | goto no_delegation_unlock; |
| 1629 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1630 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1631 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1632 | ret = 1; |
| 1633 | no_delegation_unlock: |
| 1634 | spin_unlock(&deleg_cur->lock); |
| 1635 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1636 | if (ret) |
| 1637 | update_open_stateflags(state, fmode); |
| 1638 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1639 | rcu_read_unlock(); |
| 1640 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1641 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1642 | nfs4_schedule_state_manager(clp); |
| 1643 | if (freeme.type != 0) |
| 1644 | nfs4_test_and_free_stateid(server, &freeme, |
| 1645 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1646 | |
| 1647 | return ret; |
| 1648 | } |
| 1649 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1650 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1651 | const nfs4_stateid *stateid) |
| 1652 | { |
| 1653 | struct nfs4_state *state = lsp->ls_state; |
| 1654 | bool ret = false; |
| 1655 | |
| 1656 | spin_lock(&state->state_lock); |
| 1657 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1658 | goto out_noupdate; |
| 1659 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1660 | goto out_noupdate; |
| 1661 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1662 | ret = true; |
| 1663 | out_noupdate: |
| 1664 | spin_unlock(&state->state_lock); |
| 1665 | return ret; |
| 1666 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1667 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1668 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1669 | { |
| 1670 | struct nfs_delegation *delegation; |
| 1671 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1672 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1673 | rcu_read_lock(); |
| 1674 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1675 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1676 | rcu_read_unlock(); |
| 1677 | return; |
| 1678 | } |
| 1679 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1680 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1681 | } |
| 1682 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1683 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1684 | { |
| 1685 | struct nfs4_state *state = opendata->state; |
| 1686 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1687 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1688 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1689 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1690 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1691 | nfs4_stateid stateid; |
| 1692 | int ret = -EAGAIN; |
| 1693 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1694 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1695 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1696 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1697 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1698 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1699 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1700 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1701 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1702 | rcu_read_lock(); |
| 1703 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1704 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1705 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1706 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1707 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1708 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1709 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1710 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1711 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1712 | if (!opendata->is_recover) { |
| 1713 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1714 | if (ret != 0) |
| 1715 | goto out; |
| 1716 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1717 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1718 | |
| 1719 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1720 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1721 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1722 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1723 | out: |
| 1724 | return ERR_PTR(ret); |
| 1725 | out_return_state: |
| 1726 | atomic_inc(&state->count); |
| 1727 | return state; |
| 1728 | } |
| 1729 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1730 | static void |
| 1731 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1732 | { |
| 1733 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1734 | struct nfs_delegation *delegation; |
| 1735 | int delegation_flags = 0; |
| 1736 | |
| 1737 | rcu_read_lock(); |
| 1738 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1739 | if (delegation) |
| 1740 | delegation_flags = delegation->flags; |
| 1741 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1742 | switch (data->o_arg.claim) { |
| 1743 | default: |
| 1744 | break; |
| 1745 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1746 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1747 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1748 | "returning a delegation for " |
| 1749 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1750 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1751 | return; |
| 1752 | } |
| 1753 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1754 | nfs_inode_set_delegation(state->inode, |
| 1755 | data->owner->so_cred, |
| 1756 | &data->o_res); |
| 1757 | else |
| 1758 | nfs_inode_reclaim_delegation(state->inode, |
| 1759 | data->owner->so_cred, |
| 1760 | &data->o_res); |
| 1761 | } |
| 1762 | |
| 1763 | /* |
| 1764 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1765 | * and update the nfs4_state. |
| 1766 | */ |
| 1767 | static struct nfs4_state * |
| 1768 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1769 | { |
| 1770 | struct inode *inode = data->state->inode; |
| 1771 | struct nfs4_state *state = data->state; |
| 1772 | int ret; |
| 1773 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1774 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1775 | if (data->rpc_status) |
| 1776 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1777 | /* cached opens have already been processed */ |
| 1778 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1779 | } |
| 1780 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1781 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1782 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1783 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1784 | |
| 1785 | if (data->o_res.delegation_type != 0) |
| 1786 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1787 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1788 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1789 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1790 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1791 | |
| 1792 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1793 | } |
| 1794 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1795 | static struct inode * |
| 1796 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1797 | { |
| 1798 | struct inode *inode; |
| 1799 | |
| 1800 | switch (data->o_arg.claim) { |
| 1801 | case NFS4_OPEN_CLAIM_NULL: |
| 1802 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1803 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1804 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1805 | return ERR_PTR(-EAGAIN); |
| 1806 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1807 | &data->f_attr, data->f_label); |
| 1808 | break; |
| 1809 | default: |
| 1810 | inode = d_inode(data->dentry); |
| 1811 | ihold(inode); |
| 1812 | nfs_refresh_inode(inode, &data->f_attr); |
| 1813 | } |
| 1814 | return inode; |
| 1815 | } |
| 1816 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1817 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1818 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1819 | { |
| 1820 | struct nfs4_state *state; |
| 1821 | struct inode *inode; |
| 1822 | |
| 1823 | inode = nfs4_opendata_get_inode(data); |
| 1824 | if (IS_ERR(inode)) |
| 1825 | return ERR_CAST(inode); |
| 1826 | if (data->state != NULL && data->state->inode == inode) { |
| 1827 | state = data->state; |
| 1828 | atomic_inc(&state->count); |
| 1829 | } else |
| 1830 | state = nfs4_get_open_state(inode, data->owner); |
| 1831 | iput(inode); |
| 1832 | if (state == NULL) |
| 1833 | state = ERR_PTR(-ENOMEM); |
| 1834 | return state; |
| 1835 | } |
| 1836 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1837 | static struct nfs4_state * |
| 1838 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1839 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1840 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1841 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1842 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1843 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1844 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1845 | goto out; |
| 1846 | } |
| 1847 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1848 | state = nfs4_opendata_find_nfs4_state(data); |
| 1849 | if (IS_ERR(state)) |
| 1850 | goto out; |
| 1851 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1852 | if (data->o_res.delegation_type != 0) |
| 1853 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1854 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1855 | data->o_arg.fmode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1856 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1857 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1858 | return state; |
| 1859 | } |
| 1860 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1861 | static struct nfs4_state * |
| 1862 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1863 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1864 | struct nfs4_state *ret; |
| 1865 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1866 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1867 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1868 | else |
| 1869 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1870 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1871 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1872 | } |
| 1873 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1874 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1875 | { |
| 1876 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1877 | struct nfs_open_context *ctx; |
| 1878 | |
| 1879 | spin_lock(&state->inode->i_lock); |
| 1880 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1881 | if (ctx->state != state) |
| 1882 | continue; |
| 1883 | get_nfs_open_context(ctx); |
| 1884 | spin_unlock(&state->inode->i_lock); |
| 1885 | return ctx; |
| 1886 | } |
| 1887 | spin_unlock(&state->inode->i_lock); |
| 1888 | return ERR_PTR(-ENOENT); |
| 1889 | } |
| 1890 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1891 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1892 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1893 | { |
| 1894 | struct nfs4_opendata *opendata; |
| 1895 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1896 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1897 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1898 | if (opendata == NULL) |
| 1899 | return ERR_PTR(-ENOMEM); |
| 1900 | opendata->state = state; |
| 1901 | atomic_inc(&state->count); |
| 1902 | return opendata; |
| 1903 | } |
| 1904 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1905 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1906 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1907 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1908 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1909 | int ret; |
| 1910 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1911 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1912 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1913 | opendata->o_arg.open_flags = 0; |
| 1914 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1915 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1916 | NFS_SB(opendata->dentry->d_sb), |
| 1917 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1918 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1919 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1920 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1921 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1922 | if (ret != 0) |
| 1923 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1924 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1925 | if (IS_ERR(newstate)) |
| 1926 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1927 | if (newstate != opendata->state) |
| 1928 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1929 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1930 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1934 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1935 | int ret; |
| 1936 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1937 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1938 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1939 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1940 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1941 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1942 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1943 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1944 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1945 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1946 | if (ret != 0) |
| 1947 | return ret; |
| 1948 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1949 | if (ret != 0) |
| 1950 | return ret; |
| 1951 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1952 | if (ret != 0) |
| 1953 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1954 | /* |
| 1955 | * We may have performed cached opens for all three recoveries. |
| 1956 | * Check if we need to update the current stateid. |
| 1957 | */ |
| 1958 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1959 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1960 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1961 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1962 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1963 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1964 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1965 | return 0; |
| 1966 | } |
| 1967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | /* |
| 1969 | * OPEN_RECLAIM: |
| 1970 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1972 | 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] | 1973 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1974 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1975 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1976 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | int status; |
| 1978 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1979 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1980 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1981 | if (IS_ERR(opendata)) |
| 1982 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1983 | rcu_read_lock(); |
| 1984 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1985 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1986 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1987 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1988 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1989 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1990 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | return status; |
| 1992 | } |
| 1993 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1994 | 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] | 1995 | { |
| 1996 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1997 | struct nfs4_exception exception = { }; |
| 1998 | int err; |
| 1999 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2000 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2001 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2002 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2003 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2004 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2005 | break; |
| 2006 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | } while (exception.retry); |
| 2008 | return err; |
| 2009 | } |
| 2010 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2011 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2012 | { |
| 2013 | struct nfs_open_context *ctx; |
| 2014 | int ret; |
| 2015 | |
| 2016 | ctx = nfs4_state_find_open_context(state); |
| 2017 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2018 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2019 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2020 | put_nfs_open_context(ctx); |
| 2021 | return ret; |
| 2022 | } |
| 2023 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2024 | static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, struct file_lock *fl, int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2026 | switch (err) { |
| 2027 | default: |
| 2028 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2029 | "%d.\n", __func__, err); |
| 2030 | case 0: |
| 2031 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2032 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2033 | case -ESTALE: |
| 2034 | break; |
| 2035 | case -NFS4ERR_BADSESSION: |
| 2036 | case -NFS4ERR_BADSLOT: |
| 2037 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2038 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2039 | case -NFS4ERR_DEADSESSION: |
| 2040 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2041 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 2042 | return -EAGAIN; |
| 2043 | case -NFS4ERR_STALE_CLIENTID: |
| 2044 | case -NFS4ERR_STALE_STATEID: |
| 2045 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2046 | /* Don't recall a delegation if it was lost */ |
| 2047 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2048 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2049 | case -NFS4ERR_MOVED: |
| 2050 | nfs4_schedule_migration_recovery(server); |
| 2051 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2052 | case -NFS4ERR_LEASE_MOVED: |
| 2053 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2054 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2055 | case -NFS4ERR_DELEG_REVOKED: |
| 2056 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2057 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2058 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2059 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2060 | nfs_inode_find_state_and_recover(state->inode, |
| 2061 | stateid); |
| 2062 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2063 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2064 | case -NFS4ERR_DELAY: |
| 2065 | case -NFS4ERR_GRACE: |
| 2066 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2067 | ssleep(1); |
| 2068 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2069 | case -ENOMEM: |
| 2070 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2071 | if (fl) { |
| 2072 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2073 | if (lsp) |
| 2074 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2075 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2076 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2077 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | return err; |
| 2079 | } |
| 2080 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2081 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2082 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2083 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2084 | { |
| 2085 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2086 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2087 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2088 | |
| 2089 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2090 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2091 | if (IS_ERR(opendata)) |
| 2092 | return PTR_ERR(opendata); |
| 2093 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2094 | write_seqlock(&state->seqlock); |
| 2095 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2096 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2097 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2098 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2099 | case FMODE_READ|FMODE_WRITE: |
| 2100 | case FMODE_WRITE: |
| 2101 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2102 | if (err) |
| 2103 | break; |
| 2104 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2105 | if (err) |
| 2106 | break; |
| 2107 | case FMODE_READ: |
| 2108 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2109 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2110 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2111 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2112 | } |
| 2113 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2114 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2115 | { |
| 2116 | struct nfs4_opendata *data = calldata; |
| 2117 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2118 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2119 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2120 | } |
| 2121 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2122 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2123 | { |
| 2124 | struct nfs4_opendata *data = calldata; |
| 2125 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2126 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2127 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2128 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2129 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2130 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2131 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2132 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2133 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2134 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | static void nfs4_open_confirm_release(void *calldata) |
| 2138 | { |
| 2139 | struct nfs4_opendata *data = calldata; |
| 2140 | struct nfs4_state *state = NULL; |
| 2141 | |
| 2142 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2143 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2144 | goto out_free; |
| 2145 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2146 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2147 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2148 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2149 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2150 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2151 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2152 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2156 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2157 | .rpc_call_done = nfs4_open_confirm_done, |
| 2158 | .rpc_release = nfs4_open_confirm_release, |
| 2159 | }; |
| 2160 | |
| 2161 | /* |
| 2162 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2163 | */ |
| 2164 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2165 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2166 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2167 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2168 | struct rpc_message msg = { |
| 2169 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2170 | .rpc_argp = &data->c_arg, |
| 2171 | .rpc_resp = &data->c_res, |
| 2172 | .rpc_cred = data->owner->so_cred, |
| 2173 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2174 | struct rpc_task_setup task_setup_data = { |
| 2175 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2176 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2177 | .callback_ops = &nfs4_open_confirm_ops, |
| 2178 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2179 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2180 | .flags = RPC_TASK_ASYNC, |
| 2181 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | int status; |
| 2183 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2184 | 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] | 2185 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2186 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2187 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2188 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2189 | if (data->is_recover) |
| 2190 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2191 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2192 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2193 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2194 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2195 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2196 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2197 | smp_wmb(); |
| 2198 | } else |
| 2199 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2200 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | return status; |
| 2202 | } |
| 2203 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2204 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2206 | struct nfs4_opendata *data = calldata; |
| 2207 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2208 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2209 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2210 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2211 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2212 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2213 | /* |
| 2214 | * Check if we still need to send an OPEN call, or if we can use |
| 2215 | * a delegation instead. |
| 2216 | */ |
| 2217 | if (data->state != NULL) { |
| 2218 | struct nfs_delegation *delegation; |
| 2219 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2220 | 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] | 2221 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2222 | rcu_read_lock(); |
| 2223 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2224 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2225 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2226 | rcu_read_unlock(); |
| 2227 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2228 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2229 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2230 | switch (claim) { |
| 2231 | default: |
| 2232 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2233 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2234 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2235 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2236 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2237 | case NFS4_OPEN_CLAIM_FH: |
| 2238 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2239 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2240 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2241 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2242 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2243 | &data->o_res.seq_res, |
| 2244 | task) != 0) |
| 2245 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2246 | |
| 2247 | /* Set the create mode (note dependency on the session type) */ |
| 2248 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2249 | if (data->o_arg.open_flags & O_EXCL) { |
| 2250 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2251 | if (nfs4_has_persistent_session(clp)) |
| 2252 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2253 | else if (clp->cl_mvops->minor_version > 0) |
| 2254 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2255 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2256 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2257 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2258 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2259 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2260 | out_no_action: |
| 2261 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2262 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2263 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2264 | } |
| 2265 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2266 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2267 | { |
| 2268 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2270 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2271 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2272 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2273 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2274 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2275 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2276 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2277 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2278 | case S_IFREG: |
| 2279 | break; |
| 2280 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2281 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2282 | break; |
| 2283 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2284 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2285 | break; |
| 2286 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2287 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2288 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2289 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2290 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2291 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2292 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2293 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2294 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2295 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2296 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2297 | static void nfs4_open_release(void *calldata) |
| 2298 | { |
| 2299 | struct nfs4_opendata *data = calldata; |
| 2300 | struct nfs4_state *state = NULL; |
| 2301 | |
| 2302 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2303 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2304 | goto out_free; |
| 2305 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2306 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2307 | goto out_free; |
| 2308 | /* In case we need an open_confirm, no cleanup! */ |
| 2309 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2310 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2311 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2312 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2313 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2314 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2315 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2319 | .rpc_call_prepare = nfs4_open_prepare, |
| 2320 | .rpc_call_done = nfs4_open_done, |
| 2321 | .rpc_release = nfs4_open_release, |
| 2322 | }; |
| 2323 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2324 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2325 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2326 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2327 | struct nfs_server *server = NFS_SERVER(dir); |
| 2328 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2329 | struct nfs_openres *o_res = &data->o_res; |
| 2330 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2331 | struct rpc_message msg = { |
| 2332 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2333 | .rpc_argp = o_arg, |
| 2334 | .rpc_resp = o_res, |
| 2335 | .rpc_cred = data->owner->so_cred, |
| 2336 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2337 | struct rpc_task_setup task_setup_data = { |
| 2338 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2339 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2340 | .callback_ops = &nfs4_open_ops, |
| 2341 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2342 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2343 | .flags = RPC_TASK_ASYNC, |
| 2344 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2345 | int status; |
| 2346 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2347 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2348 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2349 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2350 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2351 | data->cancelled = false; |
| 2352 | data->is_recover = false; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2353 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2354 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2355 | data->is_recover = true; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2356 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2357 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2358 | if (IS_ERR(task)) |
| 2359 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2360 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2361 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2362 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2363 | smp_wmb(); |
| 2364 | } else |
| 2365 | status = data->rpc_status; |
| 2366 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2367 | |
| 2368 | return status; |
| 2369 | } |
| 2370 | |
| 2371 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2372 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2373 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2374 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2375 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2376 | |
| 2377 | status = nfs4_run_open_task(data, 1); |
| 2378 | if (status != 0 || !data->rpc_done) |
| 2379 | return status; |
| 2380 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2381 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2382 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2383 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2384 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2385 | |
| 2386 | return status; |
| 2387 | } |
| 2388 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2389 | /* |
| 2390 | * Additional permission checks in order to distinguish between an |
| 2391 | * open for read, and an open for execute. This works around the |
| 2392 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2393 | * the same. |
| 2394 | * Note that in the non-execute case, we want to turn off permission |
| 2395 | * checking if we just created a new file (POSIX open() semantics). |
| 2396 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2397 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2398 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2399 | struct nfs4_state *state, fmode_t fmode, |
| 2400 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2401 | { |
| 2402 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2403 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2404 | |
| 2405 | /* access call failed or for some reason the server doesn't |
| 2406 | * support any access modes -- defer access call until later */ |
| 2407 | if (opendata->o_res.access_supported == 0) |
| 2408 | return 0; |
| 2409 | |
| 2410 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2411 | /* |
| 2412 | * Use openflags to check for exec, because fmode won't |
| 2413 | * always have FMODE_EXEC set when file open for exec. |
| 2414 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2415 | if (openflags & __FMODE_EXEC) { |
| 2416 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2417 | if (S_ISDIR(state->inode->i_mode)) |
| 2418 | mask = NFS4_ACCESS_LOOKUP; |
| 2419 | else |
| 2420 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2421 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2422 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2423 | |
| 2424 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2425 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2426 | nfs_access_add_cache(state->inode, &cache); |
| 2427 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2428 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2429 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2430 | return 0; |
| 2431 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2432 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2433 | } |
| 2434 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2435 | /* |
| 2436 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2437 | */ |
| 2438 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2439 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2440 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2441 | struct nfs_server *server = NFS_SERVER(dir); |
| 2442 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2443 | struct nfs_openres *o_res = &data->o_res; |
| 2444 | int status; |
| 2445 | |
| 2446 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2447 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2448 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2449 | if (status != 0) { |
| 2450 | if (status == -NFS4ERR_BADNAME && |
| 2451 | !(o_arg->open_flags & O_CREAT)) |
| 2452 | return -ENOENT; |
| 2453 | return status; |
| 2454 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2455 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2456 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2457 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2458 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2459 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2460 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2461 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2462 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2463 | if (data->file_created || |
| 2464 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2465 | update_changeattr(dir, &o_res->cinfo, |
| 2466 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2467 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2468 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2469 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2471 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2473 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2475 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2476 | nfs4_sequence_free_slot(&o_res->seq_res); |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2477 | 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] | 2478 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2479 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | /* |
| 2483 | * OPEN_EXPIRED: |
| 2484 | * reclaim state on the server after a network partition. |
| 2485 | * Assumes caller holds the appropriate lock |
| 2486 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2487 | 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] | 2488 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2489 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2490 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2492 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2493 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2494 | if (IS_ERR(opendata)) |
| 2495 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2496 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2497 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2498 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2499 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2500 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2503 | 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] | 2504 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2505 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2506 | struct nfs4_exception exception = { }; |
| 2507 | int err; |
| 2508 | |
| 2509 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2510 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2511 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2512 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2513 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2514 | switch (err) { |
| 2515 | default: |
| 2516 | goto out; |
| 2517 | case -NFS4ERR_GRACE: |
| 2518 | case -NFS4ERR_DELAY: |
| 2519 | nfs4_handle_exception(server, err, &exception); |
| 2520 | err = 0; |
| 2521 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2522 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2523 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2524 | return err; |
| 2525 | } |
| 2526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2528 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2530 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2532 | ctx = nfs4_state_find_open_context(state); |
| 2533 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2534 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2535 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2536 | put_nfs_open_context(ctx); |
| 2537 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2540 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2541 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2542 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2543 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2544 | write_seqlock(&state->seqlock); |
| 2545 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2546 | write_sequnlock(&state->seqlock); |
| 2547 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2548 | } |
| 2549 | |
| 2550 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2551 | { |
| 2552 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2553 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2557 | { |
| 2558 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2559 | nfs40_clear_delegation_stateid(state); |
| 2560 | return nfs4_open_expired(sp, state); |
| 2561 | } |
| 2562 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2563 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2564 | nfs4_stateid *stateid, |
| 2565 | struct rpc_cred *cred) |
| 2566 | { |
| 2567 | return -NFS4ERR_BAD_STATEID; |
| 2568 | } |
| 2569 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2570 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2571 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2572 | nfs4_stateid *stateid, |
| 2573 | struct rpc_cred *cred) |
| 2574 | { |
| 2575 | int status; |
| 2576 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2577 | switch (stateid->type) { |
| 2578 | default: |
| 2579 | break; |
| 2580 | case NFS4_INVALID_STATEID_TYPE: |
| 2581 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2582 | return -NFS4ERR_BAD_STATEID; |
| 2583 | case NFS4_REVOKED_STATEID_TYPE: |
| 2584 | goto out_free; |
| 2585 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2586 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2587 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2588 | switch (status) { |
| 2589 | case -NFS4ERR_EXPIRED: |
| 2590 | case -NFS4ERR_ADMIN_REVOKED: |
| 2591 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2592 | break; |
| 2593 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2594 | return status; |
| 2595 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2596 | out_free: |
| 2597 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2598 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2599 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2600 | } |
| 2601 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2602 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2603 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2604 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2605 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2606 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2607 | struct rpc_cred *cred; |
| 2608 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2609 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2610 | /* Get the delegation credential for use by test/free_stateid */ |
| 2611 | rcu_read_lock(); |
| 2612 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2613 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2614 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2615 | return; |
| 2616 | } |
| 2617 | |
| 2618 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2619 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2620 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2621 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2622 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2623 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2624 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2625 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2626 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2627 | cred = get_rpccred(delegation->cred); |
| 2628 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2629 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2630 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2631 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2632 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2633 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2634 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2638 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2639 | * |
| 2640 | * @state: NFSv4 state for an inode |
| 2641 | * |
| 2642 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2643 | * Otherwise a negative NFS4ERR value is returned. |
| 2644 | */ |
| 2645 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2646 | { |
| 2647 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2648 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2649 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2650 | |
| 2651 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2652 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2653 | |
| 2654 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2655 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2656 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2657 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2658 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2659 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2660 | spin_unlock(&state->state_lock); |
| 2661 | |
| 2662 | nfs4_put_lock_state(prev); |
| 2663 | prev = lsp; |
| 2664 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2665 | status = nfs41_test_and_free_expired_stateid(server, |
| 2666 | &lsp->ls_stateid, |
| 2667 | cred); |
| 2668 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2669 | if (status == -NFS4ERR_EXPIRED || |
| 2670 | status == -NFS4ERR_BAD_STATEID) { |
| 2671 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2672 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2673 | if (!recover_lost_locks) |
| 2674 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2675 | } else if (status != NFS_OK) { |
| 2676 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2677 | nfs4_put_lock_state(prev); |
| 2678 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2679 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2680 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2681 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2682 | } |
| 2683 | spin_unlock(&state->state_lock); |
| 2684 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2685 | out: |
| 2686 | return ret; |
| 2687 | } |
| 2688 | |
| 2689 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2690 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2691 | * |
| 2692 | * @state: NFSv4 state for an inode |
| 2693 | * |
| 2694 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2695 | * Otherwise a negative NFS4ERR value is returned. |
| 2696 | */ |
| 2697 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2698 | { |
| 2699 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2700 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2701 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2702 | int status; |
| 2703 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2704 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2705 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2706 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2707 | return NFS_OK; |
| 2708 | return -NFS4ERR_OPENMODE; |
| 2709 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2710 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2711 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2712 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2713 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2714 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2715 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2716 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2717 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2718 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2719 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2720 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2721 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2722 | if (nfs_open_stateid_recover_openmode(state)) |
| 2723 | return -NFS4ERR_OPENMODE; |
| 2724 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2728 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2729 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2730 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2731 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2732 | status = nfs41_check_expired_locks(state); |
| 2733 | if (status != NFS_OK) |
| 2734 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2735 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2736 | if (status != NFS_OK) |
| 2737 | status = nfs4_open_expired(sp, state); |
| 2738 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2739 | } |
| 2740 | #endif |
| 2741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2743 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2744 | * fields corresponding to attributes that were used to store the verifier. |
| 2745 | * Make sure we clobber those fields in the later setattr call |
| 2746 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2747 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2748 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2749 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2750 | const u32 *attrset = opendata->o_res.attrset; |
| 2751 | |
| 2752 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2753 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2754 | sattr->ia_valid |= ATTR_ATIME; |
| 2755 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2756 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2757 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2758 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2759 | |
| 2760 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2761 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
Benjamin Coddington | 501e7a4 | 2017-06-02 11:21:34 -0400 | [diff] [blame] | 2762 | (attrset[1] & FATTR4_WORD1_MODE || |
| 2763 | attrset[2] & FATTR4_WORD2_MODE_UMASK)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2764 | sattr->ia_valid &= ~ATTR_MODE; |
| 2765 | |
| 2766 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2767 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2768 | } |
| 2769 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2770 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2771 | fmode_t fmode, |
| 2772 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2773 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2774 | { |
| 2775 | struct nfs4_state_owner *sp = opendata->owner; |
| 2776 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2777 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2778 | struct nfs4_state *state; |
| 2779 | unsigned int seq; |
| 2780 | int ret; |
| 2781 | |
| 2782 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2783 | |
| 2784 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2785 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2786 | goto out; |
| 2787 | |
| 2788 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2789 | ret = PTR_ERR(state); |
| 2790 | if (IS_ERR(state)) |
| 2791 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2792 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2793 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2794 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2795 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2796 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2797 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2798 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2799 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2800 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2801 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2802 | alias = d_exact_alias(dentry, state->inode); |
| 2803 | if (!alias) |
| 2804 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2805 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2806 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2807 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2808 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2809 | } |
| 2810 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2811 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2812 | } |
| 2813 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2814 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2815 | if (ret != 0) |
| 2816 | goto out; |
| 2817 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2818 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2819 | nfs_inode_attach_open_context(ctx); |
| 2820 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2821 | nfs4_schedule_stateid_recovery(server, state); |
| 2822 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2823 | out: |
| 2824 | return ret; |
| 2825 | } |
| 2826 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2827 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2828 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2830 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2831 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2832 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2833 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2834 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | { |
| 2836 | struct nfs4_state_owner *sp; |
| 2837 | struct nfs4_state *state = NULL; |
| 2838 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2839 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2840 | struct dentry *dentry = ctx->dentry; |
| 2841 | struct rpc_cred *cred = ctx->cred; |
| 2842 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2843 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2844 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2845 | struct iattr *sattr = c->sattr; |
| 2846 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2847 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2848 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | |
| 2850 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2852 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2853 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2855 | goto out_err; |
| 2856 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2857 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2858 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2859 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2860 | if (d_really_is_positive(dentry)) |
| 2861 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2862 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2863 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2864 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2865 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 2866 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2867 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2868 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2870 | if (label) { |
| 2871 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2872 | if (IS_ERR(olabel)) { |
| 2873 | status = PTR_ERR(olabel); |
| 2874 | goto err_opendata_put; |
| 2875 | } |
| 2876 | } |
| 2877 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2878 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2879 | if (!opendata->f_attr.mdsthreshold) { |
| 2880 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2881 | if (!opendata->f_attr.mdsthreshold) |
| 2882 | goto err_free_label; |
| 2883 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2884 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2885 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2886 | if (d_really_is_positive(dentry)) |
| 2887 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2888 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2889 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2890 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2891 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2892 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2893 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2894 | 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] | 2895 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2896 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2897 | /* |
| 2898 | * send create attributes which was not set by open |
| 2899 | * with an extra setattr. |
| 2900 | */ |
| 2901 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2902 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2903 | status = nfs4_do_setattr(state->inode, cred, |
| 2904 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2905 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2906 | if (status == 0) { |
| 2907 | nfs_setattr_update_inode(state->inode, sattr, |
| 2908 | opendata->o_res.f_attr); |
| 2909 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2910 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2911 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2912 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2913 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2914 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2915 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2916 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2917 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2918 | opendata->f_attr.mdsthreshold = NULL; |
| 2919 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2920 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2921 | nfs4_label_free(olabel); |
| 2922 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2923 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2926 | err_free_label: |
| 2927 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2928 | err_opendata_put: |
| 2929 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2930 | err_put_state_owner: |
| 2931 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | return status; |
| 2934 | } |
| 2935 | |
| 2936 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2937 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2938 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2939 | int flags, |
| 2940 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2941 | struct nfs4_label *label, |
| 2942 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2944 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | struct nfs4_exception exception = { }; |
| 2946 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2947 | struct nfs4_open_createattrs c = { |
| 2948 | .label = label, |
| 2949 | .sattr = sattr, |
| 2950 | .verf = { |
| 2951 | [0] = (__u32)jiffies, |
| 2952 | [1] = (__u32)current->pid, |
| 2953 | }, |
| 2954 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | int status; |
| 2956 | |
| 2957 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2958 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2959 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2960 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | if (status == 0) |
| 2962 | break; |
| 2963 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2964 | * book-keeping w.r.t. state-changing operations |
| 2965 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2966 | * It is actually a sign of a bug on the client or on the server. |
| 2967 | * |
| 2968 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2969 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | * have unhashed the old state_owner for us, and that we can |
| 2971 | * therefore safely retry using a new one. We should still warn |
| 2972 | * the user though... |
| 2973 | */ |
| 2974 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2975 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2976 | " returned a bad sequence-id error!\n", |
| 2977 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | exception.retry = 1; |
| 2979 | continue; |
| 2980 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2981 | /* |
| 2982 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2983 | * state before it received the OPEN_CONFIRM. |
| 2984 | * Recover by retrying the request as per the discussion |
| 2985 | * on Page 181 of RFC3530. |
| 2986 | */ |
| 2987 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2988 | exception.retry = 1; |
| 2989 | continue; |
| 2990 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2991 | if (status == -EAGAIN) { |
| 2992 | /* We must have found a delegation */ |
| 2993 | exception.retry = 1; |
| 2994 | continue; |
| 2995 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2996 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2997 | continue; |
| 2998 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | status, &exception)); |
| 3000 | } while (exception.retry); |
| 3001 | return res; |
| 3002 | } |
| 3003 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3004 | static int _nfs4_do_setattr(struct inode *inode, |
| 3005 | struct nfs_setattrargs *arg, |
| 3006 | struct nfs_setattrres *res, |
| 3007 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3008 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3009 | { |
| 3010 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3011 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3012 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3013 | .rpc_argp = arg, |
| 3014 | .rpc_resp = res, |
| 3015 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3016 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3017 | struct rpc_cred *delegation_cred = NULL; |
| 3018 | unsigned long timestamp = jiffies; |
| 3019 | fmode_t fmode; |
| 3020 | bool truncate; |
| 3021 | int status; |
| 3022 | |
| 3023 | nfs_fattr_init(res->fattr); |
| 3024 | |
| 3025 | /* Servers should only apply open mode checks for file size changes */ |
| 3026 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 3027 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 3028 | |
| 3029 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 3030 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3031 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3032 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3033 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3034 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3035 | l_ctx = nfs_get_lock_context(ctx); |
| 3036 | if (IS_ERR(l_ctx)) |
| 3037 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3038 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3039 | &arg->stateid, &delegation_cred); |
| 3040 | nfs_put_lock_context(l_ctx); |
| 3041 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3042 | return -EBADF; |
| 3043 | } else |
| 3044 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 3045 | if (delegation_cred) |
| 3046 | msg.rpc_cred = delegation_cred; |
| 3047 | |
| 3048 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3049 | |
| 3050 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3051 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3052 | renew_lease(server, timestamp); |
| 3053 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3054 | return status; |
| 3055 | } |
| 3056 | |
| 3057 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 3058 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3059 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3060 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3062 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3063 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3064 | struct nfs_setattrargs arg = { |
| 3065 | .fh = NFS_FH(inode), |
| 3066 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | .server = server, |
| 3068 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3069 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3070 | }; |
| 3071 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3073 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3075 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3076 | struct nfs4_exception exception = { |
| 3077 | .state = state, |
| 3078 | .inode = inode, |
| 3079 | .stateid = &arg.stateid, |
| 3080 | }; |
| 3081 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3083 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 3084 | if (ilabel) |
| 3085 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 3086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3088 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3089 | switch (err) { |
| 3090 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3091 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3092 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3093 | "applying open mode checks to " |
| 3094 | "a SETATTR that is not " |
| 3095 | "changing file size.\n", |
| 3096 | server->nfs_client->cl_hostname); |
| 3097 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3098 | if (state && !(state->state & FMODE_WRITE)) { |
| 3099 | err = -EBADF; |
| 3100 | if (sattr->ia_valid & ATTR_OPEN) |
| 3101 | err = -EACCES; |
| 3102 | goto out; |
| 3103 | } |
| 3104 | } |
| 3105 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3107 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | return err; |
| 3109 | } |
| 3110 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3111 | static bool |
| 3112 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3113 | { |
| 3114 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3115 | return false; |
| 3116 | |
| 3117 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3118 | } |
| 3119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | struct nfs4_closedata { |
| 3121 | struct inode *inode; |
| 3122 | struct nfs4_state *state; |
| 3123 | struct nfs_closeargs arg; |
| 3124 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3125 | struct { |
| 3126 | struct nfs4_layoutreturn_args arg; |
| 3127 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3128 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3129 | u32 roc_barrier; |
| 3130 | bool roc; |
| 3131 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3132 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3133 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | }; |
| 3135 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3136 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3137 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3138 | struct nfs4_closedata *calldata = data; |
| 3139 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3140 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3141 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3142 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3143 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3144 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3145 | nfs4_put_open_state(calldata->state); |
| 3146 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3147 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3148 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3149 | kfree(calldata); |
| 3150 | } |
| 3151 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3152 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3154 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3157 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3158 | struct nfs4_exception exception = { |
| 3159 | .state = state, |
| 3160 | .inode = calldata->inode, |
| 3161 | .stateid = &calldata->arg.stateid, |
| 3162 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3164 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3165 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3166 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3167 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3168 | |
| 3169 | /* Handle Layoutreturn errors */ |
| 3170 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3171 | switch (calldata->res.lr_ret) { |
| 3172 | default: |
| 3173 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3174 | break; |
| 3175 | case 0: |
| 3176 | calldata->arg.lr_args = NULL; |
| 3177 | calldata->res.lr_res = NULL; |
| 3178 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3179 | case -NFS4ERR_OLD_STATEID: |
| 3180 | if (nfs4_refresh_layout_stateid(&calldata->arg.lr_args->stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3181 | calldata->inode)) |
| 3182 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3183 | /* Fallthrough */ |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3184 | case -NFS4ERR_ADMIN_REVOKED: |
| 3185 | case -NFS4ERR_DELEG_REVOKED: |
| 3186 | case -NFS4ERR_EXPIRED: |
| 3187 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3188 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3189 | case -NFS4ERR_WRONG_CRED: |
| 3190 | calldata->arg.lr_args = NULL; |
| 3191 | calldata->res.lr_res = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3192 | goto lr_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3193 | } |
| 3194 | } |
| 3195 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3196 | /* 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] | 3197 | * the state_owner. we keep this around to process errors |
| 3198 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | switch (task->tk_status) { |
| 3200 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3201 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3202 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3203 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3204 | case -NFS4ERR_ACCESS: |
| 3205 | if (calldata->arg.bitmask != NULL) { |
| 3206 | calldata->arg.bitmask = NULL; |
| 3207 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3208 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3209 | |
| 3210 | } |
| 3211 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3212 | case -NFS4ERR_OLD_STATEID: |
| 3213 | /* Did we race with OPEN? */ |
| 3214 | if (nfs4_refresh_open_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3215 | state)) |
| 3216 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3217 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3218 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3220 | case -NFS4ERR_EXPIRED: |
| 3221 | nfs4_free_revoked_stateid(server, |
| 3222 | &calldata->arg.stateid, |
| 3223 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3224 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3225 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3226 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3228 | task->tk_status = nfs4_async_handle_exception(task, |
| 3229 | server, task->tk_status, &exception); |
| 3230 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3231 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3233 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3234 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3235 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3236 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3237 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3238 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3239 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3240 | return; |
| 3241 | lr_restart: |
| 3242 | calldata->res.lr_ret = 0; |
| 3243 | out_restart: |
| 3244 | task->tk_status = 0; |
| 3245 | rpc_restart_call_prepare(task); |
| 3246 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3249 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3251 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3252 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3253 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3254 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3255 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3256 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3257 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3258 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3259 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3260 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3261 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3262 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3263 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3264 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3265 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3266 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3267 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3268 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3269 | if (state->n_rdonly == 0) |
| 3270 | call_close |= is_rdonly; |
| 3271 | else if (is_rdonly) |
| 3272 | calldata->arg.fmode |= FMODE_READ; |
| 3273 | if (state->n_wronly == 0) |
| 3274 | call_close |= is_wronly; |
| 3275 | else if (is_wronly) |
| 3276 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3277 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3278 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3279 | } else if (is_rdwr) |
| 3280 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3281 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3282 | if (!nfs4_valid_open_stateid(state) || |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3283 | !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3284 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3285 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3286 | |
| 3287 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3288 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3289 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3290 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3291 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3292 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3293 | nfs_release_seqid(calldata->arg.seqid); |
| 3294 | goto out_wait; |
| 3295 | } |
| 3296 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3297 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3298 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3299 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3300 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3301 | /* Close-to-open cache consistency revalidation */ |
| 3302 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3303 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3304 | else |
| 3305 | calldata->arg.bitmask = NULL; |
| 3306 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3307 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3308 | calldata->arg.share_access = |
| 3309 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3310 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3311 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3312 | if (calldata->res.fattr == NULL) |
| 3313 | calldata->arg.bitmask = NULL; |
| 3314 | else if (calldata->arg.bitmask == NULL) |
| 3315 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3316 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3317 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3318 | &calldata->arg.seq_args, |
| 3319 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3320 | task) != 0) |
| 3321 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3322 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3323 | return; |
| 3324 | out_no_action: |
| 3325 | task->tk_action = NULL; |
| 3326 | out_wait: |
| 3327 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3330 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3331 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3332 | .rpc_call_done = nfs4_close_done, |
| 3333 | .rpc_release = nfs4_free_closedata, |
| 3334 | }; |
| 3335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | /* |
| 3337 | * It is possible for data to be read/written from a mem-mapped file |
| 3338 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3339 | * This means that we can't safely call nfsv4 close on a file until |
| 3340 | * the inode is cleared. This in turn means that we are not good |
| 3341 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3342 | * share state even when we are done with one of the three share |
| 3343 | * stateid's in the inode. |
| 3344 | * |
| 3345 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3346 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3347 | 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] | 3348 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3349 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3350 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3352 | struct nfs4_state_owner *sp = state->owner; |
| 3353 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3354 | struct rpc_message msg = { |
| 3355 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3356 | .rpc_cred = state->owner->so_cred, |
| 3357 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3358 | struct rpc_task_setup task_setup_data = { |
| 3359 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3360 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3361 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3362 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3363 | .flags = RPC_TASK_ASYNC, |
| 3364 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3365 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3367 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3368 | &task_setup_data.rpc_client, &msg); |
| 3369 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3370 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3372 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3373 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3374 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3376 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3377 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3378 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3380 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3381 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3382 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3383 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3384 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3385 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3386 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3387 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3388 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3389 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3390 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3391 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3392 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3393 | if (calldata->lr.roc) { |
| 3394 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3395 | calldata->res.lr_res = &calldata->lr.res; |
| 3396 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3397 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3398 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3399 | msg.rpc_argp = &calldata->arg; |
| 3400 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3401 | task_setup_data.callback_data = calldata; |
| 3402 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3403 | if (IS_ERR(task)) |
| 3404 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3405 | status = 0; |
| 3406 | if (wait) |
| 3407 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3408 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3409 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3410 | out_free_calldata: |
| 3411 | kfree(calldata); |
| 3412 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3413 | nfs4_put_open_state(state); |
| 3414 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3415 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3418 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3419 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3420 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3423 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3424 | |
| 3425 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3427 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3428 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3429 | |
| 3430 | nfs4_label_release_security(label); |
| 3431 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3432 | if (IS_ERR(state)) |
| 3433 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3434 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3437 | 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] | 3438 | { |
| 3439 | if (ctx->state == NULL) |
| 3440 | return; |
| 3441 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3442 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3443 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3444 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3447 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3448 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3449 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3452 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3453 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3454 | struct nfs4_server_caps_arg args = { |
| 3455 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3456 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3457 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | struct nfs4_server_caps_res res = {}; |
| 3459 | struct rpc_message msg = { |
| 3460 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3461 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | .rpc_resp = &res, |
| 3463 | }; |
| 3464 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3465 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3467 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3468 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3469 | FATTR4_WORD0_LINK_SUPPORT | |
| 3470 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3471 | FATTR4_WORD0_ACLSUPPORT; |
| 3472 | if (minorversion) |
| 3473 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3474 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3475 | 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] | 3476 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3477 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3478 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3479 | case 0: |
| 3480 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3481 | res.attr_bitmask[2] = 0; |
| 3482 | break; |
| 3483 | case 1: |
| 3484 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3485 | break; |
| 3486 | case 2: |
| 3487 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3490 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3491 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3492 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3493 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3494 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3495 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3496 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3497 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | server->caps |= NFS_CAP_ACLS; |
| 3499 | if (res.has_links != 0) |
| 3500 | server->caps |= NFS_CAP_HARDLINKS; |
| 3501 | if (res.has_symlinks != 0) |
| 3502 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3503 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3504 | server->caps |= NFS_CAP_FILEID; |
| 3505 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3506 | server->caps |= NFS_CAP_MODE; |
| 3507 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3508 | server->caps |= NFS_CAP_NLINK; |
| 3509 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3510 | server->caps |= NFS_CAP_OWNER; |
| 3511 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3512 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3513 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3514 | server->caps |= NFS_CAP_ATIME; |
| 3515 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3516 | server->caps |= NFS_CAP_CTIME; |
| 3517 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3518 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3519 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3520 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3521 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3522 | #endif |
| 3523 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3524 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3525 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3526 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3527 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3528 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3529 | 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] | 3530 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3531 | |
| 3532 | /* Avoid a regression due to buggy server */ |
| 3533 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3534 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3535 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3536 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3539 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | return status; |
| 3543 | } |
| 3544 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3545 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | { |
| 3547 | struct nfs4_exception exception = { }; |
| 3548 | int err; |
| 3549 | do { |
| 3550 | err = nfs4_handle_exception(server, |
| 3551 | _nfs4_server_capabilities(server, fhandle), |
| 3552 | &exception); |
| 3553 | } while (exception.retry); |
| 3554 | return err; |
| 3555 | } |
| 3556 | |
| 3557 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3558 | struct nfs_fsinfo *info) |
| 3559 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3560 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3562 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | }; |
| 3564 | struct nfs4_lookup_res res = { |
| 3565 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3566 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | .fh = fhandle, |
| 3568 | }; |
| 3569 | struct rpc_message msg = { |
| 3570 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3571 | .rpc_argp = &args, |
| 3572 | .rpc_resp = &res, |
| 3573 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3574 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3575 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3576 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3577 | /* |
| 3578 | * Process the label in the upcoming getfattr |
| 3579 | */ |
| 3580 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3581 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3582 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3583 | 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] | 3584 | } |
| 3585 | |
| 3586 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3587 | struct nfs_fsinfo *info) |
| 3588 | { |
| 3589 | struct nfs4_exception exception = { }; |
| 3590 | int err; |
| 3591 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3592 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3593 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3594 | switch (err) { |
| 3595 | case 0: |
| 3596 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3597 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3598 | default: |
| 3599 | err = nfs4_handle_exception(server, err, &exception); |
| 3600 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3602 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | return err; |
| 3604 | } |
| 3605 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3606 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3607 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3608 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3609 | struct rpc_auth_create_args auth_args = { |
| 3610 | .pseudoflavor = flavor, |
| 3611 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3612 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3613 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3614 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3615 | if (IS_ERR(auth)) |
| 3616 | return -EACCES; |
| 3617 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3620 | /* |
| 3621 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3622 | * |
| 3623 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3624 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3625 | * |
| 3626 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3627 | * negative errno value. |
| 3628 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3629 | 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] | 3630 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3632 | /* Per 3530bis 15.33.5 */ |
| 3633 | static const rpc_authflavor_t flav_array[] = { |
| 3634 | RPC_AUTH_GSS_KRB5P, |
| 3635 | RPC_AUTH_GSS_KRB5I, |
| 3636 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3637 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3638 | RPC_AUTH_NULL, |
| 3639 | }; |
| 3640 | int status = -EPERM; |
| 3641 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3643 | if (server->auth_info.flavor_len > 0) { |
| 3644 | /* try each flavor specified by user */ |
| 3645 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3646 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3647 | server->auth_info.flavors[i]); |
| 3648 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3649 | continue; |
| 3650 | break; |
| 3651 | } |
| 3652 | } else { |
| 3653 | /* no flavors specified by user, try default list */ |
| 3654 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3655 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3656 | flav_array[i]); |
| 3657 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3658 | continue; |
| 3659 | break; |
| 3660 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3661 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3662 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3663 | /* |
| 3664 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3665 | * to access the mount. It could also mean that we tried to mount |
| 3666 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3667 | * existing mount programs don't handle -EACCES very well so it should |
| 3668 | * be mapped to -EPERM instead. |
| 3669 | */ |
| 3670 | if (status == -EACCES) |
| 3671 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3672 | return status; |
| 3673 | } |
| 3674 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3675 | /** |
| 3676 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3677 | * @server: initialized nfs_server handle |
| 3678 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3679 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3680 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3681 | * |
| 3682 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3683 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3684 | 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] | 3685 | struct nfs_fsinfo *info, |
| 3686 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3687 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3688 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3689 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3690 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3691 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3692 | |
| 3693 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3694 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3695 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | if (status == 0) |
| 3698 | status = nfs4_server_capabilities(server, fhandle); |
| 3699 | if (status == 0) |
| 3700 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3701 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3702 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3705 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3706 | struct nfs_fsinfo *info) |
| 3707 | { |
| 3708 | int error; |
| 3709 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3710 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3711 | |
| 3712 | error = nfs4_server_capabilities(server, mntfh); |
| 3713 | if (error < 0) { |
| 3714 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3715 | return error; |
| 3716 | } |
| 3717 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3718 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3719 | if (IS_ERR(label)) |
| 3720 | return PTR_ERR(label); |
| 3721 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3722 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3723 | if (error < 0) { |
| 3724 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3725 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3729 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3730 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3731 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3732 | err_free_label: |
| 3733 | nfs4_label_free(label); |
| 3734 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3735 | return error; |
| 3736 | } |
| 3737 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3738 | /* |
| 3739 | * Get locations and (maybe) other attributes of a referral. |
| 3740 | * Note that we'll actually follow the referral later when |
| 3741 | * we detect fsid mismatch in inode revalidation |
| 3742 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3743 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3744 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3745 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3746 | { |
| 3747 | int status = -ENOMEM; |
| 3748 | struct page *page = NULL; |
| 3749 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3750 | |
| 3751 | page = alloc_page(GFP_KERNEL); |
| 3752 | if (page == NULL) |
| 3753 | goto out; |
| 3754 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3755 | if (locations == NULL) |
| 3756 | goto out; |
| 3757 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3758 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3759 | if (status != 0) |
| 3760 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3761 | |
| 3762 | /* |
| 3763 | * If the fsid didn't change, this is a migration event, not a |
| 3764 | * referral. Cause us to drop into the exception handler, which |
| 3765 | * will kick off migration recovery. |
| 3766 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3767 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3768 | dprintk("%s: server did not return a different fsid for" |
| 3769 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3770 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3771 | goto out; |
| 3772 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3773 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3774 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3775 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3776 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3777 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3778 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3779 | out: |
| 3780 | if (page) |
| 3781 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3782 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3783 | return status; |
| 3784 | } |
| 3785 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3786 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3787 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | { |
| 3789 | struct nfs4_getattr_arg args = { |
| 3790 | .fh = fhandle, |
| 3791 | .bitmask = server->attr_bitmask, |
| 3792 | }; |
| 3793 | struct nfs4_getattr_res res = { |
| 3794 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3795 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | .server = server, |
| 3797 | }; |
| 3798 | struct rpc_message msg = { |
| 3799 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3800 | .rpc_argp = &args, |
| 3801 | .rpc_resp = &res, |
| 3802 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3803 | |
| 3804 | args.bitmask = nfs4_bitmask(server, label); |
| 3805 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3806 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3807 | 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] | 3808 | } |
| 3809 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3810 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3811 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | { |
| 3813 | struct nfs4_exception exception = { }; |
| 3814 | int err; |
| 3815 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3816 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3817 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3818 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | &exception); |
| 3820 | } while (exception.retry); |
| 3821 | return err; |
| 3822 | } |
| 3823 | |
| 3824 | /* |
| 3825 | * The file is not closed if it is opened due to the a request to change |
| 3826 | * the size of the file. The open call will not be needed once the |
| 3827 | * VFS layer lookup-intents are implemented. |
| 3828 | * |
| 3829 | * Close is called when the inode is destroyed. |
| 3830 | * If we haven't opened the file for O_WRONLY, we |
| 3831 | * need to in the size_change case to obtain a stateid. |
| 3832 | * |
| 3833 | * Got race? |
| 3834 | * Because OPEN is always done by name in nfsv4, it is |
| 3835 | * possible that we opened a different file by the same |
| 3836 | * name. We can recognize this race condition, but we |
| 3837 | * can't do anything about it besides returning an error. |
| 3838 | * |
| 3839 | * This will be fixed with VFS changes (lookup-intent). |
| 3840 | */ |
| 3841 | static int |
| 3842 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3843 | struct iattr *sattr) |
| 3844 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3845 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3846 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3847 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3848 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | int status; |
| 3850 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3851 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3852 | sattr->ia_valid & ATTR_SIZE && |
| 3853 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3854 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3855 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3856 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3858 | /* Deal with open(O_TRUNC) */ |
| 3859 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3860 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3861 | |
| 3862 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3863 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3864 | return 0; |
| 3865 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3866 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3867 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3868 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3869 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3870 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3871 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3872 | } |
| 3873 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3874 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3875 | if (IS_ERR(label)) |
| 3876 | return PTR_ERR(label); |
| 3877 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame^] | 3878 | /* Return any delegations if we're going to change ACLs */ |
| 3879 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
| 3880 | nfs4_inode_return_delegation(inode); |
| 3881 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3882 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3883 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3884 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3885 | nfs_setsecurity(inode, fattr, label); |
| 3886 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3887 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | return status; |
| 3889 | } |
| 3890 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3891 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3892 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3893 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3894 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3895 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3896 | int status; |
| 3897 | struct nfs4_lookup_arg args = { |
| 3898 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3899 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3900 | .name = name, |
| 3901 | }; |
| 3902 | struct nfs4_lookup_res res = { |
| 3903 | .server = server, |
| 3904 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3905 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3906 | .fh = fhandle, |
| 3907 | }; |
| 3908 | struct rpc_message msg = { |
| 3909 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3910 | .rpc_argp = &args, |
| 3911 | .rpc_resp = &res, |
| 3912 | }; |
| 3913 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3914 | args.bitmask = nfs4_bitmask(server, label); |
| 3915 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3916 | nfs_fattr_init(fattr); |
| 3917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3919 | 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] | 3920 | dprintk("NFS reply lookup: %d\n", status); |
| 3921 | return status; |
| 3922 | } |
| 3923 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3924 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3925 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3926 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3927 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3928 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3929 | fattr->nlink = 2; |
| 3930 | } |
| 3931 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3932 | 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] | 3933 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3934 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3935 | { |
| 3936 | struct nfs4_exception exception = { }; |
| 3937 | struct rpc_clnt *client = *clnt; |
| 3938 | int err; |
| 3939 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3940 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3941 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3942 | switch (err) { |
| 3943 | case -NFS4ERR_BADNAME: |
| 3944 | err = -ENOENT; |
| 3945 | goto out; |
| 3946 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3947 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3948 | if (err == -NFS4ERR_MOVED) |
| 3949 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3950 | goto out; |
| 3951 | case -NFS4ERR_WRONGSEC: |
| 3952 | err = -EPERM; |
| 3953 | if (client != *clnt) |
| 3954 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3955 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3956 | if (IS_ERR(client)) |
| 3957 | return PTR_ERR(client); |
| 3958 | |
| 3959 | exception.retry = 1; |
| 3960 | break; |
| 3961 | default: |
| 3962 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3963 | } |
| 3964 | } while (exception.retry); |
| 3965 | |
| 3966 | out: |
| 3967 | if (err == 0) |
| 3968 | *clnt = client; |
| 3969 | else if (client != *clnt) |
| 3970 | rpc_shutdown_client(client); |
| 3971 | |
| 3972 | return err; |
| 3973 | } |
| 3974 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3975 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3976 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3977 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3979 | int status; |
| 3980 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3981 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3982 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3983 | if (client != NFS_CLIENT(dir)) { |
| 3984 | rpc_shutdown_client(client); |
| 3985 | nfs_fixup_secinfo_attributes(fattr); |
| 3986 | } |
| 3987 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | } |
| 3989 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3990 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3991 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3992 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3993 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3994 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3995 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3996 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3997 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3998 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3999 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4000 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4001 | } |
| 4002 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4003 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4004 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4005 | struct nfs4_label *label) |
| 4006 | { |
| 4007 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4008 | struct nfs_server *server = NFS_SERVER(inode); |
| 4009 | int status; |
| 4010 | struct nfs4_lookupp_arg args = { |
| 4011 | .bitmask = server->attr_bitmask, |
| 4012 | .fh = NFS_FH(inode), |
| 4013 | }; |
| 4014 | struct nfs4_lookupp_res res = { |
| 4015 | .server = server, |
| 4016 | .fattr = fattr, |
| 4017 | .label = label, |
| 4018 | .fh = fhandle, |
| 4019 | }; |
| 4020 | struct rpc_message msg = { |
| 4021 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4022 | .rpc_argp = &args, |
| 4023 | .rpc_resp = &res, |
| 4024 | }; |
| 4025 | |
| 4026 | args.bitmask = nfs4_bitmask(server, label); |
| 4027 | |
| 4028 | nfs_fattr_init(fattr); |
| 4029 | |
| 4030 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4031 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4032 | &res.seq_res, 0); |
| 4033 | dprintk("NFS reply lookupp: %d\n", status); |
| 4034 | return status; |
| 4035 | } |
| 4036 | |
| 4037 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4038 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4039 | { |
| 4040 | struct nfs4_exception exception = { }; |
| 4041 | int err; |
| 4042 | do { |
| 4043 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4044 | trace_nfs4_lookupp(inode, err); |
| 4045 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4046 | &exception); |
| 4047 | } while (exception.retry); |
| 4048 | return err; |
| 4049 | } |
| 4050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4052 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4053 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | struct nfs4_accessargs args = { |
| 4055 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 4056 | .bitmask = server->cache_consistency_bitmask, |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4057 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4059 | struct nfs4_accessres res = { |
| 4060 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4061 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | struct rpc_message msg = { |
| 4063 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4064 | .rpc_argp = &args, |
| 4065 | .rpc_resp = &res, |
| 4066 | .rpc_cred = entry->cred, |
| 4067 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4068 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4070 | res.fattr = nfs_alloc_fattr(); |
| 4071 | if (res.fattr == NULL) |
| 4072 | return -ENOMEM; |
| 4073 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4074 | 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] | 4075 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4076 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4077 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4079 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | return status; |
| 4081 | } |
| 4082 | |
| 4083 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4084 | { |
| 4085 | struct nfs4_exception exception = { }; |
| 4086 | int err; |
| 4087 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4088 | err = _nfs4_proc_access(inode, entry); |
| 4089 | trace_nfs4_access(inode, err); |
| 4090 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | &exception); |
| 4092 | } while (exception.retry); |
| 4093 | return err; |
| 4094 | } |
| 4095 | |
| 4096 | /* |
| 4097 | * TODO: For the time being, we don't try to get any attributes |
| 4098 | * along with any of the zero-copy operations READ, READDIR, |
| 4099 | * READLINK, WRITE. |
| 4100 | * |
| 4101 | * In the case of the first three, we want to put the GETATTR |
| 4102 | * after the read-type operation -- this is because it is hard |
| 4103 | * to predict the length of a GETATTR response in v4, and thus |
| 4104 | * align the READ data correctly. This means that the GETATTR |
| 4105 | * may end up partially falling into the page cache, and we should |
| 4106 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4107 | * To do this efficiently, we need to know the total length |
| 4108 | * of data received, which doesn't seem to be available outside |
| 4109 | * of the RPC layer. |
| 4110 | * |
| 4111 | * In the case of WRITE, we also want to put the GETATTR after |
| 4112 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4113 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | * |
| 4115 | * Both of these changes to the XDR layer would in fact be quite |
| 4116 | * minor, but I decided to leave them for a subsequent patch. |
| 4117 | */ |
| 4118 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4119 | unsigned int pgbase, unsigned int pglen) |
| 4120 | { |
| 4121 | struct nfs4_readlink args = { |
| 4122 | .fh = NFS_FH(inode), |
| 4123 | .pgbase = pgbase, |
| 4124 | .pglen = pglen, |
| 4125 | .pages = &page, |
| 4126 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4127 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | struct rpc_message msg = { |
| 4129 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4130 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4131 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | }; |
| 4133 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4134 | 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] | 4135 | } |
| 4136 | |
| 4137 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4138 | unsigned int pgbase, unsigned int pglen) |
| 4139 | { |
| 4140 | struct nfs4_exception exception = { }; |
| 4141 | int err; |
| 4142 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4143 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4144 | trace_nfs4_readlink(inode, err); |
| 4145 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | &exception); |
| 4147 | } while (exception.retry); |
| 4148 | return err; |
| 4149 | } |
| 4150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4152 | * 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] | 4153 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | static int |
| 4155 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4156 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4158 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4159 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4160 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | int status = 0; |
| 4163 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4164 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4165 | if (IS_ERR(ctx)) |
| 4166 | return PTR_ERR(ctx); |
| 4167 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4168 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4169 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4170 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4171 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4172 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | if (IS_ERR(state)) { |
| 4174 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4175 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4178 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4179 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | return status; |
| 4181 | } |
| 4182 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4183 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4185 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4186 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4188 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4190 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4191 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4192 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4194 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4195 | .rpc_argp = &args, |
| 4196 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4198 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4199 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4200 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4201 | 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] | 4202 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4203 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | return status; |
| 4205 | } |
| 4206 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4207 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4208 | { |
| 4209 | struct nfs4_exception exception = { }; |
| 4210 | struct inode *inode = d_inode(dentry); |
| 4211 | int err; |
| 4212 | |
| 4213 | if (inode) |
| 4214 | nfs4_inode_return_delegation(inode); |
| 4215 | do { |
| 4216 | err = _nfs4_proc_remove(dir, &dentry->d_name); |
| 4217 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4218 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4219 | &exception); |
| 4220 | } while (exception.retry); |
| 4221 | return err; |
| 4222 | } |
| 4223 | |
| 4224 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | { |
| 4226 | struct nfs4_exception exception = { }; |
| 4227 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4230 | err = _nfs4_proc_remove(dir, name); |
| 4231 | trace_nfs4_remove(dir, name, err); |
| 4232 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | &exception); |
| 4234 | } while (exception.retry); |
| 4235 | return err; |
| 4236 | } |
| 4237 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4238 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4240 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4241 | struct nfs_removeres *res = msg->rpc_resp; |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4242 | struct inode *inode = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4244 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4246 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4247 | |
| 4248 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4249 | |
| 4250 | if (inode) |
| 4251 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | } |
| 4253 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4254 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4255 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4256 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4257 | &data->args.seq_args, |
| 4258 | &data->res.seq_res, |
| 4259 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | } |
| 4261 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4262 | 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] | 4263 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4264 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4265 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4266 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4267 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4268 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4269 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4270 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4271 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4272 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4273 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4274 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | } |
| 4276 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4277 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4278 | struct dentry *old_dentry, |
| 4279 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4280 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4281 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4282 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4283 | struct inode *old_inode = d_inode(old_dentry); |
| 4284 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4285 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4286 | if (old_inode) |
| 4287 | nfs4_inode_return_delegation(old_inode); |
| 4288 | if (new_inode) |
| 4289 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4290 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4291 | res->server = NFS_SB(old_dentry->d_sb); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4292 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4293 | } |
| 4294 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4295 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4296 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4297 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4298 | &data->args.seq_args, |
| 4299 | &data->res.seq_res, |
| 4300 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4304 | struct inode *new_dir) |
| 4305 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4306 | struct nfs_renamedata *data = task->tk_calldata; |
| 4307 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4308 | |
| 4309 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4310 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4311 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4312 | return 0; |
| 4313 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4314 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4315 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4316 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4317 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4318 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4319 | return 1; |
| 4320 | } |
| 4321 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4322 | 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] | 4323 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4324 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | struct nfs4_link_arg arg = { |
| 4326 | .fh = NFS_FH(inode), |
| 4327 | .dir_fh = NFS_FH(dir), |
| 4328 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4329 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4331 | struct nfs4_link_res res = { |
| 4332 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4333 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4334 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | struct rpc_message msg = { |
| 4336 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4337 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4338 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4340 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4342 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4343 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4344 | goto out; |
| 4345 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4346 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4347 | if (IS_ERR(res.label)) { |
| 4348 | status = PTR_ERR(res.label); |
| 4349 | goto out; |
| 4350 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4351 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4352 | |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4353 | nfs4_inode_return_delegation(inode); |
| 4354 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4355 | 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] | 4356 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4357 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4358 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4359 | if (!status) |
| 4360 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4361 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4362 | |
| 4363 | |
| 4364 | nfs4_label_free(res.label); |
| 4365 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4366 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4367 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | return status; |
| 4369 | } |
| 4370 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4371 | 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] | 4372 | { |
| 4373 | struct nfs4_exception exception = { }; |
| 4374 | int err; |
| 4375 | do { |
| 4376 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4377 | _nfs4_proc_link(inode, dir, name), |
| 4378 | &exception); |
| 4379 | } while (exception.retry); |
| 4380 | return err; |
| 4381 | } |
| 4382 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4383 | struct nfs4_createdata { |
| 4384 | struct rpc_message msg; |
| 4385 | struct nfs4_create_arg arg; |
| 4386 | struct nfs4_create_res res; |
| 4387 | struct nfs_fh fh; |
| 4388 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4389 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4390 | }; |
| 4391 | |
| 4392 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4393 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4394 | { |
| 4395 | struct nfs4_createdata *data; |
| 4396 | |
| 4397 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4398 | if (data != NULL) { |
| 4399 | struct nfs_server *server = NFS_SERVER(dir); |
| 4400 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4401 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4402 | if (IS_ERR(data->label)) |
| 4403 | goto out_free; |
| 4404 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4405 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4406 | data->msg.rpc_argp = &data->arg; |
| 4407 | data->msg.rpc_resp = &data->res; |
| 4408 | data->arg.dir_fh = NFS_FH(dir); |
| 4409 | data->arg.server = server; |
| 4410 | data->arg.name = name; |
| 4411 | data->arg.attrs = sattr; |
| 4412 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4413 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4414 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4415 | data->res.server = server; |
| 4416 | data->res.fh = &data->fh; |
| 4417 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4418 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4419 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4420 | } |
| 4421 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4422 | out_free: |
| 4423 | kfree(data); |
| 4424 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4428 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4429 | 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] | 4430 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4431 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4432 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4433 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4434 | 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] | 4435 | } |
| 4436 | return status; |
| 4437 | } |
| 4438 | |
| 4439 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4440 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4441 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4442 | kfree(data); |
| 4443 | } |
| 4444 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4445 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4446 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4447 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4449 | struct nfs4_createdata *data; |
| 4450 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4452 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4453 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4454 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4455 | status = -ENOMEM; |
| 4456 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4457 | if (data == NULL) |
| 4458 | goto out; |
| 4459 | |
| 4460 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4461 | data->arg.u.symlink.pages = &page; |
| 4462 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4463 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4465 | status = nfs4_do_create(dir, dentry, data); |
| 4466 | |
| 4467 | nfs4_free_createdata(data); |
| 4468 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | return status; |
| 4470 | } |
| 4471 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4472 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4473 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | { |
| 4475 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4476 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4478 | |
| 4479 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4482 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4483 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4484 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | &exception); |
| 4486 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4487 | |
| 4488 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | return err; |
| 4490 | } |
| 4491 | |
| 4492 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4493 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4495 | struct nfs4_createdata *data; |
| 4496 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4498 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4499 | if (data == NULL) |
| 4500 | goto out; |
| 4501 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4502 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4503 | status = nfs4_do_create(dir, dentry, data); |
| 4504 | |
| 4505 | nfs4_free_createdata(data); |
| 4506 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | return status; |
| 4508 | } |
| 4509 | |
| 4510 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4511 | struct iattr *sattr) |
| 4512 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4513 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4515 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4517 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4518 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4519 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4520 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4521 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4523 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4524 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4525 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | &exception); |
| 4527 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4528 | nfs4_label_release_security(label); |
| 4529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | return err; |
| 4531 | } |
| 4532 | |
| 4533 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4534 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4536 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | struct nfs4_readdir_arg args = { |
| 4538 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4539 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | .pgbase = 0, |
| 4541 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4542 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4543 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | }; |
| 4545 | struct nfs4_readdir_res res; |
| 4546 | struct rpc_message msg = { |
| 4547 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4548 | .rpc_argp = &args, |
| 4549 | .rpc_resp = &res, |
| 4550 | .rpc_cred = cred, |
| 4551 | }; |
| 4552 | int status; |
| 4553 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4554 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4555 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4556 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4557 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4559 | 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] | 4560 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4561 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4562 | status += args.pgbase; |
| 4563 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4564 | |
| 4565 | nfs_invalidate_atime(dir); |
| 4566 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4567 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | return status; |
| 4569 | } |
| 4570 | |
| 4571 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4572 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | { |
| 4574 | struct nfs4_exception exception = { }; |
| 4575 | int err; |
| 4576 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4577 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4578 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4579 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4580 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | &exception); |
| 4582 | } while (exception.retry); |
| 4583 | return err; |
| 4584 | } |
| 4585 | |
| 4586 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4587 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4589 | struct nfs4_createdata *data; |
| 4590 | int mode = sattr->ia_mode; |
| 4591 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4593 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4594 | if (data == NULL) |
| 4595 | goto out; |
| 4596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4598 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4600 | data->arg.ftype = NF4BLK; |
| 4601 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4602 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | } |
| 4604 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4605 | data->arg.ftype = NF4CHR; |
| 4606 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4607 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4608 | } else if (!S_ISSOCK(mode)) { |
| 4609 | status = -EINVAL; |
| 4610 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4612 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4613 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4614 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4615 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4616 | nfs4_free_createdata(data); |
| 4617 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | return status; |
| 4619 | } |
| 4620 | |
| 4621 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4622 | struct iattr *sattr, dev_t rdev) |
| 4623 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4624 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4626 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4628 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4629 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4630 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4631 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4632 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4634 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4635 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4636 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | &exception); |
| 4638 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4639 | |
| 4640 | nfs4_label_release_security(label); |
| 4641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | return err; |
| 4643 | } |
| 4644 | |
| 4645 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4646 | struct nfs_fsstat *fsstat) |
| 4647 | { |
| 4648 | struct nfs4_statfs_arg args = { |
| 4649 | .fh = fhandle, |
| 4650 | .bitmask = server->attr_bitmask, |
| 4651 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4652 | struct nfs4_statfs_res res = { |
| 4653 | .fsstat = fsstat, |
| 4654 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | struct rpc_message msg = { |
| 4656 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4657 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4658 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | }; |
| 4660 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4661 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4662 | 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] | 4663 | } |
| 4664 | |
| 4665 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4666 | { |
| 4667 | struct nfs4_exception exception = { }; |
| 4668 | int err; |
| 4669 | do { |
| 4670 | err = nfs4_handle_exception(server, |
| 4671 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4672 | &exception); |
| 4673 | } while (exception.retry); |
| 4674 | return err; |
| 4675 | } |
| 4676 | |
| 4677 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4678 | struct nfs_fsinfo *fsinfo) |
| 4679 | { |
| 4680 | struct nfs4_fsinfo_arg args = { |
| 4681 | .fh = fhandle, |
| 4682 | .bitmask = server->attr_bitmask, |
| 4683 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4684 | struct nfs4_fsinfo_res res = { |
| 4685 | .fsinfo = fsinfo, |
| 4686 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | struct rpc_message msg = { |
| 4688 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4689 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4690 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | }; |
| 4692 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4693 | 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] | 4694 | } |
| 4695 | |
| 4696 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4697 | { |
| 4698 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4699 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | int err; |
| 4701 | |
| 4702 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4703 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4704 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4705 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4706 | nfs4_set_lease_period(server->nfs_client, |
| 4707 | fsinfo->lease_time * HZ, |
| 4708 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4709 | break; |
| 4710 | } |
| 4711 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | } while (exception.retry); |
| 4713 | return err; |
| 4714 | } |
| 4715 | |
| 4716 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4717 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4718 | int error; |
| 4719 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4720 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4721 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4722 | if (error == 0) { |
| 4723 | /* block layout checks this! */ |
| 4724 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4725 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4726 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4727 | |
| 4728 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4732 | struct nfs_pathconf *pathconf) |
| 4733 | { |
| 4734 | struct nfs4_pathconf_arg args = { |
| 4735 | .fh = fhandle, |
| 4736 | .bitmask = server->attr_bitmask, |
| 4737 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4738 | struct nfs4_pathconf_res res = { |
| 4739 | .pathconf = pathconf, |
| 4740 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | struct rpc_message msg = { |
| 4742 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4743 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4744 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | }; |
| 4746 | |
| 4747 | /* None of the pathconf attributes are mandatory to implement */ |
| 4748 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4749 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4750 | return 0; |
| 4751 | } |
| 4752 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4753 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4754 | 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] | 4755 | } |
| 4756 | |
| 4757 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4758 | struct nfs_pathconf *pathconf) |
| 4759 | { |
| 4760 | struct nfs4_exception exception = { }; |
| 4761 | int err; |
| 4762 | |
| 4763 | do { |
| 4764 | err = nfs4_handle_exception(server, |
| 4765 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4766 | &exception); |
| 4767 | } while (exception.retry); |
| 4768 | return err; |
| 4769 | } |
| 4770 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4771 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4772 | const struct nfs_open_context *ctx, |
| 4773 | const struct nfs_lock_context *l_ctx, |
| 4774 | fmode_t fmode) |
| 4775 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4776 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4777 | } |
| 4778 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4779 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4780 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4781 | const struct nfs_open_context *ctx, |
| 4782 | const struct nfs_lock_context *l_ctx, |
| 4783 | fmode_t fmode) |
| 4784 | { |
| 4785 | nfs4_stateid current_stateid; |
| 4786 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4787 | /* If the current stateid represents a lost lock, then exit */ |
| 4788 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4789 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4790 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4791 | } |
| 4792 | |
| 4793 | static bool nfs4_error_stateid_expired(int err) |
| 4794 | { |
| 4795 | switch (err) { |
| 4796 | case -NFS4ERR_DELEG_REVOKED: |
| 4797 | case -NFS4ERR_ADMIN_REVOKED: |
| 4798 | case -NFS4ERR_BAD_STATEID: |
| 4799 | case -NFS4ERR_STALE_STATEID: |
| 4800 | case -NFS4ERR_OLD_STATEID: |
| 4801 | case -NFS4ERR_OPENMODE: |
| 4802 | case -NFS4ERR_EXPIRED: |
| 4803 | return true; |
| 4804 | } |
| 4805 | return false; |
| 4806 | } |
| 4807 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4808 | 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] | 4809 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4810 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4812 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4813 | if (task->tk_status < 0) { |
| 4814 | struct nfs4_exception exception = { |
| 4815 | .inode = hdr->inode, |
| 4816 | .state = hdr->args.context->state, |
| 4817 | .stateid = &hdr->args.stateid, |
| 4818 | }; |
| 4819 | task->tk_status = nfs4_async_handle_exception(task, |
| 4820 | server, task->tk_status, &exception); |
| 4821 | if (exception.retry) { |
| 4822 | rpc_restart_call_prepare(task); |
| 4823 | return -EAGAIN; |
| 4824 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4828 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4829 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4830 | } |
| 4831 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4832 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4833 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4834 | { |
| 4835 | |
| 4836 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4837 | nfs4_stateid_is_current(&args->stateid, |
| 4838 | args->context, |
| 4839 | args->lock_context, |
| 4840 | FMODE_READ)) |
| 4841 | return false; |
| 4842 | rpc_restart_call_prepare(task); |
| 4843 | return true; |
| 4844 | } |
| 4845 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4846 | 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] | 4847 | { |
| 4848 | |
| 4849 | dprintk("--> %s\n", __func__); |
| 4850 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4851 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4852 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4853 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4854 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4855 | if (task->tk_status > 0) |
| 4856 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4857 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4858 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4859 | } |
| 4860 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4861 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4862 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4864 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4865 | if (!hdr->pgio_done_cb) |
| 4866 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4867 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4868 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4871 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4872 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4873 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4874 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4875 | &hdr->args.seq_args, |
| 4876 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4877 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4878 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4879 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4880 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4881 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4882 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4883 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4884 | return -EIO; |
| 4885 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4888 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4889 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4891 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4892 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4893 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4894 | if (task->tk_status < 0) { |
| 4895 | struct nfs4_exception exception = { |
| 4896 | .inode = hdr->inode, |
| 4897 | .state = hdr->args.context->state, |
| 4898 | .stateid = &hdr->args.stateid, |
| 4899 | }; |
| 4900 | task->tk_status = nfs4_async_handle_exception(task, |
| 4901 | NFS_SERVER(inode), task->tk_status, |
| 4902 | &exception); |
| 4903 | if (exception.retry) { |
| 4904 | rpc_restart_call_prepare(task); |
| 4905 | return -EAGAIN; |
| 4906 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4908 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4909 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4910 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4911 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4912 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | } |
| 4914 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4915 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4916 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4917 | { |
| 4918 | |
| 4919 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4920 | nfs4_stateid_is_current(&args->stateid, |
| 4921 | args->context, |
| 4922 | args->lock_context, |
| 4923 | FMODE_WRITE)) |
| 4924 | return false; |
| 4925 | rpc_restart_call_prepare(task); |
| 4926 | return true; |
| 4927 | } |
| 4928 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4929 | 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] | 4930 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4931 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4932 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4933 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4934 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4935 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4936 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4939 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4940 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4941 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4942 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4943 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4944 | return false; |
| 4945 | /* Otherwise, request attributes if and only if we don't hold |
| 4946 | * a delegation |
| 4947 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4948 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4949 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4950 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4951 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4952 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4954 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4955 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4956 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4957 | hdr->args.bitmask = NULL; |
| 4958 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4959 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4960 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4961 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4962 | if (!hdr->pgio_done_cb) |
| 4963 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4964 | hdr->res.server = server; |
| 4965 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4966 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4967 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4968 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | } |
| 4970 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4971 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4972 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4973 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4974 | &data->args.seq_args, |
| 4975 | &data->res.seq_res, |
| 4976 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4979 | 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] | 4980 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4982 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4983 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4984 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4985 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4986 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4987 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4988 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4989 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4992 | 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] | 4993 | { |
| 4994 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4995 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4996 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4999 | 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] | 5000 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5001 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5002 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5003 | if (data->commit_done_cb == NULL) |
| 5004 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5005 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5006 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5007 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | } |
| 5009 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5010 | struct nfs4_renewdata { |
| 5011 | struct nfs_client *client; |
| 5012 | unsigned long timestamp; |
| 5013 | }; |
| 5014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | /* |
| 5016 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5017 | * standalone procedure for queueing an asynchronous RENEW. |
| 5018 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5019 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5020 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5021 | struct nfs4_renewdata *data = calldata; |
| 5022 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5023 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5024 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5025 | nfs4_schedule_state_renewal(clp); |
| 5026 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5027 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5028 | } |
| 5029 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5030 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5032 | struct nfs4_renewdata *data = calldata; |
| 5033 | struct nfs_client *clp = data->client; |
| 5034 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5036 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5037 | switch (task->tk_status) { |
| 5038 | case 0: |
| 5039 | break; |
| 5040 | case -NFS4ERR_LEASE_MOVED: |
| 5041 | nfs4_schedule_lease_moved_recovery(clp); |
| 5042 | break; |
| 5043 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5044 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5045 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5046 | return; |
| 5047 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5048 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5049 | return; |
| 5050 | } |
| 5051 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5053 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5054 | } |
| 5055 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5056 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5057 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5058 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5059 | }; |
| 5060 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5061 | 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] | 5062 | { |
| 5063 | struct rpc_message msg = { |
| 5064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5065 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5066 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5068 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5070 | if (renew_flags == 0) |
| 5071 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5072 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5073 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5074 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5075 | if (data == NULL) { |
| 5076 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5077 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5078 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5079 | data->client = clp; |
| 5080 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5081 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5082 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | } |
| 5084 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5085 | 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] | 5086 | { |
| 5087 | struct rpc_message msg = { |
| 5088 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5089 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5090 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5091 | }; |
| 5092 | unsigned long now = jiffies; |
| 5093 | int status; |
| 5094 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5095 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | if (status < 0) |
| 5097 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5098 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | return 0; |
| 5100 | } |
| 5101 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5102 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5103 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5104 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5105 | } |
| 5106 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5107 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5108 | * 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] | 5109 | * the stack. |
| 5110 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5111 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5112 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5113 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5114 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5115 | { |
| 5116 | struct page *newpage, **spages; |
| 5117 | int rc = 0; |
| 5118 | size_t len; |
| 5119 | spages = pages; |
| 5120 | |
| 5121 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5122 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5123 | newpage = alloc_page(GFP_KERNEL); |
| 5124 | |
| 5125 | if (newpage == NULL) |
| 5126 | goto unwind; |
| 5127 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5128 | buf += len; |
| 5129 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5130 | *pages++ = newpage; |
| 5131 | rc++; |
| 5132 | } while (buflen != 0); |
| 5133 | |
| 5134 | return rc; |
| 5135 | |
| 5136 | unwind: |
| 5137 | for(; rc > 0; rc--) |
| 5138 | __free_page(spages[rc-1]); |
| 5139 | return -ENOMEM; |
| 5140 | } |
| 5141 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5142 | struct nfs4_cached_acl { |
| 5143 | int cached; |
| 5144 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5145 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5146 | }; |
| 5147 | |
| 5148 | 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] | 5149 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5150 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5151 | |
| 5152 | spin_lock(&inode->i_lock); |
| 5153 | kfree(nfsi->nfs4_acl); |
| 5154 | nfsi->nfs4_acl = acl; |
| 5155 | spin_unlock(&inode->i_lock); |
| 5156 | } |
| 5157 | |
| 5158 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5159 | { |
| 5160 | nfs4_set_cached_acl(inode, NULL); |
| 5161 | } |
| 5162 | |
| 5163 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5164 | { |
| 5165 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5166 | struct nfs4_cached_acl *acl; |
| 5167 | int ret = -ENOENT; |
| 5168 | |
| 5169 | spin_lock(&inode->i_lock); |
| 5170 | acl = nfsi->nfs4_acl; |
| 5171 | if (acl == NULL) |
| 5172 | goto out; |
| 5173 | if (buf == NULL) /* user is just asking for length */ |
| 5174 | goto out_len; |
| 5175 | if (acl->cached == 0) |
| 5176 | goto out; |
| 5177 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5178 | if (acl->len > buflen) |
| 5179 | goto out; |
| 5180 | memcpy(buf, acl->data, acl->len); |
| 5181 | out_len: |
| 5182 | ret = acl->len; |
| 5183 | out: |
| 5184 | spin_unlock(&inode->i_lock); |
| 5185 | return ret; |
| 5186 | } |
| 5187 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5188 | 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] | 5189 | { |
| 5190 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5191 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5192 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5193 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5194 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5195 | if (acl == NULL) |
| 5196 | goto out; |
| 5197 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5198 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5199 | } else { |
| 5200 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5201 | if (acl == NULL) |
| 5202 | goto out; |
| 5203 | acl->cached = 0; |
| 5204 | } |
| 5205 | acl->len = acl_len; |
| 5206 | out: |
| 5207 | nfs4_set_cached_acl(inode, acl); |
| 5208 | } |
| 5209 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5210 | /* |
| 5211 | * The getxattr API returns the required buffer length when called with a |
| 5212 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5213 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5214 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5215 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5216 | * the cache. If not so, we throw away the page, and cache the required |
| 5217 | * length. The next getxattr call will then produce another round trip to |
| 5218 | * the server, this time with the input buf of the required size. |
| 5219 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5220 | 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] | 5221 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5222 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5223 | struct nfs_getaclargs args = { |
| 5224 | .fh = NFS_FH(inode), |
| 5225 | .acl_pages = pages, |
| 5226 | .acl_len = buflen, |
| 5227 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5228 | struct nfs_getaclres res = { |
| 5229 | .acl_len = buflen, |
| 5230 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5231 | struct rpc_message msg = { |
| 5232 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5233 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5234 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5235 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5236 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5237 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5238 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5239 | if (npages > ARRAY_SIZE(pages)) |
| 5240 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5241 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5242 | for (i = 0; i < npages; i++) { |
| 5243 | pages[i] = alloc_page(GFP_KERNEL); |
| 5244 | if (!pages[i]) |
| 5245 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5246 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5247 | |
| 5248 | /* for decoding across pages */ |
| 5249 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5250 | if (!res.acl_scratch) |
| 5251 | goto out_free; |
| 5252 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5253 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5254 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5255 | 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] | 5256 | __func__, buf, buflen, npages, args.acl_len); |
| 5257 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5258 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5259 | if (ret) |
| 5260 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5261 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5262 | /* Handle the case where the passed-in buffer is too short */ |
| 5263 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5264 | /* Did the user only issue a request for the acl length? */ |
| 5265 | if (buf == NULL) |
| 5266 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5267 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5268 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5269 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5270 | 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] | 5271 | if (buf) { |
| 5272 | if (res.acl_len > buflen) { |
| 5273 | ret = -ERANGE; |
| 5274 | goto out_free; |
| 5275 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5276 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5277 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5278 | out_ok: |
| 5279 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5280 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5281 | for (i = 0; i < npages; i++) |
| 5282 | if (pages[i]) |
| 5283 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5284 | if (res.acl_scratch) |
| 5285 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5286 | return ret; |
| 5287 | } |
| 5288 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5289 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5290 | { |
| 5291 | struct nfs4_exception exception = { }; |
| 5292 | ssize_t ret; |
| 5293 | do { |
| 5294 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5295 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5296 | if (ret >= 0) |
| 5297 | break; |
| 5298 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5299 | } while (exception.retry); |
| 5300 | return ret; |
| 5301 | } |
| 5302 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5303 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5304 | { |
| 5305 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5306 | int ret; |
| 5307 | |
| 5308 | if (!nfs4_server_supports_acls(server)) |
| 5309 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5310 | ret = nfs_revalidate_inode(server, inode); |
| 5311 | if (ret < 0) |
| 5312 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5313 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5314 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5315 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5316 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5317 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5318 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5319 | return ret; |
| 5320 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5323 | 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] | 5324 | { |
| 5325 | struct nfs_server *server = NFS_SERVER(inode); |
| 5326 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5327 | struct nfs_setaclargs arg = { |
| 5328 | .fh = NFS_FH(inode), |
| 5329 | .acl_pages = pages, |
| 5330 | .acl_len = buflen, |
| 5331 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5332 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5333 | struct rpc_message msg = { |
| 5334 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5335 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5336 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5337 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5338 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5339 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5340 | |
| 5341 | if (!nfs4_server_supports_acls(server)) |
| 5342 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5343 | if (npages > ARRAY_SIZE(pages)) |
| 5344 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5345 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5346 | if (i < 0) |
| 5347 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5348 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5349 | 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] | 5350 | |
| 5351 | /* |
| 5352 | * Free each page after tx, so the only ref left is |
| 5353 | * held by the network stack |
| 5354 | */ |
| 5355 | for (; i > 0; i--) |
| 5356 | put_page(pages[i-1]); |
| 5357 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5358 | /* |
| 5359 | * Acl update can result in inode attribute update. |
| 5360 | * so mark the attribute cache invalid. |
| 5361 | */ |
| 5362 | spin_lock(&inode->i_lock); |
| 5363 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5364 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5365 | nfs_access_zap_cache(inode); |
| 5366 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5367 | return ret; |
| 5368 | } |
| 5369 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5370 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5371 | { |
| 5372 | struct nfs4_exception exception = { }; |
| 5373 | int err; |
| 5374 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5375 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5376 | trace_nfs4_set_acl(inode, err); |
| 5377 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5378 | &exception); |
| 5379 | } while (exception.retry); |
| 5380 | return err; |
| 5381 | } |
| 5382 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5383 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5384 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5385 | size_t buflen) |
| 5386 | { |
| 5387 | struct nfs_server *server = NFS_SERVER(inode); |
| 5388 | struct nfs_fattr fattr; |
| 5389 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5390 | |
| 5391 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5392 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5393 | .fh = NFS_FH(inode), |
| 5394 | .bitmask = bitmask, |
| 5395 | }; |
| 5396 | struct nfs4_getattr_res res = { |
| 5397 | .fattr = &fattr, |
| 5398 | .label = &label, |
| 5399 | .server = server, |
| 5400 | }; |
| 5401 | struct rpc_message msg = { |
| 5402 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5403 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5404 | .rpc_resp = &res, |
| 5405 | }; |
| 5406 | int ret; |
| 5407 | |
| 5408 | nfs_fattr_init(&fattr); |
| 5409 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5410 | 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] | 5411 | if (ret) |
| 5412 | return ret; |
| 5413 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5414 | return -ENOENT; |
| 5415 | if (buflen < label.len) |
| 5416 | return -ERANGE; |
| 5417 | return 0; |
| 5418 | } |
| 5419 | |
| 5420 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5421 | size_t buflen) |
| 5422 | { |
| 5423 | struct nfs4_exception exception = { }; |
| 5424 | int err; |
| 5425 | |
| 5426 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5427 | return -EOPNOTSUPP; |
| 5428 | |
| 5429 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5430 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5431 | trace_nfs4_get_security_label(inode, err); |
| 5432 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5433 | &exception); |
| 5434 | } while (exception.retry); |
| 5435 | return err; |
| 5436 | } |
| 5437 | |
| 5438 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5439 | struct nfs4_label *ilabel, |
| 5440 | struct nfs_fattr *fattr, |
| 5441 | struct nfs4_label *olabel) |
| 5442 | { |
| 5443 | |
| 5444 | struct iattr sattr = {0}; |
| 5445 | struct nfs_server *server = NFS_SERVER(inode); |
| 5446 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5447 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5448 | .fh = NFS_FH(inode), |
| 5449 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5450 | .server = server, |
| 5451 | .bitmask = bitmask, |
| 5452 | .label = ilabel, |
| 5453 | }; |
| 5454 | struct nfs_setattrres res = { |
| 5455 | .fattr = fattr, |
| 5456 | .label = olabel, |
| 5457 | .server = server, |
| 5458 | }; |
| 5459 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5460 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5461 | .rpc_argp = &arg, |
| 5462 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5463 | }; |
| 5464 | int status; |
| 5465 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5466 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5467 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5468 | 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] | 5469 | if (status) |
| 5470 | dprintk("%s failed: %d\n", __func__, status); |
| 5471 | |
| 5472 | return status; |
| 5473 | } |
| 5474 | |
| 5475 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5476 | struct nfs4_label *ilabel, |
| 5477 | struct nfs_fattr *fattr, |
| 5478 | struct nfs4_label *olabel) |
| 5479 | { |
| 5480 | struct nfs4_exception exception = { }; |
| 5481 | int err; |
| 5482 | |
| 5483 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5484 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5485 | fattr, olabel); |
| 5486 | trace_nfs4_set_security_label(inode, err); |
| 5487 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5488 | &exception); |
| 5489 | } while (exception.retry); |
| 5490 | return err; |
| 5491 | } |
| 5492 | |
| 5493 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5494 | 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] | 5495 | { |
| 5496 | struct nfs4_label ilabel, *olabel = NULL; |
| 5497 | struct nfs_fattr fattr; |
| 5498 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5499 | int status; |
| 5500 | |
| 5501 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5502 | return -EOPNOTSUPP; |
| 5503 | |
| 5504 | nfs_fattr_init(&fattr); |
| 5505 | |
| 5506 | ilabel.pi = 0; |
| 5507 | ilabel.lfs = 0; |
| 5508 | ilabel.label = (char *)buf; |
| 5509 | ilabel.len = buflen; |
| 5510 | |
| 5511 | cred = rpc_lookup_cred(); |
| 5512 | if (IS_ERR(cred)) |
| 5513 | return PTR_ERR(cred); |
| 5514 | |
| 5515 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5516 | if (IS_ERR(olabel)) { |
| 5517 | status = -PTR_ERR(olabel); |
| 5518 | goto out; |
| 5519 | } |
| 5520 | |
| 5521 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5522 | if (status == 0) |
| 5523 | nfs_setsecurity(inode, &fattr, olabel); |
| 5524 | |
| 5525 | nfs4_label_free(olabel); |
| 5526 | out: |
| 5527 | put_rpccred(cred); |
| 5528 | return status; |
| 5529 | } |
| 5530 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5531 | |
| 5532 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5533 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5534 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5535 | { |
| 5536 | __be32 verf[2]; |
| 5537 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5538 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5539 | /* An impossible timestamp guarantees this value |
| 5540 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5541 | verf[0] = cpu_to_be32(U32_MAX); |
| 5542 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5543 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5544 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5545 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5546 | |
| 5547 | verf[0] = cpu_to_be32(ns >> 32); |
| 5548 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5549 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5550 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5551 | } |
| 5552 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5553 | static int |
| 5554 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5555 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5556 | size_t len; |
| 5557 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5558 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5559 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5560 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5561 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5562 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5563 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5564 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5565 | 1 + |
| 5566 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5567 | 1; |
| 5568 | rcu_read_unlock(); |
| 5569 | |
| 5570 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5571 | return -EINVAL; |
| 5572 | |
| 5573 | /* |
| 5574 | * Since this string is allocated at mount time, and held until the |
| 5575 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5576 | * about a memory-reclaim deadlock. |
| 5577 | */ |
| 5578 | str = kmalloc(len, GFP_KERNEL); |
| 5579 | if (!str) |
| 5580 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5581 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5582 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5583 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5584 | clp->cl_ipaddr, |
| 5585 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5586 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5587 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5588 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5589 | clp->cl_owner_id = str; |
| 5590 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5591 | } |
| 5592 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5593 | static int |
| 5594 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5595 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5596 | size_t len; |
| 5597 | char *str; |
| 5598 | |
| 5599 | len = 10 + 10 + 1 + 10 + 1 + |
| 5600 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5601 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5602 | |
| 5603 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5604 | return -EINVAL; |
| 5605 | |
| 5606 | /* |
| 5607 | * Since this string is allocated at mount time, and held until the |
| 5608 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5609 | * about a memory-reclaim deadlock. |
| 5610 | */ |
| 5611 | str = kmalloc(len, GFP_KERNEL); |
| 5612 | if (!str) |
| 5613 | return -ENOMEM; |
| 5614 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5615 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5616 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5617 | nfs4_client_id_uniquifier, |
| 5618 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5619 | clp->cl_owner_id = str; |
| 5620 | return 0; |
| 5621 | } |
| 5622 | |
| 5623 | static int |
| 5624 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5625 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5626 | size_t len; |
| 5627 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5628 | |
| 5629 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5630 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5631 | |
| 5632 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5633 | return nfs4_init_uniquifier_client_string(clp); |
| 5634 | |
| 5635 | len = 10 + 10 + 1 + 10 + 1 + |
| 5636 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5637 | |
| 5638 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5639 | return -EINVAL; |
| 5640 | |
| 5641 | /* |
| 5642 | * Since this string is allocated at mount time, and held until the |
| 5643 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5644 | * about a memory-reclaim deadlock. |
| 5645 | */ |
| 5646 | str = kmalloc(len, GFP_KERNEL); |
| 5647 | if (!str) |
| 5648 | return -ENOMEM; |
| 5649 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5650 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5651 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5652 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5653 | clp->cl_owner_id = str; |
| 5654 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5655 | } |
| 5656 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5657 | /* |
| 5658 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5659 | * services. Advertise one based on the address family of the |
| 5660 | * clientaddr. |
| 5661 | */ |
| 5662 | static unsigned int |
| 5663 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5664 | { |
| 5665 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5666 | return scnprintf(buf, len, "tcp6"); |
| 5667 | else |
| 5668 | return scnprintf(buf, len, "tcp"); |
| 5669 | } |
| 5670 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5671 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5672 | { |
| 5673 | struct nfs4_setclientid *sc = calldata; |
| 5674 | |
| 5675 | if (task->tk_status == 0) |
| 5676 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5677 | } |
| 5678 | |
| 5679 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5680 | .rpc_call_done = nfs4_setclientid_done, |
| 5681 | }; |
| 5682 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5683 | /** |
| 5684 | * nfs4_proc_setclientid - Negotiate client ID |
| 5685 | * @clp: state data structure |
| 5686 | * @program: RPC program for NFSv4 callback service |
| 5687 | * @port: IP port number for NFS4 callback service |
| 5688 | * @cred: RPC credential to use for this call |
| 5689 | * @res: where to place the result |
| 5690 | * |
| 5691 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5692 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5693 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5694 | unsigned short port, struct rpc_cred *cred, |
| 5695 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | { |
| 5697 | nfs4_verifier sc_verifier; |
| 5698 | struct nfs4_setclientid setclientid = { |
| 5699 | .sc_verifier = &sc_verifier, |
| 5700 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5701 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | }; |
| 5703 | struct rpc_message msg = { |
| 5704 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5705 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5706 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5707 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5709 | struct rpc_task *task; |
| 5710 | struct rpc_task_setup task_setup_data = { |
| 5711 | .rpc_client = clp->cl_rpcclient, |
| 5712 | .rpc_message = &msg, |
| 5713 | .callback_ops = &nfs4_setclientid_ops, |
| 5714 | .callback_data = &setclientid, |
| 5715 | .flags = RPC_TASK_TIMEOUT, |
| 5716 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5717 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5719 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5720 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5721 | |
| 5722 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5723 | status = nfs4_init_uniform_client_string(clp); |
| 5724 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5725 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5726 | |
| 5727 | if (status) |
| 5728 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5729 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5730 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5731 | setclientid.sc_netid_len = |
| 5732 | nfs4_init_callback_netid(clp, |
| 5733 | setclientid.sc_netid, |
| 5734 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5735 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5736 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5738 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5739 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5740 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5741 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5742 | task = rpc_run_task(&task_setup_data); |
| 5743 | if (IS_ERR(task)) { |
| 5744 | status = PTR_ERR(task); |
| 5745 | goto out; |
| 5746 | } |
| 5747 | status = task->tk_status; |
| 5748 | if (setclientid.sc_cred) { |
| 5749 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5750 | put_rpccred(setclientid.sc_cred); |
| 5751 | } |
| 5752 | rpc_put_task(task); |
| 5753 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5754 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5755 | dprintk("NFS reply setclientid: %d\n", status); |
| 5756 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5757 | } |
| 5758 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5759 | /** |
| 5760 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5761 | * @clp: state data structure |
| 5762 | * @res: result of a previous SETCLIENTID |
| 5763 | * @cred: RPC credential to use for this call |
| 5764 | * |
| 5765 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5766 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5767 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5768 | struct nfs4_setclientid_res *arg, |
| 5769 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5770 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | struct rpc_message msg = { |
| 5772 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5773 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5774 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5776 | int status; |
| 5777 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5778 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5779 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5780 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5781 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5782 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5783 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | return status; |
| 5785 | } |
| 5786 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5787 | struct nfs4_delegreturndata { |
| 5788 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5789 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5790 | struct nfs_fh fh; |
| 5791 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5792 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5793 | struct { |
| 5794 | struct nfs4_layoutreturn_args arg; |
| 5795 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5796 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5797 | u32 roc_barrier; |
| 5798 | bool roc; |
| 5799 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5800 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5801 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5802 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5803 | }; |
| 5804 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5805 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5806 | { |
| 5807 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5808 | struct nfs4_exception exception = { |
| 5809 | .inode = data->inode, |
| 5810 | .stateid = &data->stateid, |
| 5811 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5812 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5813 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5814 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5815 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5816 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5817 | |
| 5818 | /* Handle Layoutreturn errors */ |
| 5819 | if (data->args.lr_args && task->tk_status != 0) { |
| 5820 | switch(data->res.lr_ret) { |
| 5821 | default: |
| 5822 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5823 | break; |
| 5824 | case 0: |
| 5825 | data->args.lr_args = NULL; |
| 5826 | data->res.lr_res = NULL; |
| 5827 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5828 | case -NFS4ERR_OLD_STATEID: |
| 5829 | if (nfs4_refresh_layout_stateid(&data->args.lr_args->stateid, |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5830 | data->inode)) |
| 5831 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5832 | /* Fallthrough */ |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5833 | case -NFS4ERR_ADMIN_REVOKED: |
| 5834 | case -NFS4ERR_DELEG_REVOKED: |
| 5835 | case -NFS4ERR_EXPIRED: |
| 5836 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5837 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5838 | case -NFS4ERR_WRONG_CRED: |
| 5839 | data->args.lr_args = NULL; |
| 5840 | data->res.lr_res = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5841 | goto lr_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5842 | } |
| 5843 | } |
| 5844 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5845 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5846 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5847 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5848 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5849 | case -NFS4ERR_ADMIN_REVOKED: |
| 5850 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5851 | case -NFS4ERR_EXPIRED: |
| 5852 | nfs4_free_revoked_stateid(data->res.server, |
| 5853 | data->args.stateid, |
| 5854 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5855 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5856 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5857 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5858 | task->tk_status = 0; |
| 5859 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5860 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5861 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 5862 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5863 | task->tk_status = 0; |
| 5864 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5865 | case -NFS4ERR_ACCESS: |
| 5866 | if (data->args.bitmask) { |
| 5867 | data->args.bitmask = NULL; |
| 5868 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5869 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5870 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5871 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5872 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5873 | task->tk_status = nfs4_async_handle_exception(task, |
| 5874 | data->res.server, task->tk_status, |
| 5875 | &exception); |
| 5876 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5877 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5878 | } |
| 5879 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5880 | return; |
| 5881 | lr_restart: |
| 5882 | data->res.lr_ret = 0; |
| 5883 | out_restart: |
| 5884 | task->tk_status = 0; |
| 5885 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | static void nfs4_delegreturn_release(void *calldata) |
| 5889 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5890 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5891 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5892 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5893 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5894 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5895 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5896 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5897 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5898 | nfs_iput_and_deactive(inode); |
| 5899 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5900 | kfree(calldata); |
| 5901 | } |
| 5902 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5903 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5904 | { |
| 5905 | struct nfs4_delegreturndata *d_data; |
| 5906 | |
| 5907 | d_data = (struct nfs4_delegreturndata *)data; |
| 5908 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5909 | 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] | 5910 | return; |
| 5911 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5912 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5913 | &d_data->args.seq_args, |
| 5914 | &d_data->res.seq_res, |
| 5915 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5916 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5917 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5918 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5919 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5920 | .rpc_call_done = nfs4_delegreturn_done, |
| 5921 | .rpc_release = nfs4_delegreturn_release, |
| 5922 | }; |
| 5923 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5924 | 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] | 5925 | { |
| 5926 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5927 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5928 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5929 | struct rpc_message msg = { |
| 5930 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5931 | .rpc_cred = cred, |
| 5932 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5933 | struct rpc_task_setup task_setup_data = { |
| 5934 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5935 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5936 | .callback_ops = &nfs4_delegreturn_ops, |
| 5937 | .flags = RPC_TASK_ASYNC, |
| 5938 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5939 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5940 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5941 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5942 | if (data == NULL) |
| 5943 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5944 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5945 | |
| 5946 | nfs4_state_protect(server->nfs_client, |
| 5947 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5948 | &task_setup_data.rpc_client, &msg); |
| 5949 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5950 | data->args.fhandle = &data->fh; |
| 5951 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5952 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5953 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5954 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5955 | data->res.fattr = &data->fattr; |
| 5956 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5957 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5958 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5959 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5960 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5961 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5962 | 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] | 5963 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5964 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5965 | if (data->lr.roc) { |
| 5966 | data->args.lr_args = &data->lr.arg; |
| 5967 | data->res.lr_res = &data->lr.res; |
| 5968 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5969 | } else if (data->lr.roc) { |
| 5970 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5971 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5972 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5973 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5974 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5975 | msg.rpc_argp = &data->args; |
| 5976 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5977 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5978 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5979 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5980 | if (!issync) |
| 5981 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5982 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5983 | if (status != 0) |
| 5984 | goto out; |
| 5985 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5986 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5987 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5988 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5989 | } |
| 5990 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5991 | 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] | 5992 | { |
| 5993 | struct nfs_server *server = NFS_SERVER(inode); |
| 5994 | struct nfs4_exception exception = { }; |
| 5995 | int err; |
| 5996 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5997 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5998 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5999 | switch (err) { |
| 6000 | case -NFS4ERR_STALE_STATEID: |
| 6001 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6002 | case 0: |
| 6003 | return 0; |
| 6004 | } |
| 6005 | err = nfs4_handle_exception(server, err, &exception); |
| 6006 | } while (exception.retry); |
| 6007 | return err; |
| 6008 | } |
| 6009 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6011 | { |
| 6012 | struct inode *inode = state->inode; |
| 6013 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6014 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6015 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6017 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6018 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6019 | struct nfs_lockt_res res = { |
| 6020 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6021 | }; |
| 6022 | struct rpc_message msg = { |
| 6023 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6024 | .rpc_argp = &arg, |
| 6025 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6026 | .rpc_cred = state->owner->so_cred, |
| 6027 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6028 | struct nfs4_lock_state *lsp; |
| 6029 | int status; |
| 6030 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6031 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6032 | status = nfs4_set_lock_state(state, request); |
| 6033 | if (status != 0) |
| 6034 | goto out; |
| 6035 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6036 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6037 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6038 | 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] | 6039 | switch (status) { |
| 6040 | case 0: |
| 6041 | request->fl_type = F_UNLCK; |
| 6042 | break; |
| 6043 | case -NFS4ERR_DENIED: |
| 6044 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6045 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6046 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6047 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6048 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6049 | return status; |
| 6050 | } |
| 6051 | |
| 6052 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6053 | { |
| 6054 | struct nfs4_exception exception = { }; |
| 6055 | int err; |
| 6056 | |
| 6057 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6058 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6059 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6060 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6061 | &exception); |
| 6062 | } while (exception.retry); |
| 6063 | return err; |
| 6064 | } |
| 6065 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6066 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6067 | struct nfs_locku_args arg; |
| 6068 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6069 | struct nfs4_lock_state *lsp; |
| 6070 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6071 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6072 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6073 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6074 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6075 | }; |
| 6076 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6077 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6078 | struct nfs_open_context *ctx, |
| 6079 | struct nfs4_lock_state *lsp, |
| 6080 | struct nfs_seqid *seqid) |
| 6081 | { |
| 6082 | struct nfs4_unlockdata *p; |
| 6083 | struct inode *inode = lsp->ls_state->inode; |
| 6084 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6085 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6086 | if (p == NULL) |
| 6087 | return NULL; |
| 6088 | p->arg.fh = NFS_FH(inode); |
| 6089 | p->arg.fl = &p->fl; |
| 6090 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6091 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6092 | p->lsp = lsp; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6093 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6094 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6095 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6096 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6097 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6098 | p->server = NFS_SERVER(inode); |
| 6099 | return p; |
| 6100 | } |
| 6101 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6102 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6103 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6104 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6105 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6106 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6107 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6108 | put_nfs_open_context(calldata->ctx); |
| 6109 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6110 | } |
| 6111 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6112 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6113 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6114 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6115 | struct nfs4_exception exception = { |
| 6116 | .inode = calldata->lsp->ls_state->inode, |
| 6117 | .stateid = &calldata->arg.stateid, |
| 6118 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6119 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6120 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6121 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6122 | switch (task->tk_status) { |
| 6123 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6124 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6125 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6126 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6127 | &calldata->res.stateid)) |
| 6128 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6129 | case -NFS4ERR_ADMIN_REVOKED: |
| 6130 | case -NFS4ERR_EXPIRED: |
| 6131 | nfs4_free_revoked_stateid(calldata->server, |
| 6132 | &calldata->arg.stateid, |
| 6133 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6134 | case -NFS4ERR_BAD_STATEID: |
| 6135 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6136 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6137 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 6138 | &calldata->lsp->ls_stateid)) |
| 6139 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6140 | break; |
| 6141 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6142 | task->tk_status = nfs4_async_handle_exception(task, |
| 6143 | calldata->server, task->tk_status, |
| 6144 | &exception); |
| 6145 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6146 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6147 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6148 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6149 | } |
| 6150 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6151 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6152 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6153 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6154 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6155 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6156 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6157 | return; |
| 6158 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6159 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6160 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6161 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6162 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6163 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6164 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6165 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6166 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6167 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6168 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6169 | &calldata->res.seq_res, |
| 6170 | task) != 0) |
| 6171 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6172 | return; |
| 6173 | out_no_action: |
| 6174 | task->tk_action = NULL; |
| 6175 | out_wait: |
| 6176 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6177 | } |
| 6178 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6179 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6180 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6181 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6182 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6183 | }; |
| 6184 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6185 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6186 | struct nfs_open_context *ctx, |
| 6187 | struct nfs4_lock_state *lsp, |
| 6188 | struct nfs_seqid *seqid) |
| 6189 | { |
| 6190 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6191 | struct rpc_message msg = { |
| 6192 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6193 | .rpc_cred = ctx->cred, |
| 6194 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6195 | struct rpc_task_setup task_setup_data = { |
| 6196 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6197 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6198 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6199 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6200 | .flags = RPC_TASK_ASYNC, |
| 6201 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6202 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6203 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6204 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6205 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6206 | /* Ensure this is an unlock - when canceling a lock, the |
| 6207 | * canceled lock is passed in, and it won't be an unlock. |
| 6208 | */ |
| 6209 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6210 | if (fl->fl_flags & FL_CLOSE) |
| 6211 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6212 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6213 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6214 | if (data == NULL) { |
| 6215 | nfs_free_seqid(seqid); |
| 6216 | return ERR_PTR(-ENOMEM); |
| 6217 | } |
| 6218 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6219 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6220 | msg.rpc_argp = &data->arg; |
| 6221 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6222 | task_setup_data.callback_data = data; |
| 6223 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6224 | } |
| 6225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6227 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6228 | struct inode *inode = state->inode; |
| 6229 | struct nfs4_state_owner *sp = state->owner; |
| 6230 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6231 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6232 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6233 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6234 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6235 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6236 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6237 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6238 | status = nfs4_set_lock_state(state, request); |
| 6239 | /* Unlock _before_ we do the RPC call */ |
| 6240 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6241 | /* Exclude nfs_delegation_claim_locks() */ |
| 6242 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6243 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6244 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6245 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6246 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6247 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6248 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6249 | } |
| 6250 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6251 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6252 | if (status != 0) |
| 6253 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6254 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6255 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6256 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6257 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6258 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6259 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6260 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6261 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6262 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6263 | 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] | 6264 | status = PTR_ERR(task); |
| 6265 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6266 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6267 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6268 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6269 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6270 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6271 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6272 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6275 | struct nfs4_lockdata { |
| 6276 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6277 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6278 | struct nfs4_lock_state *lsp; |
| 6279 | struct nfs_open_context *ctx; |
| 6280 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6281 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6282 | int rpc_status; |
| 6283 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6284 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6285 | }; |
| 6286 | |
| 6287 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6288 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6289 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6290 | { |
| 6291 | struct nfs4_lockdata *p; |
| 6292 | struct inode *inode = lsp->ls_state->inode; |
| 6293 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6294 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6295 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6296 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6297 | if (p == NULL) |
| 6298 | return NULL; |
| 6299 | |
| 6300 | p->arg.fh = NFS_FH(inode); |
| 6301 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6302 | 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] | 6303 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6304 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6305 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6306 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6307 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6308 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6309 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6310 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6311 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6312 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6313 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6314 | p->server = server; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6315 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6316 | p->ctx = get_nfs_open_context(ctx); |
| 6317 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6318 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6319 | out_free_seqid: |
| 6320 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6321 | out_free: |
| 6322 | kfree(p); |
| 6323 | return NULL; |
| 6324 | } |
| 6325 | |
| 6326 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6327 | { |
| 6328 | struct nfs4_lockdata *data = calldata; |
| 6329 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6330 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6331 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6332 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6333 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6334 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6335 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6336 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6337 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6338 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6339 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6340 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6341 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6342 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6343 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6344 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6345 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6346 | &data->lsp->ls_stateid); |
| 6347 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6348 | if (!nfs4_valid_open_stateid(state)) { |
| 6349 | data->rpc_status = -EBADF; |
| 6350 | task->tk_action = NULL; |
| 6351 | goto out_release_open_seqid; |
| 6352 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6353 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6354 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6355 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6356 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6357 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6358 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6359 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6360 | nfs_release_seqid(data->arg.open_seqid); |
| 6361 | out_release_lock_seqid: |
| 6362 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6363 | out_wait: |
| 6364 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6365 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6366 | } |
| 6367 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6368 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6369 | { |
| 6370 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6371 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6372 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6373 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6374 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6375 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6376 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6377 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6378 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6379 | switch (task->tk_status) { |
| 6380 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6381 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6382 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6383 | if (data->arg.new_lock) { |
| 6384 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6385 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6386 | rpc_restart_call_prepare(task); |
| 6387 | break; |
| 6388 | } |
| 6389 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6390 | if (data->arg.new_lock_owner != 0) { |
| 6391 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6392 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6393 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6394 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6395 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6396 | break; |
| 6397 | case -NFS4ERR_BAD_STATEID: |
| 6398 | case -NFS4ERR_OLD_STATEID: |
| 6399 | case -NFS4ERR_STALE_STATEID: |
| 6400 | case -NFS4ERR_EXPIRED: |
| 6401 | if (data->arg.new_lock_owner != 0) { |
| 6402 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6403 | &lsp->ls_state->open_stateid)) |
| 6404 | rpc_restart_call_prepare(task); |
| 6405 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6406 | &lsp->ls_stateid)) |
| 6407 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6408 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6409 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | static void nfs4_lock_release(void *calldata) |
| 6413 | { |
| 6414 | struct nfs4_lockdata *data = calldata; |
| 6415 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6416 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6417 | nfs_free_seqid(data->arg.open_seqid); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6418 | if (data->cancelled) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6419 | struct rpc_task *task; |
| 6420 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6421 | data->arg.lock_seqid); |
| 6422 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6423 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6424 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6425 | } else |
| 6426 | nfs_free_seqid(data->arg.lock_seqid); |
| 6427 | nfs4_put_lock_state(data->lsp); |
| 6428 | put_nfs_open_context(data->ctx); |
| 6429 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6430 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6431 | } |
| 6432 | |
| 6433 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6434 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6435 | .rpc_call_done = nfs4_lock_done, |
| 6436 | .rpc_release = nfs4_lock_release, |
| 6437 | }; |
| 6438 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6439 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6440 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6441 | switch (error) { |
| 6442 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6443 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6444 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6445 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6446 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6447 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6448 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6449 | break; |
| 6450 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6451 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6452 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6453 | }; |
| 6454 | } |
| 6455 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6456 | 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] | 6457 | { |
| 6458 | struct nfs4_lockdata *data; |
| 6459 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6460 | struct rpc_message msg = { |
| 6461 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6462 | .rpc_cred = state->owner->so_cred, |
| 6463 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6464 | struct rpc_task_setup task_setup_data = { |
| 6465 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6466 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6467 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6468 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6469 | .flags = RPC_TASK_ASYNC, |
| 6470 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6471 | int ret; |
| 6472 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6473 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6474 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6475 | fl->fl_u.nfs4_fl.owner, |
| 6476 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6477 | if (data == NULL) |
| 6478 | return -ENOMEM; |
| 6479 | if (IS_SETLKW(cmd)) |
| 6480 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6481 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6482 | msg.rpc_argp = &data->arg; |
| 6483 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6484 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6485 | if (recovery_type > NFS_LOCK_NEW) { |
| 6486 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6487 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6488 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6489 | } else |
| 6490 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6491 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6492 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6493 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6494 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6495 | if (ret == 0) { |
| 6496 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6497 | if (ret) |
| 6498 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6499 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6500 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6501 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6502 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6503 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6504 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6505 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6506 | } |
| 6507 | |
| 6508 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6509 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6510 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6511 | struct nfs4_exception exception = { |
| 6512 | .inode = state->inode, |
| 6513 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6514 | int err; |
| 6515 | |
| 6516 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6517 | /* Cache the lock if possible... */ |
| 6518 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6519 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6520 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6521 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6522 | break; |
| 6523 | nfs4_handle_exception(server, err, &exception); |
| 6524 | } while (exception.retry); |
| 6525 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6526 | } |
| 6527 | |
| 6528 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6529 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6530 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6531 | struct nfs4_exception exception = { |
| 6532 | .inode = state->inode, |
| 6533 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6534 | int err; |
| 6535 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6536 | err = nfs4_set_lock_state(state, request); |
| 6537 | if (err != 0) |
| 6538 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6539 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6540 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6541 | return 0; |
| 6542 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6543 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6544 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6545 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6546 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6547 | switch (err) { |
| 6548 | default: |
| 6549 | goto out; |
| 6550 | case -NFS4ERR_GRACE: |
| 6551 | case -NFS4ERR_DELAY: |
| 6552 | nfs4_handle_exception(server, err, &exception); |
| 6553 | err = 0; |
| 6554 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6555 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6556 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6557 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6558 | } |
| 6559 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6560 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6561 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6562 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6563 | struct nfs4_lock_state *lsp; |
| 6564 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6565 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6566 | status = nfs4_set_lock_state(state, request); |
| 6567 | if (status != 0) |
| 6568 | return status; |
| 6569 | lsp = request->fl_u.nfs4_fl.owner; |
| 6570 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6571 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6572 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6573 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6574 | } |
| 6575 | #endif |
| 6576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6577 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6578 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6579 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6580 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6581 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6582 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6583 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6584 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6585 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6586 | if (status < 0) |
| 6587 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6588 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6589 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6590 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6591 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6592 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6593 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6594 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6595 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6596 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6597 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6598 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6599 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6600 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6601 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6602 | out: |
| 6603 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6604 | return status; |
| 6605 | } |
| 6606 | |
| 6607 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6608 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6609 | struct nfs4_exception exception = { |
| 6610 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6611 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6612 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6613 | int err; |
| 6614 | |
| 6615 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6616 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6617 | if (err == -NFS4ERR_DENIED) |
| 6618 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6619 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6620 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | } while (exception.retry); |
| 6622 | return err; |
| 6623 | } |
| 6624 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6625 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6626 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6627 | |
| 6628 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6629 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6630 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6631 | { |
| 6632 | int status = -ERESTARTSYS; |
| 6633 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6634 | |
| 6635 | while(!signalled()) { |
| 6636 | status = nfs4_proc_setlk(state, cmd, request); |
| 6637 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6638 | break; |
| 6639 | freezable_schedule_timeout_interruptible(timeout); |
| 6640 | timeout *= 2; |
| 6641 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6642 | status = -ERESTARTSYS; |
| 6643 | } |
| 6644 | return status; |
| 6645 | } |
| 6646 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6647 | #ifdef CONFIG_NFS_V4_1 |
| 6648 | struct nfs4_lock_waiter { |
| 6649 | struct task_struct *task; |
| 6650 | struct inode *inode; |
| 6651 | struct nfs_lowner *owner; |
| 6652 | bool notified; |
| 6653 | }; |
| 6654 | |
| 6655 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6656 | nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, void *key) |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6657 | { |
| 6658 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6659 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6660 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6661 | /* NULL key means to wake up everyone */ |
| 6662 | if (key) { |
| 6663 | struct cb_notify_lock_args *cbnl = key; |
| 6664 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6665 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6666 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6667 | /* Only wake if the callback was for the same owner. */ |
| 6668 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 6669 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6670 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6671 | /* Make sure it's for the right inode */ |
| 6672 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6673 | return 0; |
| 6674 | |
| 6675 | waiter->notified = true; |
| 6676 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6677 | |
| 6678 | /* override "private" so we can use default_wake_function */ |
| 6679 | wait->private = waiter->task; |
| 6680 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6681 | wait->private = waiter; |
| 6682 | return ret; |
| 6683 | } |
| 6684 | |
| 6685 | static int |
| 6686 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6687 | { |
| 6688 | int status = -ERESTARTSYS; |
| 6689 | unsigned long flags; |
| 6690 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6691 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6692 | struct nfs_client *clp = server->nfs_client; |
| 6693 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6694 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6695 | .id = lsp->ls_seqid.owner_id, |
| 6696 | .s_dev = server->s_dev }; |
| 6697 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6698 | .inode = state->inode, |
| 6699 | .owner = &owner, |
| 6700 | .notified = false }; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6701 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6702 | |
| 6703 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6704 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6705 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6706 | |
| 6707 | init_wait(&wait); |
| 6708 | wait.private = &waiter; |
| 6709 | wait.func = nfs4_wake_lock_waiter; |
| 6710 | add_wait_queue(q, &wait); |
| 6711 | |
| 6712 | while(!signalled()) { |
Jeff Layton | 41a7462 | 2018-03-18 08:37:01 -0400 | [diff] [blame] | 6713 | waiter.notified = false; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6714 | status = nfs4_proc_setlk(state, cmd, request); |
| 6715 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6716 | break; |
| 6717 | |
| 6718 | status = -ERESTARTSYS; |
| 6719 | spin_lock_irqsave(&q->lock, flags); |
| 6720 | if (waiter.notified) { |
| 6721 | spin_unlock_irqrestore(&q->lock, flags); |
| 6722 | continue; |
| 6723 | } |
| 6724 | set_current_state(TASK_INTERRUPTIBLE); |
| 6725 | spin_unlock_irqrestore(&q->lock, flags); |
| 6726 | |
Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6727 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6728 | } |
| 6729 | |
| 6730 | finish_wait(q, &wait); |
| 6731 | return status; |
| 6732 | } |
| 6733 | #else /* !CONFIG_NFS_V4_1 */ |
| 6734 | static inline int |
| 6735 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6736 | { |
| 6737 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6738 | } |
| 6739 | #endif |
| 6740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6741 | static int |
| 6742 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6743 | { |
| 6744 | struct nfs_open_context *ctx; |
| 6745 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6746 | int status; |
| 6747 | |
| 6748 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6749 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6750 | state = ctx->state; |
| 6751 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6752 | if (IS_GETLK(cmd)) { |
| 6753 | if (state != NULL) |
| 6754 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6755 | return 0; |
| 6756 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6757 | |
| 6758 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6759 | return -EINVAL; |
| 6760 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6761 | if (request->fl_type == F_UNLCK) { |
| 6762 | if (state != NULL) |
| 6763 | return nfs4_proc_unlck(state, cmd, request); |
| 6764 | return 0; |
| 6765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6766 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6767 | if (state == NULL) |
| 6768 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6769 | |
| 6770 | if ((request->fl_flags & FL_POSIX) && |
| 6771 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6772 | return -ENOLCK; |
| 6773 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 6774 | /* |
| 6775 | * Don't rely on the VFS having checked the file open mode, |
| 6776 | * since it won't do this for flock() locks. |
| 6777 | */ |
| 6778 | switch (request->fl_type) { |
| 6779 | case F_RDLCK: |
| 6780 | if (!(filp->f_mode & FMODE_READ)) |
| 6781 | return -EBADF; |
| 6782 | break; |
| 6783 | case F_WRLCK: |
| 6784 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6785 | return -EBADF; |
| 6786 | } |
| 6787 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6788 | status = nfs4_set_lock_state(state, request); |
| 6789 | if (status != 0) |
| 6790 | return status; |
| 6791 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6792 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | } |
| 6794 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6795 | 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] | 6796 | { |
| 6797 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6798 | int err; |
| 6799 | |
| 6800 | err = nfs4_set_lock_state(state, fl); |
| 6801 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6802 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6803 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 6804 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6805 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6806 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6807 | struct nfs_release_lockowner_data { |
| 6808 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6809 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6810 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6811 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6812 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6813 | }; |
| 6814 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6815 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6816 | { |
| 6817 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6818 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6819 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6820 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6821 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6822 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6823 | } |
| 6824 | |
| 6825 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6826 | { |
| 6827 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6828 | struct nfs_server *server = data->server; |
| 6829 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6830 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6831 | |
| 6832 | switch (task->tk_status) { |
| 6833 | case 0: |
| 6834 | renew_lease(server, data->timestamp); |
| 6835 | break; |
| 6836 | case -NFS4ERR_STALE_CLIENTID: |
| 6837 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6838 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6839 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6840 | case -NFS4ERR_LEASE_MOVED: |
| 6841 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6842 | if (nfs4_async_handle_error(task, server, |
| 6843 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6844 | rpc_restart_call_prepare(task); |
| 6845 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6846 | } |
| 6847 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6848 | static void nfs4_release_lockowner_release(void *calldata) |
| 6849 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6850 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6851 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6852 | kfree(calldata); |
| 6853 | } |
| 6854 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6855 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6856 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6857 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6858 | .rpc_release = nfs4_release_lockowner_release, |
| 6859 | }; |
| 6860 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6861 | static void |
| 6862 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6863 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6864 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6865 | struct rpc_message msg = { |
| 6866 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6867 | }; |
| 6868 | |
| 6869 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6870 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6871 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6872 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6873 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6874 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6875 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6876 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6877 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6878 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6879 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6880 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6881 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6882 | msg.rpc_resp = &data->res; |
| 6883 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6884 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6885 | } |
| 6886 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6887 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6888 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6889 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6890 | struct dentry *unused, struct inode *inode, |
| 6891 | const char *key, const void *buf, |
| 6892 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6893 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6894 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6895 | } |
| 6896 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6897 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6898 | struct dentry *unused, struct inode *inode, |
| 6899 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6900 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6901 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6902 | } |
| 6903 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6904 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6905 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6906 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6907 | } |
| 6908 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6909 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6910 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6911 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6912 | struct dentry *unused, struct inode *inode, |
| 6913 | const char *key, const void *buf, |
| 6914 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6915 | { |
| 6916 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6917 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6918 | |
| 6919 | return -EOPNOTSUPP; |
| 6920 | } |
| 6921 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6922 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6923 | struct dentry *unused, struct inode *inode, |
| 6924 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6925 | { |
| 6926 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6927 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6928 | return -EOPNOTSUPP; |
| 6929 | } |
| 6930 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6931 | static ssize_t |
| 6932 | 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] | 6933 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6934 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6935 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6936 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6937 | len = security_inode_listsecurity(inode, list, list_len); |
| 6938 | if (list_len && len > list_len) |
| 6939 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6940 | } |
| 6941 | return len; |
| 6942 | } |
| 6943 | |
| 6944 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6945 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6946 | .get = nfs4_xattr_get_nfs4_label, |
| 6947 | .set = nfs4_xattr_set_nfs4_label, |
| 6948 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6949 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6950 | #else |
| 6951 | |
| 6952 | static ssize_t |
| 6953 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6954 | { |
| 6955 | return 0; |
| 6956 | } |
| 6957 | |
| 6958 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6959 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6960 | /* |
| 6961 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6962 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6963 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6964 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6965 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6966 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6967 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6968 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6969 | return; |
| 6970 | |
| 6971 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6972 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6973 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6974 | fattr->nlink = 2; |
| 6975 | } |
| 6976 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6977 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6978 | const struct qstr *name, |
| 6979 | struct nfs4_fs_locations *fs_locations, |
| 6980 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6981 | { |
| 6982 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 6983 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6984 | struct nfs4_fs_locations_arg args = { |
| 6985 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6986 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6987 | .page = page, |
| 6988 | .bitmask = bitmask, |
| 6989 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6990 | struct nfs4_fs_locations_res res = { |
| 6991 | .fs_locations = fs_locations, |
| 6992 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6993 | struct rpc_message msg = { |
| 6994 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6995 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6996 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6997 | }; |
| 6998 | int status; |
| 6999 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7000 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7001 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7002 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7003 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7004 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7005 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7006 | * is not supported */ |
| 7007 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7008 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7009 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7010 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7011 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7012 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7013 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7014 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7015 | 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] | 7016 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7017 | return status; |
| 7018 | } |
| 7019 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7020 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7021 | const struct qstr *name, |
| 7022 | struct nfs4_fs_locations *fs_locations, |
| 7023 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7024 | { |
| 7025 | struct nfs4_exception exception = { }; |
| 7026 | int err; |
| 7027 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7028 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7029 | fs_locations, page); |
| 7030 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7031 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7032 | &exception); |
| 7033 | } while (exception.retry); |
| 7034 | return err; |
| 7035 | } |
| 7036 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7037 | /* |
| 7038 | * This operation also signals the server that this client is |
| 7039 | * performing migration recovery. The server can stop returning |
| 7040 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7041 | * appended to this compound to identify the client ID which is |
| 7042 | * performing recovery. |
| 7043 | */ |
| 7044 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7045 | struct nfs4_fs_locations *locations, |
| 7046 | struct page *page, struct rpc_cred *cred) |
| 7047 | { |
| 7048 | struct nfs_server *server = NFS_SERVER(inode); |
| 7049 | struct rpc_clnt *clnt = server->client; |
| 7050 | u32 bitmask[2] = { |
| 7051 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7052 | }; |
| 7053 | struct nfs4_fs_locations_arg args = { |
| 7054 | .clientid = server->nfs_client->cl_clientid, |
| 7055 | .fh = NFS_FH(inode), |
| 7056 | .page = page, |
| 7057 | .bitmask = bitmask, |
| 7058 | .migration = 1, /* skip LOOKUP */ |
| 7059 | .renew = 1, /* append RENEW */ |
| 7060 | }; |
| 7061 | struct nfs4_fs_locations_res res = { |
| 7062 | .fs_locations = locations, |
| 7063 | .migration = 1, |
| 7064 | .renew = 1, |
| 7065 | }; |
| 7066 | struct rpc_message msg = { |
| 7067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7068 | .rpc_argp = &args, |
| 7069 | .rpc_resp = &res, |
| 7070 | .rpc_cred = cred, |
| 7071 | }; |
| 7072 | unsigned long now = jiffies; |
| 7073 | int status; |
| 7074 | |
| 7075 | nfs_fattr_init(&locations->fattr); |
| 7076 | locations->server = server; |
| 7077 | locations->nlocations = 0; |
| 7078 | |
| 7079 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7080 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7081 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7082 | &args.seq_args, &res.seq_res); |
| 7083 | if (status) |
| 7084 | return status; |
| 7085 | |
| 7086 | renew_lease(server, now); |
| 7087 | return 0; |
| 7088 | } |
| 7089 | |
| 7090 | #ifdef CONFIG_NFS_V4_1 |
| 7091 | |
| 7092 | /* |
| 7093 | * This operation also signals the server that this client is |
| 7094 | * performing migration recovery. The server can stop asserting |
| 7095 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7096 | * performing this operation is identified in the SEQUENCE |
| 7097 | * operation in this compound. |
| 7098 | * |
| 7099 | * When the client supports GETATTR(fs_locations_info), it can |
| 7100 | * be plumbed in here. |
| 7101 | */ |
| 7102 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7103 | struct nfs4_fs_locations *locations, |
| 7104 | struct page *page, struct rpc_cred *cred) |
| 7105 | { |
| 7106 | struct nfs_server *server = NFS_SERVER(inode); |
| 7107 | struct rpc_clnt *clnt = server->client; |
| 7108 | u32 bitmask[2] = { |
| 7109 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7110 | }; |
| 7111 | struct nfs4_fs_locations_arg args = { |
| 7112 | .fh = NFS_FH(inode), |
| 7113 | .page = page, |
| 7114 | .bitmask = bitmask, |
| 7115 | .migration = 1, /* skip LOOKUP */ |
| 7116 | }; |
| 7117 | struct nfs4_fs_locations_res res = { |
| 7118 | .fs_locations = locations, |
| 7119 | .migration = 1, |
| 7120 | }; |
| 7121 | struct rpc_message msg = { |
| 7122 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7123 | .rpc_argp = &args, |
| 7124 | .rpc_resp = &res, |
| 7125 | .rpc_cred = cred, |
| 7126 | }; |
| 7127 | int status; |
| 7128 | |
| 7129 | nfs_fattr_init(&locations->fattr); |
| 7130 | locations->server = server; |
| 7131 | locations->nlocations = 0; |
| 7132 | |
| 7133 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7134 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7135 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7136 | &args.seq_args, &res.seq_res); |
| 7137 | if (status == NFS4_OK && |
| 7138 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7139 | status = -NFS4ERR_LEASE_MOVED; |
| 7140 | return status; |
| 7141 | } |
| 7142 | |
| 7143 | #endif /* CONFIG_NFS_V4_1 */ |
| 7144 | |
| 7145 | /** |
| 7146 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7147 | * @inode: inode on FSID that is migrating |
| 7148 | * @locations: result of query |
| 7149 | * @page: buffer |
| 7150 | * @cred: credential to use for this operation |
| 7151 | * |
| 7152 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7153 | * operation failed, or a negative errno if a local error occurred. |
| 7154 | * |
| 7155 | * On success, "locations" is filled in, but if the server has |
| 7156 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7157 | * asserted. |
| 7158 | * |
| 7159 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7160 | * from this client that require migration recovery. |
| 7161 | */ |
| 7162 | int nfs4_proc_get_locations(struct inode *inode, |
| 7163 | struct nfs4_fs_locations *locations, |
| 7164 | struct page *page, struct rpc_cred *cred) |
| 7165 | { |
| 7166 | struct nfs_server *server = NFS_SERVER(inode); |
| 7167 | struct nfs_client *clp = server->nfs_client; |
| 7168 | const struct nfs4_mig_recovery_ops *ops = |
| 7169 | clp->cl_mvops->mig_recovery_ops; |
| 7170 | struct nfs4_exception exception = { }; |
| 7171 | int status; |
| 7172 | |
| 7173 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7174 | (unsigned long long)server->fsid.major, |
| 7175 | (unsigned long long)server->fsid.minor, |
| 7176 | clp->cl_hostname); |
| 7177 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7178 | |
| 7179 | do { |
| 7180 | status = ops->get_locations(inode, locations, page, cred); |
| 7181 | if (status != -NFS4ERR_DELAY) |
| 7182 | break; |
| 7183 | nfs4_handle_exception(server, status, &exception); |
| 7184 | } while (exception.retry); |
| 7185 | return status; |
| 7186 | } |
| 7187 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7188 | /* |
| 7189 | * This operation also signals the server that this client is |
| 7190 | * performing "lease moved" recovery. The server can stop |
| 7191 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7192 | * is appended to this compound to identify the client ID which is |
| 7193 | * performing recovery. |
| 7194 | */ |
| 7195 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7196 | { |
| 7197 | struct nfs_server *server = NFS_SERVER(inode); |
| 7198 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7199 | struct rpc_clnt *clnt = server->client; |
| 7200 | struct nfs4_fsid_present_arg args = { |
| 7201 | .fh = NFS_FH(inode), |
| 7202 | .clientid = clp->cl_clientid, |
| 7203 | .renew = 1, /* append RENEW */ |
| 7204 | }; |
| 7205 | struct nfs4_fsid_present_res res = { |
| 7206 | .renew = 1, |
| 7207 | }; |
| 7208 | struct rpc_message msg = { |
| 7209 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7210 | .rpc_argp = &args, |
| 7211 | .rpc_resp = &res, |
| 7212 | .rpc_cred = cred, |
| 7213 | }; |
| 7214 | unsigned long now = jiffies; |
| 7215 | int status; |
| 7216 | |
| 7217 | res.fh = nfs_alloc_fhandle(); |
| 7218 | if (res.fh == NULL) |
| 7219 | return -ENOMEM; |
| 7220 | |
| 7221 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7222 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7223 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7224 | &args.seq_args, &res.seq_res); |
| 7225 | nfs_free_fhandle(res.fh); |
| 7226 | if (status) |
| 7227 | return status; |
| 7228 | |
| 7229 | do_renew_lease(clp, now); |
| 7230 | return 0; |
| 7231 | } |
| 7232 | |
| 7233 | #ifdef CONFIG_NFS_V4_1 |
| 7234 | |
| 7235 | /* |
| 7236 | * This operation also signals the server that this client is |
| 7237 | * performing "lease moved" recovery. The server can stop asserting |
| 7238 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7239 | * this operation is identified in the SEQUENCE operation in this |
| 7240 | * compound. |
| 7241 | */ |
| 7242 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7243 | { |
| 7244 | struct nfs_server *server = NFS_SERVER(inode); |
| 7245 | struct rpc_clnt *clnt = server->client; |
| 7246 | struct nfs4_fsid_present_arg args = { |
| 7247 | .fh = NFS_FH(inode), |
| 7248 | }; |
| 7249 | struct nfs4_fsid_present_res res = { |
| 7250 | }; |
| 7251 | struct rpc_message msg = { |
| 7252 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7253 | .rpc_argp = &args, |
| 7254 | .rpc_resp = &res, |
| 7255 | .rpc_cred = cred, |
| 7256 | }; |
| 7257 | int status; |
| 7258 | |
| 7259 | res.fh = nfs_alloc_fhandle(); |
| 7260 | if (res.fh == NULL) |
| 7261 | return -ENOMEM; |
| 7262 | |
| 7263 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7264 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7265 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7266 | &args.seq_args, &res.seq_res); |
| 7267 | nfs_free_fhandle(res.fh); |
| 7268 | if (status == NFS4_OK && |
| 7269 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7270 | status = -NFS4ERR_LEASE_MOVED; |
| 7271 | return status; |
| 7272 | } |
| 7273 | |
| 7274 | #endif /* CONFIG_NFS_V4_1 */ |
| 7275 | |
| 7276 | /** |
| 7277 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7278 | * @inode: inode on FSID to check |
| 7279 | * @cred: credential to use for this operation |
| 7280 | * |
| 7281 | * Server indicates whether the FSID is present, moved, or not |
| 7282 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7283 | * condition for this client ID. |
| 7284 | * |
| 7285 | * Returns NFS4_OK if the FSID is present on this server, |
| 7286 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7287 | * NFS4ERR code if some error occurred on the server, or a |
| 7288 | * negative errno if a local failure occurred. |
| 7289 | */ |
| 7290 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7291 | { |
| 7292 | struct nfs_server *server = NFS_SERVER(inode); |
| 7293 | struct nfs_client *clp = server->nfs_client; |
| 7294 | const struct nfs4_mig_recovery_ops *ops = |
| 7295 | clp->cl_mvops->mig_recovery_ops; |
| 7296 | struct nfs4_exception exception = { }; |
| 7297 | int status; |
| 7298 | |
| 7299 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7300 | (unsigned long long)server->fsid.major, |
| 7301 | (unsigned long long)server->fsid.minor, |
| 7302 | clp->cl_hostname); |
| 7303 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7304 | |
| 7305 | do { |
| 7306 | status = ops->fsid_present(inode, cred); |
| 7307 | if (status != -NFS4ERR_DELAY) |
| 7308 | break; |
| 7309 | nfs4_handle_exception(server, status, &exception); |
| 7310 | } while (exception.retry); |
| 7311 | return status; |
| 7312 | } |
| 7313 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7314 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7315 | * If 'use_integrity' is true and the state managment nfs_client |
| 7316 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7317 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7318 | * Considerations sections. Otherwise, just use the user cred with the |
| 7319 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7320 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7321 | 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] | 7322 | { |
| 7323 | int status; |
| 7324 | struct nfs4_secinfo_arg args = { |
| 7325 | .dir_fh = NFS_FH(dir), |
| 7326 | .name = name, |
| 7327 | }; |
| 7328 | struct nfs4_secinfo_res res = { |
| 7329 | .flavors = flavors, |
| 7330 | }; |
| 7331 | struct rpc_message msg = { |
| 7332 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7333 | .rpc_argp = &args, |
| 7334 | .rpc_resp = &res, |
| 7335 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7336 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7337 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7338 | |
| 7339 | if (use_integrity) { |
| 7340 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7341 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7342 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7343 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7344 | |
| 7345 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7346 | |
| 7347 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7348 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7349 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7350 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7351 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7352 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7353 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7354 | if (cred) |
| 7355 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7356 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7357 | return status; |
| 7358 | } |
| 7359 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7360 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7361 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7362 | { |
| 7363 | struct nfs4_exception exception = { }; |
| 7364 | int err; |
| 7365 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7366 | err = -NFS4ERR_WRONGSEC; |
| 7367 | |
| 7368 | /* try to use integrity protection with machine cred */ |
| 7369 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7370 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7371 | |
| 7372 | /* |
| 7373 | * if unable to use integrity protection, or SECINFO with |
| 7374 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7375 | * disallowed by spec, but exists in deployed servers) use |
| 7376 | * the current filesystem's rpc_client and the user cred. |
| 7377 | */ |
| 7378 | if (err == -NFS4ERR_WRONGSEC) |
| 7379 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7380 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7381 | trace_nfs4_secinfo(dir, name, err); |
| 7382 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7383 | &exception); |
| 7384 | } while (exception.retry); |
| 7385 | return err; |
| 7386 | } |
| 7387 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7388 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7389 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7390 | * Check the exchange flags returned by the server for invalid flags, having |
| 7391 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7392 | * DS flags set. |
| 7393 | */ |
| 7394 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7395 | { |
| 7396 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7397 | goto out_inval; |
| 7398 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7399 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7400 | goto out_inval; |
| 7401 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7402 | goto out_inval; |
| 7403 | return NFS_OK; |
| 7404 | out_inval: |
| 7405 | return -NFS4ERR_INVAL; |
| 7406 | } |
| 7407 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7408 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7409 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7410 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7411 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7412 | if (a->server_scope_sz != b->server_scope_sz) |
| 7413 | return false; |
| 7414 | 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] | 7415 | } |
| 7416 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7417 | static void |
| 7418 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7419 | { |
| 7420 | } |
| 7421 | |
| 7422 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7423 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7424 | }; |
| 7425 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7426 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7427 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7428 | * |
| 7429 | * The 4.1 client currently uses the same TCP connection for the |
| 7430 | * fore and backchannel. |
| 7431 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7432 | static |
| 7433 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7434 | struct rpc_xprt *xprt, |
| 7435 | struct nfs_client *clp, |
| 7436 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7437 | { |
| 7438 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7439 | struct nfs41_bind_conn_to_session_args args = { |
| 7440 | .client = clp, |
| 7441 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7442 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7443 | struct nfs41_bind_conn_to_session_res res; |
| 7444 | struct rpc_message msg = { |
| 7445 | .rpc_proc = |
| 7446 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7447 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7448 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7449 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7450 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7451 | struct rpc_task_setup task_setup_data = { |
| 7452 | .rpc_client = clnt, |
| 7453 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7454 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7455 | .rpc_message = &msg, |
| 7456 | .flags = RPC_TASK_TIMEOUT, |
| 7457 | }; |
| 7458 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7459 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7460 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7461 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7462 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7463 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7464 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7465 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7466 | args.dir = NFS4_CDFC4_FORE; |
| 7467 | |
| 7468 | task = rpc_run_task(&task_setup_data); |
| 7469 | if (!IS_ERR(task)) { |
| 7470 | status = task->tk_status; |
| 7471 | rpc_put_task(task); |
| 7472 | } else |
| 7473 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7474 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7475 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7476 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7477 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7478 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7479 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7480 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7481 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7482 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7483 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7484 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7485 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7486 | 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] | 7487 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7488 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7489 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7490 | } |
| 7491 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7492 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7493 | return status; |
| 7494 | } |
| 7495 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7496 | struct rpc_bind_conn_calldata { |
| 7497 | struct nfs_client *clp; |
| 7498 | struct rpc_cred *cred; |
| 7499 | }; |
| 7500 | |
| 7501 | static int |
| 7502 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7503 | struct rpc_xprt *xprt, |
| 7504 | void *calldata) |
| 7505 | { |
| 7506 | struct rpc_bind_conn_calldata *p = calldata; |
| 7507 | |
| 7508 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7509 | } |
| 7510 | |
| 7511 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7512 | { |
| 7513 | struct rpc_bind_conn_calldata data = { |
| 7514 | .clp = clp, |
| 7515 | .cred = cred, |
| 7516 | }; |
| 7517 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7518 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7519 | } |
| 7520 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7521 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7522 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7523 | * 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] | 7524 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7525 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7526 | .how = SP4_MACH_CRED, |
| 7527 | .enforce.u.words = { |
| 7528 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7529 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7530 | 1 << (OP_CREATE_SESSION - 32) | |
| 7531 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7532 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7533 | }, |
| 7534 | .allow.u.words = { |
| 7535 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7536 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7537 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7538 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7539 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7540 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7541 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7542 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7543 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7544 | 1 << (OP_FREE_STATEID - 32) | |
| 7545 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7546 | } |
| 7547 | }; |
| 7548 | |
| 7549 | /* |
| 7550 | * Select the state protection mode for client `clp' given the server results |
| 7551 | * from exchange_id in `sp'. |
| 7552 | * |
| 7553 | * Returns 0 on success, negative errno otherwise. |
| 7554 | */ |
| 7555 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7556 | struct nfs41_state_protection *sp) |
| 7557 | { |
| 7558 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7559 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7560 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7561 | 1 << (OP_CREATE_SESSION - 32) | |
| 7562 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7563 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7564 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7565 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7566 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7567 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7568 | |
| 7569 | if (sp->how == SP4_MACH_CRED) { |
| 7570 | /* Print state protect result */ |
| 7571 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7572 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7573 | if (test_bit(i, sp->enforce.u.longs)) |
| 7574 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7575 | if (test_bit(i, sp->allow.u.longs)) |
| 7576 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7577 | } |
| 7578 | |
| 7579 | /* make sure nothing is on enforce list that isn't supported */ |
| 7580 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7581 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7582 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7583 | ret = -EINVAL; |
| 7584 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7585 | } |
| 7586 | } |
| 7587 | |
| 7588 | /* |
| 7589 | * Minimal mode - state operations are allowed to use machine |
| 7590 | * credential. Note this already happens by default, so the |
| 7591 | * client doesn't have to do anything more than the negotiation. |
| 7592 | * |
| 7593 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7594 | * we're already using the machine cred for exchange_id |
| 7595 | * and will never use a different cred. |
| 7596 | */ |
| 7597 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7598 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7599 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7600 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7601 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7602 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7603 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7604 | } else { |
| 7605 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7606 | ret = -EINVAL; |
| 7607 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7608 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7609 | |
| 7610 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7611 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7612 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7613 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7614 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7615 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7616 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7617 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7618 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7619 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7620 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7621 | } |
| 7622 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7623 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7624 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7625 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7626 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7627 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7628 | |
| 7629 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7630 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7631 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7632 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7633 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7634 | |
| 7635 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7636 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7637 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7641 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7642 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7643 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7644 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7645 | out: |
| 7646 | clp->cl_sp4_flags = flags; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7647 | return 0; |
| 7648 | } |
| 7649 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7650 | struct nfs41_exchange_id_data { |
| 7651 | struct nfs41_exchange_id_res res; |
| 7652 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7653 | }; |
| 7654 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7655 | static void nfs4_exchange_id_release(void *data) |
| 7656 | { |
| 7657 | struct nfs41_exchange_id_data *cdata = |
| 7658 | (struct nfs41_exchange_id_data *)data; |
| 7659 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7660 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7661 | kfree(cdata->res.impl_id); |
| 7662 | kfree(cdata->res.server_scope); |
| 7663 | kfree(cdata->res.server_owner); |
| 7664 | kfree(cdata); |
| 7665 | } |
| 7666 | |
| 7667 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7668 | .rpc_release = nfs4_exchange_id_release, |
| 7669 | }; |
| 7670 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7671 | /* |
| 7672 | * _nfs4_proc_exchange_id() |
| 7673 | * |
| 7674 | * Wrapper for EXCHANGE_ID operation. |
| 7675 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7676 | static struct rpc_task * |
| 7677 | nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7678 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7679 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7680 | struct rpc_message msg = { |
| 7681 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7682 | .rpc_cred = cred, |
| 7683 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7684 | struct rpc_task_setup task_setup_data = { |
| 7685 | .rpc_client = clp->cl_rpcclient, |
| 7686 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7687 | .rpc_message = &msg, |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7688 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7689 | }; |
| 7690 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7691 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7692 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 7693 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7694 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7695 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7696 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7697 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7698 | if (!calldata) |
| 7699 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7700 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7701 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7702 | |
| 7703 | status = nfs4_init_uniform_client_string(clp); |
| 7704 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7705 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7706 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7707 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7708 | GFP_NOFS); |
| 7709 | status = -ENOMEM; |
| 7710 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7711 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7712 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7713 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7714 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7715 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7716 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7717 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7718 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7719 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7720 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7721 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7722 | switch (sp4_how) { |
| 7723 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7724 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7725 | break; |
| 7726 | |
| 7727 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7728 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7729 | break; |
| 7730 | |
| 7731 | default: |
| 7732 | /* unsupported! */ |
| 7733 | WARN_ON_ONCE(1); |
| 7734 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7735 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7736 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7737 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7738 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7739 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7740 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 7741 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7742 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7743 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7744 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7745 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7746 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7747 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7748 | #endif |
| 7749 | msg.rpc_argp = &calldata->args; |
| 7750 | msg.rpc_resp = &calldata->res; |
| 7751 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7752 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7753 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7754 | |
| 7755 | out_impl_id: |
| 7756 | kfree(calldata->res.impl_id); |
| 7757 | out_server_scope: |
| 7758 | kfree(calldata->res.server_scope); |
| 7759 | out_server_owner: |
| 7760 | kfree(calldata->res.server_owner); |
| 7761 | out_calldata: |
| 7762 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7763 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7764 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7765 | return ERR_PTR(status); |
| 7766 | } |
| 7767 | |
| 7768 | /* |
| 7769 | * _nfs4_proc_exchange_id() |
| 7770 | * |
| 7771 | * Wrapper for EXCHANGE_ID operation. |
| 7772 | */ |
| 7773 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7774 | u32 sp4_how) |
| 7775 | { |
| 7776 | struct rpc_task *task; |
| 7777 | struct nfs41_exchange_id_args *argp; |
| 7778 | struct nfs41_exchange_id_res *resp; |
| 7779 | int status; |
| 7780 | |
| 7781 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 7782 | if (IS_ERR(task)) |
| 7783 | return PTR_ERR(task); |
| 7784 | |
| 7785 | argp = task->tk_msg.rpc_argp; |
| 7786 | resp = task->tk_msg.rpc_resp; |
| 7787 | status = task->tk_status; |
| 7788 | if (status != 0) |
| 7789 | goto out; |
| 7790 | |
| 7791 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 7792 | if (status != 0) |
| 7793 | goto out; |
| 7794 | |
| 7795 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 7796 | if (status != 0) |
| 7797 | goto out; |
| 7798 | |
| 7799 | clp->cl_clientid = resp->clientid; |
| 7800 | clp->cl_exchange_flags = resp->flags; |
| 7801 | clp->cl_seqid = resp->seqid; |
| 7802 | /* Client ID is not confirmed */ |
| 7803 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 7804 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7805 | &clp->cl_session->session_state); |
| 7806 | |
| 7807 | if (clp->cl_serverscope != NULL && |
| 7808 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7809 | resp->server_scope)) { |
| 7810 | dprintk("%s: server_scope mismatch detected\n", |
| 7811 | __func__); |
| 7812 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7813 | } |
| 7814 | |
| 7815 | swap(clp->cl_serverowner, resp->server_owner); |
| 7816 | swap(clp->cl_serverscope, resp->server_scope); |
| 7817 | swap(clp->cl_implid, resp->impl_id); |
| 7818 | |
| 7819 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7820 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 7821 | sizeof(clp->cl_confirm.data)); |
| 7822 | out: |
| 7823 | trace_nfs4_exchange_id(clp, status); |
| 7824 | rpc_put_task(task); |
| 7825 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7826 | } |
| 7827 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7828 | /* |
| 7829 | * nfs4_proc_exchange_id() |
| 7830 | * |
| 7831 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7832 | * |
| 7833 | * Since the clientid has expired, all compounds using sessions |
| 7834 | * associated with the stale clientid will be returning |
| 7835 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7836 | * be in some phase of session reset. |
| 7837 | * |
| 7838 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7839 | */ |
| 7840 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7841 | { |
| 7842 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7843 | int status; |
| 7844 | |
| 7845 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7846 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7847 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7848 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7849 | if (!status) |
| 7850 | return 0; |
| 7851 | } |
| 7852 | |
| 7853 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7854 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7855 | } |
| 7856 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7857 | /** |
| 7858 | * nfs4_test_session_trunk |
| 7859 | * |
| 7860 | * This is an add_xprt_test() test function called from |
| 7861 | * rpc_clnt_setup_test_and_add_xprt. |
| 7862 | * |
| 7863 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7864 | * and is dereferrenced in nfs4_exchange_id_release |
| 7865 | * |
| 7866 | * Upon success, add the new transport to the rpc_clnt |
| 7867 | * |
| 7868 | * @clnt: struct rpc_clnt to get new transport |
| 7869 | * @xprt: the rpc_xprt to test |
| 7870 | * @data: call data for _nfs4_proc_exchange_id. |
| 7871 | */ |
| 7872 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7873 | void *data) |
| 7874 | { |
| 7875 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7876 | struct rpc_task *task; |
| 7877 | int status; |
| 7878 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7879 | u32 sp4_how; |
| 7880 | |
| 7881 | dprintk("--> %s try %s\n", __func__, |
| 7882 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7883 | |
| 7884 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7885 | |
| 7886 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7887 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7888 | if (IS_ERR(task)) |
| 7889 | return PTR_ERR(task); |
| 7890 | |
| 7891 | status = task->tk_status; |
| 7892 | if (status == 0) |
| 7893 | status = nfs4_detect_session_trunking(adata->clp, |
| 7894 | task->tk_msg.rpc_resp, xprt); |
| 7895 | |
| 7896 | rpc_put_task(task); |
| 7897 | return status; |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7898 | } |
| 7899 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7900 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7901 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7902 | struct rpc_cred *cred) |
| 7903 | { |
| 7904 | struct rpc_message msg = { |
| 7905 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7906 | .rpc_argp = clp, |
| 7907 | .rpc_cred = cred, |
| 7908 | }; |
| 7909 | int status; |
| 7910 | |
| 7911 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7912 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7913 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7914 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7915 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7916 | return status; |
| 7917 | } |
| 7918 | |
| 7919 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7920 | struct rpc_cred *cred) |
| 7921 | { |
| 7922 | unsigned int loop; |
| 7923 | int ret; |
| 7924 | |
| 7925 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7926 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7927 | switch (ret) { |
| 7928 | case -NFS4ERR_DELAY: |
| 7929 | case -NFS4ERR_CLIENTID_BUSY: |
| 7930 | ssleep(1); |
| 7931 | break; |
| 7932 | default: |
| 7933 | return ret; |
| 7934 | } |
| 7935 | } |
| 7936 | return 0; |
| 7937 | } |
| 7938 | |
| 7939 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7940 | { |
| 7941 | struct rpc_cred *cred; |
| 7942 | int ret = 0; |
| 7943 | |
| 7944 | if (clp->cl_mvops->minor_version < 1) |
| 7945 | goto out; |
| 7946 | if (clp->cl_exchange_flags == 0) |
| 7947 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7948 | if (clp->cl_preserve_clid) |
| 7949 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7950 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7951 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7952 | if (cred) |
| 7953 | put_rpccred(cred); |
| 7954 | switch (ret) { |
| 7955 | case 0: |
| 7956 | case -NFS4ERR_STALE_CLIENTID: |
| 7957 | clp->cl_exchange_flags = 0; |
| 7958 | } |
| 7959 | out: |
| 7960 | return ret; |
| 7961 | } |
| 7962 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7963 | struct nfs4_get_lease_time_data { |
| 7964 | struct nfs4_get_lease_time_args *args; |
| 7965 | struct nfs4_get_lease_time_res *res; |
| 7966 | struct nfs_client *clp; |
| 7967 | }; |
| 7968 | |
| 7969 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7970 | void *calldata) |
| 7971 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7972 | struct nfs4_get_lease_time_data *data = |
| 7973 | (struct nfs4_get_lease_time_data *)calldata; |
| 7974 | |
| 7975 | dprintk("--> %s\n", __func__); |
| 7976 | /* just setup sequence, do not trigger session recovery |
| 7977 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7978 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7979 | &data->args->la_seq_args, |
| 7980 | &data->res->lr_seq_res, |
| 7981 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7982 | dprintk("<-- %s\n", __func__); |
| 7983 | } |
| 7984 | |
| 7985 | /* |
| 7986 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7987 | * from sequence operation or clientid errors. |
| 7988 | */ |
| 7989 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7990 | { |
| 7991 | struct nfs4_get_lease_time_data *data = |
| 7992 | (struct nfs4_get_lease_time_data *)calldata; |
| 7993 | |
| 7994 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7995 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7996 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7997 | switch (task->tk_status) { |
| 7998 | case -NFS4ERR_DELAY: |
| 7999 | case -NFS4ERR_GRACE: |
| 8000 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8001 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8002 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8003 | /* fall through */ |
| 8004 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8005 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8006 | return; |
| 8007 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8008 | dprintk("<-- %s\n", __func__); |
| 8009 | } |
| 8010 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8011 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8012 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8013 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8014 | }; |
| 8015 | |
| 8016 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8017 | { |
| 8018 | struct rpc_task *task; |
| 8019 | struct nfs4_get_lease_time_args args; |
| 8020 | struct nfs4_get_lease_time_res res = { |
| 8021 | .lr_fsinfo = fsinfo, |
| 8022 | }; |
| 8023 | struct nfs4_get_lease_time_data data = { |
| 8024 | .args = &args, |
| 8025 | .res = &res, |
| 8026 | .clp = clp, |
| 8027 | }; |
| 8028 | struct rpc_message msg = { |
| 8029 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8030 | .rpc_argp = &args, |
| 8031 | .rpc_resp = &res, |
| 8032 | }; |
| 8033 | struct rpc_task_setup task_setup = { |
| 8034 | .rpc_client = clp->cl_rpcclient, |
| 8035 | .rpc_message = &msg, |
| 8036 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8037 | .callback_data = &data, |
| 8038 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8039 | }; |
| 8040 | int status; |
| 8041 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8042 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8043 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8044 | task = rpc_run_task(&task_setup); |
| 8045 | |
| 8046 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8047 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8048 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8049 | status = task->tk_status; |
| 8050 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8051 | return status; |
| 8052 | } |
| 8053 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8054 | /* |
| 8055 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8056 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8057 | * use them. |
| 8058 | * |
| 8059 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8060 | * always set csa_cachethis to FALSE because the current implementation |
| 8061 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8062 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8063 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8064 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8065 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8066 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8067 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8068 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8069 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8070 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8071 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8072 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8073 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8074 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8075 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8076 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8077 | |
| 8078 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8079 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8080 | __func__, |
| 8081 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8082 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8083 | |
| 8084 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8085 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8086 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8087 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8088 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8089 | 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] | 8090 | |
| 8091 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8092 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8093 | __func__, |
| 8094 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8095 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8096 | args->bc_attrs.max_reqs); |
| 8097 | } |
| 8098 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8099 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8100 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8101 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8102 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8103 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8104 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8105 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8106 | return -EINVAL; |
| 8107 | /* |
| 8108 | * Our requested max_ops is the minimum we need; we're not |
| 8109 | * prepared to break up compounds into smaller pieces than that. |
| 8110 | * So, no point even trying to continue if the server won't |
| 8111 | * cooperate: |
| 8112 | */ |
| 8113 | if (rcvd->max_ops < sent->max_ops) |
| 8114 | return -EINVAL; |
| 8115 | if (rcvd->max_reqs == 0) |
| 8116 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8117 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8118 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8119 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8120 | } |
| 8121 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8122 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8123 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8124 | { |
| 8125 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8126 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8127 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8128 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8129 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8130 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8131 | return -EINVAL; |
| 8132 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8133 | return -EINVAL; |
| 8134 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8135 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8136 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8137 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8138 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8139 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8140 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8141 | return 0; |
| 8142 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8143 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8144 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8145 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8146 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8147 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8148 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8149 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8150 | if (ret) |
| 8151 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8152 | return nfs4_verify_back_channel_attrs(args, res); |
| 8153 | } |
| 8154 | |
| 8155 | static void nfs4_update_session(struct nfs4_session *session, |
| 8156 | struct nfs41_create_session_res *res) |
| 8157 | { |
| 8158 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8159 | /* Mark client id and session as being confirmed */ |
| 8160 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8161 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8162 | session->flags = res->flags; |
| 8163 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8164 | if (res->flags & SESSION4_BACK_CHAN) |
| 8165 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8166 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8167 | } |
| 8168 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8169 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8170 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8171 | { |
| 8172 | struct nfs4_session *session = clp->cl_session; |
| 8173 | struct nfs41_create_session_args args = { |
| 8174 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8175 | .clientid = clp->cl_clientid, |
| 8176 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8177 | .cb_program = NFS4_CALLBACK, |
| 8178 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8179 | struct nfs41_create_session_res res; |
| 8180 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8181 | struct rpc_message msg = { |
| 8182 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8183 | .rpc_argp = &args, |
| 8184 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8185 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8186 | }; |
| 8187 | int status; |
| 8188 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8189 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8190 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8191 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8192 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8193 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8194 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8195 | switch (status) { |
| 8196 | case -NFS4ERR_STALE_CLIENTID: |
| 8197 | case -NFS4ERR_DELAY: |
| 8198 | case -ETIMEDOUT: |
| 8199 | case -EACCES: |
| 8200 | case -EAGAIN: |
| 8201 | goto out; |
| 8202 | }; |
| 8203 | |
| 8204 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8205 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8206 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8207 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8208 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8209 | if (status) |
| 8210 | goto out; |
| 8211 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8212 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8213 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8214 | return status; |
| 8215 | } |
| 8216 | |
| 8217 | /* |
| 8218 | * Issues a CREATE_SESSION operation to the server. |
| 8219 | * It is the responsibility of the caller to verify the session is |
| 8220 | * expired before calling this routine. |
| 8221 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8222 | 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] | 8223 | { |
| 8224 | int status; |
| 8225 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8226 | struct nfs4_session *session = clp->cl_session; |
| 8227 | |
| 8228 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8229 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8230 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8231 | if (status) |
| 8232 | goto out; |
| 8233 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8234 | /* Init or reset the session slot tables */ |
| 8235 | status = nfs4_setup_session_slot_tables(session); |
| 8236 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8237 | if (status) |
| 8238 | goto out; |
| 8239 | |
| 8240 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8241 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8242 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8243 | out: |
| 8244 | dprintk("<-- %s\n", __func__); |
| 8245 | return status; |
| 8246 | } |
| 8247 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8248 | /* |
| 8249 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8250 | * The caller must serialize access to this routine. |
| 8251 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8252 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8253 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8254 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8255 | struct rpc_message msg = { |
| 8256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8257 | .rpc_argp = session, |
| 8258 | .rpc_cred = cred, |
| 8259 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8260 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8261 | |
| 8262 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8263 | |
| 8264 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8265 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8266 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8267 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8268 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8269 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8270 | |
| 8271 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8272 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8273 | "Session has been destroyed regardless...\n", status); |
| 8274 | |
| 8275 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8276 | return status; |
| 8277 | } |
| 8278 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8279 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8280 | * Renew the cl_session lease. |
| 8281 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8282 | struct nfs4_sequence_data { |
| 8283 | struct nfs_client *clp; |
| 8284 | struct nfs4_sequence_args args; |
| 8285 | struct nfs4_sequence_res res; |
| 8286 | }; |
| 8287 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8288 | static void nfs41_sequence_release(void *data) |
| 8289 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8290 | struct nfs4_sequence_data *calldata = data; |
| 8291 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8292 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8293 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8294 | nfs4_schedule_state_renewal(clp); |
| 8295 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8296 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8297 | } |
| 8298 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8299 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8300 | { |
| 8301 | switch(task->tk_status) { |
| 8302 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8303 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8304 | return -EAGAIN; |
| 8305 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8306 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8307 | } |
| 8308 | return 0; |
| 8309 | } |
| 8310 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8311 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8312 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8313 | struct nfs4_sequence_data *calldata = data; |
| 8314 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8315 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8316 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8317 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8318 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8319 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8320 | if (task->tk_status < 0) { |
| 8321 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8322 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8323 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8324 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8325 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8326 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8327 | return; |
| 8328 | } |
| 8329 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8330 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8331 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8332 | dprintk("<-- %s\n", __func__); |
| 8333 | } |
| 8334 | |
| 8335 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8336 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8337 | struct nfs4_sequence_data *calldata = data; |
| 8338 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8339 | struct nfs4_sequence_args *args; |
| 8340 | struct nfs4_sequence_res *res; |
| 8341 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8342 | args = task->tk_msg.rpc_argp; |
| 8343 | res = task->tk_msg.rpc_resp; |
| 8344 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8345 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8346 | } |
| 8347 | |
| 8348 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8349 | .rpc_call_done = nfs41_sequence_call_done, |
| 8350 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8351 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8352 | }; |
| 8353 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8354 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8355 | struct rpc_cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8356 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8357 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8358 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8359 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8360 | struct rpc_message msg = { |
| 8361 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8362 | .rpc_cred = cred, |
| 8363 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8364 | struct rpc_task_setup task_setup_data = { |
| 8365 | .rpc_client = clp->cl_rpcclient, |
| 8366 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8367 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8368 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8369 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8370 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8371 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8372 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8373 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8374 | goto out_err; |
| 8375 | |
| 8376 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8377 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8378 | if (calldata == NULL) |
| 8379 | goto out_put_clp; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8380 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8381 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8382 | if (is_privileged) |
| 8383 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8384 | msg.rpc_argp = &calldata->args; |
| 8385 | msg.rpc_resp = &calldata->res; |
| 8386 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8387 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8388 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8389 | ret = rpc_run_task(&task_setup_data); |
| 8390 | if (IS_ERR(ret)) |
| 8391 | goto out_err; |
| 8392 | return ret; |
| 8393 | out_put_clp: |
| 8394 | nfs_put_client(clp); |
| 8395 | out_err: |
| 8396 | nfs41_release_slot(slot); |
| 8397 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8398 | } |
| 8399 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8400 | 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] | 8401 | { |
| 8402 | struct rpc_task *task; |
| 8403 | int ret = 0; |
| 8404 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8405 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8406 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8407 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8408 | if (IS_ERR(task)) |
| 8409 | ret = PTR_ERR(task); |
| 8410 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8411 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8412 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8413 | return ret; |
| 8414 | } |
| 8415 | |
| 8416 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8417 | { |
| 8418 | struct rpc_task *task; |
| 8419 | int ret; |
| 8420 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8421 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8422 | if (IS_ERR(task)) { |
| 8423 | ret = PTR_ERR(task); |
| 8424 | goto out; |
| 8425 | } |
| 8426 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8427 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8428 | ret = task->tk_status; |
| 8429 | rpc_put_task(task); |
| 8430 | out: |
| 8431 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8432 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8433 | } |
| 8434 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8435 | struct nfs4_reclaim_complete_data { |
| 8436 | struct nfs_client *clp; |
| 8437 | struct nfs41_reclaim_complete_args arg; |
| 8438 | struct nfs41_reclaim_complete_res res; |
| 8439 | }; |
| 8440 | |
| 8441 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8442 | { |
| 8443 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8444 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8445 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8446 | &calldata->arg.seq_args, |
| 8447 | &calldata->res.seq_res, |
| 8448 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8449 | } |
| 8450 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8451 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8452 | { |
| 8453 | switch(task->tk_status) { |
| 8454 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8455 | wake_up_all(&clp->cl_lock_waitq); |
| 8456 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8457 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8458 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8459 | break; |
| 8460 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8461 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8462 | /* fall through */ |
| 8463 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8464 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8465 | case -NFS4ERR_BADSESSION: |
| 8466 | case -NFS4ERR_DEADSESSION: |
| 8467 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8468 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8469 | task->tk_status); |
| 8470 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8471 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8472 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8473 | } |
| 8474 | return 0; |
| 8475 | } |
| 8476 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8477 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8478 | { |
| 8479 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8480 | struct nfs_client *clp = calldata->clp; |
| 8481 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8482 | |
| 8483 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8484 | if (!nfs41_sequence_done(task, res)) |
| 8485 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8486 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8487 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8488 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8489 | rpc_restart_call_prepare(task); |
| 8490 | return; |
| 8491 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8492 | dprintk("<-- %s\n", __func__); |
| 8493 | } |
| 8494 | |
| 8495 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8496 | { |
| 8497 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8498 | |
| 8499 | kfree(calldata); |
| 8500 | } |
| 8501 | |
| 8502 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8503 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8504 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8505 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8506 | }; |
| 8507 | |
| 8508 | /* |
| 8509 | * Issue a global reclaim complete. |
| 8510 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8511 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8512 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8513 | { |
| 8514 | struct nfs4_reclaim_complete_data *calldata; |
| 8515 | struct rpc_task *task; |
| 8516 | struct rpc_message msg = { |
| 8517 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8518 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8519 | }; |
| 8520 | struct rpc_task_setup task_setup_data = { |
| 8521 | .rpc_client = clp->cl_rpcclient, |
| 8522 | .rpc_message = &msg, |
| 8523 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8524 | .flags = RPC_TASK_ASYNC, |
| 8525 | }; |
| 8526 | int status = -ENOMEM; |
| 8527 | |
| 8528 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8529 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8530 | if (calldata == NULL) |
| 8531 | goto out; |
| 8532 | calldata->clp = clp; |
| 8533 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8534 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8535 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8536 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8537 | msg.rpc_argp = &calldata->arg; |
| 8538 | msg.rpc_resp = &calldata->res; |
| 8539 | task_setup_data.callback_data = calldata; |
| 8540 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8541 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8542 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8543 | goto out; |
| 8544 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8545 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8546 | if (status == 0) |
| 8547 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8548 | rpc_put_task(task); |
| 8549 | out: |
| 8550 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8551 | return status; |
| 8552 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8553 | |
| 8554 | static void |
| 8555 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8556 | { |
| 8557 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8558 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8559 | |
| 8560 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8561 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8562 | &lgp->res.seq_res, task); |
| 8563 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8564 | } |
| 8565 | |
| 8566 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8567 | { |
| 8568 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8569 | |
| 8570 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8571 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8572 | dprintk("<-- %s\n", __func__); |
| 8573 | } |
| 8574 | |
| 8575 | static int |
| 8576 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8577 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8578 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8579 | struct inode *inode = lgp->args.inode; |
| 8580 | struct nfs_server *server = NFS_SERVER(inode); |
| 8581 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8582 | int nfs4err = task->tk_status; |
| 8583 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8584 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8585 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8586 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8587 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8588 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8589 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8590 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8591 | |
| 8592 | /* |
| 8593 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8594 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8595 | * retry go inband. |
| 8596 | */ |
| 8597 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8598 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8599 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8600 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8601 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8602 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8603 | */ |
| 8604 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8605 | status = -EOVERFLOW; |
| 8606 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8607 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8608 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8609 | * (or clients) writing to the same RAID stripe except when |
| 8610 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8611 | * |
| 8612 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8613 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8614 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8615 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8616 | if (lgp->args.minlength == 0) { |
| 8617 | status = -EOVERFLOW; |
| 8618 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8619 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8620 | status = -EBUSY; |
| 8621 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8622 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8623 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8624 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8625 | case -NFS4ERR_DELEG_REVOKED: |
| 8626 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8627 | case -NFS4ERR_EXPIRED: |
| 8628 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8629 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8630 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8631 | lo = NFS_I(inode)->layout; |
| 8632 | /* If the open stateid was bad, then recover it. */ |
| 8633 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 8634 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8635 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8636 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8637 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8638 | break; |
| 8639 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8640 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8641 | /* |
| 8642 | * Mark the bad layout state as invalid, then retry |
| 8643 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8644 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8645 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8646 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8647 | pnfs_free_lseg_list(&head); |
| 8648 | status = -EAGAIN; |
| 8649 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8650 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8651 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8652 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8653 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8654 | if (!status) { |
| 8655 | if (exception->retry) |
| 8656 | status = -EAGAIN; |
| 8657 | else |
| 8658 | status = err; |
| 8659 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8660 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8661 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8662 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8663 | } |
| 8664 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8665 | static size_t max_response_pages(struct nfs_server *server) |
| 8666 | { |
| 8667 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8668 | return nfs_page_array_len(0, max_resp_sz); |
| 8669 | } |
| 8670 | |
| 8671 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8672 | { |
| 8673 | int i; |
| 8674 | |
| 8675 | if (!pages) |
| 8676 | return; |
| 8677 | |
| 8678 | for (i = 0; i < size; i++) { |
| 8679 | if (!pages[i]) |
| 8680 | break; |
| 8681 | __free_page(pages[i]); |
| 8682 | } |
| 8683 | kfree(pages); |
| 8684 | } |
| 8685 | |
| 8686 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8687 | { |
| 8688 | struct page **pages; |
| 8689 | int i; |
| 8690 | |
| 8691 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8692 | if (!pages) { |
| 8693 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8694 | return NULL; |
| 8695 | } |
| 8696 | |
| 8697 | for (i = 0; i < size; i++) { |
| 8698 | pages[i] = alloc_page(gfp_flags); |
| 8699 | if (!pages[i]) { |
| 8700 | dprintk("%s: failed to allocate page\n", __func__); |
| 8701 | nfs4_free_pages(pages, size); |
| 8702 | return NULL; |
| 8703 | } |
| 8704 | } |
| 8705 | |
| 8706 | return pages; |
| 8707 | } |
| 8708 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8709 | static void nfs4_layoutget_release(void *calldata) |
| 8710 | { |
| 8711 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8712 | struct inode *inode = lgp->args.inode; |
| 8713 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8714 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8715 | |
| 8716 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8717 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8718 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8719 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8720 | put_nfs_open_context(lgp->args.ctx); |
| 8721 | kfree(calldata); |
| 8722 | dprintk("<-- %s\n", __func__); |
| 8723 | } |
| 8724 | |
| 8725 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8726 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8727 | .rpc_call_done = nfs4_layoutget_done, |
| 8728 | .rpc_release = nfs4_layoutget_release, |
| 8729 | }; |
| 8730 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8731 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8732 | 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] | 8733 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8734 | struct inode *inode = lgp->args.inode; |
| 8735 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8736 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8737 | struct rpc_task *task; |
| 8738 | struct rpc_message msg = { |
| 8739 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8740 | .rpc_argp = &lgp->args, |
| 8741 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8742 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8743 | }; |
| 8744 | struct rpc_task_setup task_setup_data = { |
| 8745 | .rpc_client = server->client, |
| 8746 | .rpc_message = &msg, |
| 8747 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8748 | .callback_data = lgp, |
| 8749 | .flags = RPC_TASK_ASYNC, |
| 8750 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8751 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8752 | struct nfs4_exception exception = { |
| 8753 | .inode = inode, |
| 8754 | .timeout = *timeout, |
| 8755 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8756 | int status = 0; |
| 8757 | |
| 8758 | dprintk("--> %s\n", __func__); |
| 8759 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8760 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8761 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8762 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8763 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8764 | if (!lgp->args.layout.pages) { |
| 8765 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8766 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8767 | } |
| 8768 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8769 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8770 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8771 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8772 | 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] | 8773 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8774 | task = rpc_run_task(&task_setup_data); |
| 8775 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8776 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8777 | status = rpc_wait_for_completion_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8778 | if (status == 0) { |
| 8779 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8780 | *timeout = exception.timeout; |
| 8781 | } |
| 8782 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8783 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8784 | &lgp->args.range, |
| 8785 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8786 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8787 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8788 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8789 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8790 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8791 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8792 | rpc_put_task(task); |
| 8793 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8794 | if (status) |
| 8795 | return ERR_PTR(status); |
| 8796 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8797 | } |
| 8798 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8799 | static void |
| 8800 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8801 | { |
| 8802 | struct nfs4_layoutreturn *lrp = calldata; |
| 8803 | |
| 8804 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8805 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8806 | &lrp->args.seq_args, |
| 8807 | &lrp->res.seq_res, |
| 8808 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8809 | } |
| 8810 | |
| 8811 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8812 | { |
| 8813 | struct nfs4_layoutreturn *lrp = calldata; |
| 8814 | struct nfs_server *server; |
| 8815 | |
| 8816 | dprintk("--> %s\n", __func__); |
| 8817 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8818 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8819 | return; |
| 8820 | |
| 8821 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8822 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8823 | case -NFS4ERR_OLD_STATEID: |
| 8824 | if (nfs4_refresh_layout_stateid(&lrp->args.stateid, |
| 8825 | lrp->args.inode)) |
| 8826 | goto out_restart; |
| 8827 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8828 | default: |
| 8829 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8830 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8831 | case 0: |
| 8832 | break; |
| 8833 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8834 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8835 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8836 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8837 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8838 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8839 | return; |
| 8840 | out_restart: |
| 8841 | task->tk_status = 0; |
| 8842 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 8843 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8844 | } |
| 8845 | |
| 8846 | static void nfs4_layoutreturn_release(void *calldata) |
| 8847 | { |
| 8848 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8849 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8850 | |
| 8851 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8852 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8853 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8854 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8855 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8856 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8857 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8858 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8859 | kfree(calldata); |
| 8860 | dprintk("<-- %s\n", __func__); |
| 8861 | } |
| 8862 | |
| 8863 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8864 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8865 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8866 | .rpc_release = nfs4_layoutreturn_release, |
| 8867 | }; |
| 8868 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8869 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8870 | { |
| 8871 | struct rpc_task *task; |
| 8872 | struct rpc_message msg = { |
| 8873 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8874 | .rpc_argp = &lrp->args, |
| 8875 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8876 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8877 | }; |
| 8878 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8879 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8880 | .rpc_message = &msg, |
| 8881 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8882 | .callback_data = lrp, |
| 8883 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8884 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8885 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8886 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8887 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8888 | &task_setup_data.rpc_client, &msg); |
| 8889 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8890 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8891 | if (!sync) { |
| 8892 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8893 | if (!lrp->inode) { |
| 8894 | nfs4_layoutreturn_release(lrp); |
| 8895 | return -EAGAIN; |
| 8896 | } |
| 8897 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8898 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8899 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8900 | task = rpc_run_task(&task_setup_data); |
| 8901 | if (IS_ERR(task)) |
| 8902 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8903 | if (sync) |
| 8904 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8905 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8906 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8907 | rpc_put_task(task); |
| 8908 | return status; |
| 8909 | } |
| 8910 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8911 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8912 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8913 | struct pnfs_device *pdev, |
| 8914 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8915 | { |
| 8916 | struct nfs4_getdeviceinfo_args args = { |
| 8917 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8918 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8919 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8920 | }; |
| 8921 | struct nfs4_getdeviceinfo_res res = { |
| 8922 | .pdev = pdev, |
| 8923 | }; |
| 8924 | struct rpc_message msg = { |
| 8925 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8926 | .rpc_argp = &args, |
| 8927 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8928 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8929 | }; |
| 8930 | int status; |
| 8931 | |
| 8932 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8933 | 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] | 8934 | if (res.notification & ~args.notify_types) |
| 8935 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8936 | if (res.notification != args.notify_types) |
| 8937 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8938 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8939 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8940 | |
| 8941 | return status; |
| 8942 | } |
| 8943 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8944 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8945 | struct pnfs_device *pdev, |
| 8946 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8947 | { |
| 8948 | struct nfs4_exception exception = { }; |
| 8949 | int err; |
| 8950 | |
| 8951 | do { |
| 8952 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8953 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8954 | &exception); |
| 8955 | } while (exception.retry); |
| 8956 | return err; |
| 8957 | } |
| 8958 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8959 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8960 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8961 | { |
| 8962 | struct nfs4_layoutcommit_data *data = calldata; |
| 8963 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8964 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8965 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8966 | &data->args.seq_args, |
| 8967 | &data->res.seq_res, |
| 8968 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8969 | } |
| 8970 | |
| 8971 | static void |
| 8972 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8973 | { |
| 8974 | struct nfs4_layoutcommit_data *data = calldata; |
| 8975 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8976 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8977 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8978 | return; |
| 8979 | |
| 8980 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8981 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8982 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8983 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8984 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8985 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8986 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8987 | break; |
| 8988 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8989 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8990 | rpc_restart_call_prepare(task); |
| 8991 | return; |
| 8992 | } |
| 8993 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8994 | } |
| 8995 | |
| 8996 | static void nfs4_layoutcommit_release(void *calldata) |
| 8997 | { |
| 8998 | struct nfs4_layoutcommit_data *data = calldata; |
| 8999 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9000 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9001 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9002 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9003 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9004 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9005 | kfree(data); |
| 9006 | } |
| 9007 | |
| 9008 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9009 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9010 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9011 | .rpc_release = nfs4_layoutcommit_release, |
| 9012 | }; |
| 9013 | |
| 9014 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9015 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9016 | { |
| 9017 | struct rpc_message msg = { |
| 9018 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9019 | .rpc_argp = &data->args, |
| 9020 | .rpc_resp = &data->res, |
| 9021 | .rpc_cred = data->cred, |
| 9022 | }; |
| 9023 | struct rpc_task_setup task_setup_data = { |
| 9024 | .task = &data->task, |
| 9025 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9026 | .rpc_message = &msg, |
| 9027 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9028 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9029 | }; |
| 9030 | struct rpc_task *task; |
| 9031 | int status = 0; |
| 9032 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9033 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9034 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9035 | data->args.lastbytewritten, |
| 9036 | data->args.inode->i_ino); |
| 9037 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9038 | if (!sync) { |
| 9039 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9040 | if (data->inode == NULL) { |
| 9041 | nfs4_layoutcommit_release(data); |
| 9042 | return -EAGAIN; |
| 9043 | } |
| 9044 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9045 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9046 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9047 | task = rpc_run_task(&task_setup_data); |
| 9048 | if (IS_ERR(task)) |
| 9049 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9050 | if (sync) |
| 9051 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9052 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9053 | dprintk("%s: status %d\n", __func__, status); |
| 9054 | rpc_put_task(task); |
| 9055 | return status; |
| 9056 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9057 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9058 | /** |
| 9059 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9060 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9061 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9062 | static int |
| 9063 | _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] | 9064 | struct nfs_fsinfo *info, |
| 9065 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9066 | { |
| 9067 | struct nfs41_secinfo_no_name_args args = { |
| 9068 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9069 | }; |
| 9070 | struct nfs4_secinfo_res res = { |
| 9071 | .flavors = flavors, |
| 9072 | }; |
| 9073 | struct rpc_message msg = { |
| 9074 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9075 | .rpc_argp = &args, |
| 9076 | .rpc_resp = &res, |
| 9077 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9078 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9079 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9080 | int status; |
| 9081 | |
| 9082 | if (use_integrity) { |
| 9083 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9084 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9085 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | dprintk("--> %s\n", __func__); |
| 9089 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 9090 | &res.seq_res, 0); |
| 9091 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9092 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9093 | if (cred) |
| 9094 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9095 | |
| 9096 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9097 | } |
| 9098 | |
| 9099 | static int |
| 9100 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9101 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9102 | { |
| 9103 | struct nfs4_exception exception = { }; |
| 9104 | int err; |
| 9105 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9106 | /* first try using integrity protection */ |
| 9107 | err = -NFS4ERR_WRONGSEC; |
| 9108 | |
| 9109 | /* try to use integrity protection with machine cred */ |
| 9110 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9111 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9112 | flavors, true); |
| 9113 | |
| 9114 | /* |
| 9115 | * if unable to use integrity protection, or SECINFO with |
| 9116 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9117 | * disallowed by spec, but exists in deployed servers) use |
| 9118 | * the current filesystem's rpc_client and the user cred. |
| 9119 | */ |
| 9120 | if (err == -NFS4ERR_WRONGSEC) |
| 9121 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9122 | flavors, false); |
| 9123 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9124 | switch (err) { |
| 9125 | case 0: |
| 9126 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9127 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9128 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9129 | default: |
| 9130 | err = nfs4_handle_exception(server, err, &exception); |
| 9131 | } |
| 9132 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9133 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9134 | return err; |
| 9135 | } |
| 9136 | |
| 9137 | static int |
| 9138 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9139 | struct nfs_fsinfo *info) |
| 9140 | { |
| 9141 | int err; |
| 9142 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9143 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9144 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9145 | struct nfs4_secinfo4 *secinfo; |
| 9146 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9147 | |
| 9148 | page = alloc_page(GFP_KERNEL); |
| 9149 | if (!page) { |
| 9150 | err = -ENOMEM; |
| 9151 | goto out; |
| 9152 | } |
| 9153 | |
| 9154 | flavors = page_address(page); |
| 9155 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9156 | |
| 9157 | /* |
| 9158 | * Fall back on "guess and check" method if |
| 9159 | * the server doesn't support SECINFO_NO_NAME |
| 9160 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9161 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9162 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9163 | goto out_freepage; |
| 9164 | } |
| 9165 | if (err) |
| 9166 | goto out_freepage; |
| 9167 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9168 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9169 | secinfo = &flavors->flavors[i]; |
| 9170 | |
| 9171 | switch (secinfo->flavor) { |
| 9172 | case RPC_AUTH_NULL: |
| 9173 | case RPC_AUTH_UNIX: |
| 9174 | case RPC_AUTH_GSS: |
| 9175 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9176 | &secinfo->flavor_info); |
| 9177 | break; |
| 9178 | default: |
| 9179 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9180 | break; |
| 9181 | } |
| 9182 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9183 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9184 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9185 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9186 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9187 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9188 | info, flavor); |
| 9189 | if (!err) |
| 9190 | break; |
| 9191 | } |
| 9192 | } |
| 9193 | |
| 9194 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9195 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9196 | |
| 9197 | out_freepage: |
| 9198 | put_page(page); |
| 9199 | if (err == -EACCES) |
| 9200 | return -EPERM; |
| 9201 | out: |
| 9202 | return err; |
| 9203 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9204 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9205 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9206 | nfs4_stateid *stateid, |
| 9207 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9208 | { |
| 9209 | int status; |
| 9210 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9211 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9212 | }; |
| 9213 | struct nfs41_test_stateid_res res; |
| 9214 | struct rpc_message msg = { |
| 9215 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9216 | .rpc_argp = &args, |
| 9217 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9218 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9219 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9220 | struct rpc_clnt *rpc_client = server->client; |
| 9221 | |
| 9222 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9223 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9224 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9225 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9226 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9227 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9228 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9229 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9230 | if (status != NFS_OK) { |
| 9231 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9232 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9233 | } |
| 9234 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9235 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9236 | } |
| 9237 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9238 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9239 | int err, struct nfs4_exception *exception) |
| 9240 | { |
| 9241 | exception->retry = 0; |
| 9242 | switch(err) { |
| 9243 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9244 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9245 | nfs4_handle_exception(server, err, exception); |
| 9246 | break; |
| 9247 | case -NFS4ERR_BADSESSION: |
| 9248 | case -NFS4ERR_BADSLOT: |
| 9249 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9250 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9251 | case -NFS4ERR_DEADSESSION: |
| 9252 | nfs4_do_handle_exception(server, err, exception); |
| 9253 | } |
| 9254 | } |
| 9255 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9256 | /** |
| 9257 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9258 | * |
| 9259 | * @server: server / transport on which to perform the operation |
| 9260 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9261 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9262 | * |
| 9263 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9264 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9265 | * failed or the state ID is not currently valid. |
| 9266 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9267 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9268 | nfs4_stateid *stateid, |
| 9269 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9270 | { |
| 9271 | struct nfs4_exception exception = { }; |
| 9272 | int err; |
| 9273 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9274 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9275 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9276 | } while (exception.retry); |
| 9277 | return err; |
| 9278 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9279 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9280 | struct nfs_free_stateid_data { |
| 9281 | struct nfs_server *server; |
| 9282 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9283 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9284 | }; |
| 9285 | |
| 9286 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9287 | { |
| 9288 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9289 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9290 | &data->args.seq_args, |
| 9291 | &data->res.seq_res, |
| 9292 | task); |
| 9293 | } |
| 9294 | |
| 9295 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9296 | { |
| 9297 | struct nfs_free_stateid_data *data = calldata; |
| 9298 | |
| 9299 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9300 | |
| 9301 | switch (task->tk_status) { |
| 9302 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9303 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9304 | rpc_restart_call_prepare(task); |
| 9305 | } |
| 9306 | } |
| 9307 | |
| 9308 | static void nfs41_free_stateid_release(void *calldata) |
| 9309 | { |
| 9310 | kfree(calldata); |
| 9311 | } |
| 9312 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9313 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9314 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9315 | .rpc_call_done = nfs41_free_stateid_done, |
| 9316 | .rpc_release = nfs41_free_stateid_release, |
| 9317 | }; |
| 9318 | |
| 9319 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9320 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9321 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9322 | bool privileged) |
| 9323 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9324 | struct rpc_message msg = { |
| 9325 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9326 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9327 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9328 | struct rpc_task_setup task_setup = { |
| 9329 | .rpc_client = server->client, |
| 9330 | .rpc_message = &msg, |
| 9331 | .callback_ops = &nfs41_free_stateid_ops, |
| 9332 | .flags = RPC_TASK_ASYNC, |
| 9333 | }; |
| 9334 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9335 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9336 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9337 | &task_setup.rpc_client, &msg); |
| 9338 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9339 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9340 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9341 | if (!data) |
| 9342 | return ERR_PTR(-ENOMEM); |
| 9343 | data->server = server; |
| 9344 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9345 | |
| 9346 | task_setup.callback_data = data; |
| 9347 | |
| 9348 | msg.rpc_argp = &data->args; |
| 9349 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9350 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9351 | if (privileged) |
| 9352 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9353 | |
| 9354 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9355 | } |
| 9356 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9357 | /** |
| 9358 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9359 | * |
| 9360 | * @server: server / transport on which to perform the operation |
| 9361 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9362 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9363 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9364 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9365 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9366 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9367 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9368 | const nfs4_stateid *stateid, |
| 9369 | struct rpc_cred *cred, |
| 9370 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9371 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9372 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9373 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9374 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9375 | if (IS_ERR(task)) |
| 9376 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9377 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9378 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9379 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9380 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9381 | static void |
| 9382 | 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] | 9383 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9384 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9385 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9386 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9387 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9388 | } |
| 9389 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9390 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9391 | const nfs4_stateid *s2) |
| 9392 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9393 | if (s1->type != s2->type) |
| 9394 | return false; |
| 9395 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9396 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9397 | return false; |
| 9398 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9399 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9400 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9401 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9402 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9403 | } |
| 9404 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9405 | #endif /* CONFIG_NFS_V4_1 */ |
| 9406 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9407 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9408 | const nfs4_stateid *s2) |
| 9409 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9410 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9411 | } |
| 9412 | |
| 9413 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9414 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9415 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9416 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9417 | .recover_open = nfs4_open_reclaim, |
| 9418 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9419 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9420 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9421 | }; |
| 9422 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9423 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9424 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9425 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9426 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9427 | .recover_open = nfs4_open_reclaim, |
| 9428 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9429 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9430 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9431 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9432 | }; |
| 9433 | #endif /* CONFIG_NFS_V4_1 */ |
| 9434 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9435 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9436 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9437 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9438 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9439 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9440 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9441 | }; |
| 9442 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9443 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9444 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9445 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9446 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9447 | .recover_open = nfs41_open_expired, |
| 9448 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9449 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9450 | }; |
| 9451 | #endif /* CONFIG_NFS_V4_1 */ |
| 9452 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9453 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9454 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9455 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9456 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9457 | }; |
| 9458 | |
| 9459 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9460 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9461 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9462 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9463 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9464 | }; |
| 9465 | #endif |
| 9466 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9467 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9468 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9469 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9470 | }; |
| 9471 | |
| 9472 | #if defined(CONFIG_NFS_V4_1) |
| 9473 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9474 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9475 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9476 | }; |
| 9477 | #endif /* CONFIG_NFS_V4_1 */ |
| 9478 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9479 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9480 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9481 | .init_caps = NFS_CAP_READDIRPLUS |
| 9482 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9483 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9484 | .init_client = nfs40_init_client, |
| 9485 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9486 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9487 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9488 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9489 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9490 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9491 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9492 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9493 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9494 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9495 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9496 | }; |
| 9497 | |
| 9498 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9499 | static struct nfs_seqid * |
| 9500 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9501 | { |
| 9502 | return NULL; |
| 9503 | } |
| 9504 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9505 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9506 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9507 | .init_caps = NFS_CAP_READDIRPLUS |
| 9508 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9509 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9510 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9511 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9512 | .init_client = nfs41_init_client, |
| 9513 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9514 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9515 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9516 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9517 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9518 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9519 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9520 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9521 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9522 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9523 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9524 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9525 | }; |
| 9526 | #endif |
| 9527 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9528 | #if defined(CONFIG_NFS_V4_2) |
| 9529 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9530 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9531 | .init_caps = NFS_CAP_READDIRPLUS |
| 9532 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9533 | | NFS_CAP_POSIX_LOCK |
| 9534 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9535 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9536 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9537 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9538 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9539 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9540 | | NFS_CAP_LAYOUTSTATS |
| 9541 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9542 | .init_client = nfs41_init_client, |
| 9543 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9544 | .match_stateid = nfs41_match_stateid, |
| 9545 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9546 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9547 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9548 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9549 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9550 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9551 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9552 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9553 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9554 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9555 | }; |
| 9556 | #endif |
| 9557 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9558 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9559 | [0] = &nfs_v4_0_minor_ops, |
| 9560 | #if defined(CONFIG_NFS_V4_1) |
| 9561 | [1] = &nfs_v4_1_minor_ops, |
| 9562 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9563 | #if defined(CONFIG_NFS_V4_2) |
| 9564 | [2] = &nfs_v4_2_minor_ops, |
| 9565 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9566 | }; |
| 9567 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9568 | 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] | 9569 | { |
| 9570 | ssize_t error, error2; |
| 9571 | |
| 9572 | error = generic_listxattr(dentry, list, size); |
| 9573 | if (error < 0) |
| 9574 | return error; |
| 9575 | if (list) { |
| 9576 | list += error; |
| 9577 | size -= error; |
| 9578 | } |
| 9579 | |
| 9580 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9581 | if (error2 < 0) |
| 9582 | return error2; |
| 9583 | return error + error2; |
| 9584 | } |
| 9585 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9586 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9587 | .create = nfs_create, |
| 9588 | .lookup = nfs_lookup, |
| 9589 | .atomic_open = nfs_atomic_open, |
| 9590 | .link = nfs_link, |
| 9591 | .unlink = nfs_unlink, |
| 9592 | .symlink = nfs_symlink, |
| 9593 | .mkdir = nfs_mkdir, |
| 9594 | .rmdir = nfs_rmdir, |
| 9595 | .mknod = nfs_mknod, |
| 9596 | .rename = nfs_rename, |
| 9597 | .permission = nfs_permission, |
| 9598 | .getattr = nfs_getattr, |
| 9599 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9600 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9601 | }; |
| 9602 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9603 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9604 | .permission = nfs_permission, |
| 9605 | .getattr = nfs_getattr, |
| 9606 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9607 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9608 | }; |
| 9609 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9610 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9611 | .version = 4, /* protocol version */ |
| 9612 | .dentry_ops = &nfs4_dentry_operations, |
| 9613 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9614 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9615 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9616 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9617 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9618 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9619 | .getattr = nfs4_proc_getattr, |
| 9620 | .setattr = nfs4_proc_setattr, |
| 9621 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9622 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9623 | .access = nfs4_proc_access, |
| 9624 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9625 | .create = nfs4_proc_create, |
| 9626 | .remove = nfs4_proc_remove, |
| 9627 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9628 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9629 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9630 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9631 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9632 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9633 | .link = nfs4_proc_link, |
| 9634 | .symlink = nfs4_proc_symlink, |
| 9635 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 9636 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9637 | .readdir = nfs4_proc_readdir, |
| 9638 | .mknod = nfs4_proc_mknod, |
| 9639 | .statfs = nfs4_proc_statfs, |
| 9640 | .fsinfo = nfs4_proc_fsinfo, |
| 9641 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9642 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9643 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9644 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9645 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9646 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9647 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9648 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9649 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9650 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9651 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9652 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9653 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9654 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9655 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9656 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9657 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9658 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9659 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9660 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9661 | .create_server = nfs4_create_server, |
| 9662 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9663 | }; |
| 9664 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9665 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9666 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9667 | .list = nfs4_xattr_list_nfs4_acl, |
| 9668 | .get = nfs4_xattr_get_nfs4_acl, |
| 9669 | .set = nfs4_xattr_set_nfs4_acl, |
| 9670 | }; |
| 9671 | |
| 9672 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9673 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9674 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9675 | &nfs4_xattr_nfs4_label_handler, |
| 9676 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9677 | NULL |
| 9678 | }; |
| 9679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9680 | /* |
| 9681 | * Local variables: |
| 9682 | * c-basic-offset: 8 |
| 9683 | * End: |
| 9684 | */ |