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" |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 66 | #include "sysfs.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 67 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 68 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 69 | #include "fscache.h" |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 70 | #include "nfs42.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 72 | #include "nfs4trace.h" |
| 73 | |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 74 | #ifdef CONFIG_NFS_V4_2 |
| 75 | #include "nfs42.h" |
| 76 | #endif /* CONFIG_NFS_V4_2 */ |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 79 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 80 | #define NFS4_BITMASK_SZ 3 |
| 81 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 82 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 84 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 85 | /* file attributes which can be mapped to nfs attributes */ |
| 86 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 87 | | ATTR_UID \ |
| 88 | | ATTR_GID \ |
| 89 | | ATTR_SIZE \ |
| 90 | | ATTR_ATIME \ |
| 91 | | ATTR_MTIME \ |
| 92 | | ATTR_CTIME \ |
| 93 | | ATTR_ATIME_SET \ |
| 94 | | ATTR_MTIME_SET) |
| 95 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 96 | struct nfs4_opendata; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 97 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | 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] | 99 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 100 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 101 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 102 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 103 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 104 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 105 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 106 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 107 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 108 | struct nfs4_slot *slot, |
| 109 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 110 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 111 | const struct cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 112 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 113 | const struct cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 114 | #endif |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 115 | static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], |
| 116 | const __u32 *src, struct inode *inode, |
| 117 | struct nfs_server *server, |
| 118 | struct nfs4_label *label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 119 | |
| 120 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 121 | static inline struct nfs4_label * |
| 122 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 123 | struct iattr *sattr, struct nfs4_label *label) |
| 124 | { |
| 125 | int err; |
| 126 | |
| 127 | if (label == NULL) |
| 128 | return NULL; |
| 129 | |
| 130 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 131 | return NULL; |
| 132 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 133 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 134 | &dentry->d_name, (void **)&label->label, &label->len); |
| 135 | if (err == 0) |
| 136 | return label; |
| 137 | |
| 138 | return NULL; |
| 139 | } |
| 140 | static inline void |
| 141 | nfs4_label_release_security(struct nfs4_label *label) |
| 142 | { |
| 143 | if (label) |
| 144 | security_release_secctx(label->label, label->len); |
| 145 | } |
| 146 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 147 | { |
| 148 | if (label) |
| 149 | return server->attr_bitmask; |
| 150 | |
| 151 | return server->attr_bitmask_nl; |
| 152 | } |
| 153 | #else |
| 154 | static inline struct nfs4_label * |
| 155 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 156 | struct iattr *sattr, struct nfs4_label *l) |
| 157 | { return NULL; } |
| 158 | static inline void |
| 159 | nfs4_label_release_security(struct nfs4_label *label) |
| 160 | { return; } |
| 161 | static inline u32 * |
| 162 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 163 | { return server->attr_bitmask; } |
| 164 | #endif |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 167 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 169 | if (err >= -1000) |
| 170 | return err; |
| 171 | switch (err) { |
| 172 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 173 | case -NFS4ERR_LAYOUTTRYLATER: |
| 174 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 175 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 176 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 177 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 178 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 179 | case -NFS4ERR_BADOWNER: |
| 180 | case -NFS4ERR_BADNAME: |
| 181 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 182 | case -NFS4ERR_SHARE_DENIED: |
| 183 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 184 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 185 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 186 | case -NFS4ERR_FILE_OPEN: |
| 187 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 188 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 190 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 191 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 193 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
| 197 | * This is our standard bitmap for GETATTR requests. |
| 198 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 199 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | FATTR4_WORD0_TYPE |
| 201 | | FATTR4_WORD0_CHANGE |
| 202 | | FATTR4_WORD0_SIZE |
| 203 | | FATTR4_WORD0_FSID |
| 204 | | FATTR4_WORD0_FILEID, |
| 205 | FATTR4_WORD1_MODE |
| 206 | | FATTR4_WORD1_NUMLINKS |
| 207 | | FATTR4_WORD1_OWNER |
| 208 | | FATTR4_WORD1_OWNER_GROUP |
| 209 | | FATTR4_WORD1_RAWDEV |
| 210 | | FATTR4_WORD1_SPACE_USED |
| 211 | | FATTR4_WORD1_TIME_ACCESS |
| 212 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 213 | | FATTR4_WORD1_TIME_MODIFY |
| 214 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 215 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 216 | FATTR4_WORD2_SECURITY_LABEL |
| 217 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 220 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 221 | FATTR4_WORD0_TYPE |
| 222 | | FATTR4_WORD0_CHANGE |
| 223 | | FATTR4_WORD0_SIZE |
| 224 | | FATTR4_WORD0_FSID |
| 225 | | FATTR4_WORD0_FILEID, |
| 226 | FATTR4_WORD1_MODE |
| 227 | | FATTR4_WORD1_NUMLINKS |
| 228 | | FATTR4_WORD1_OWNER |
| 229 | | FATTR4_WORD1_OWNER_GROUP |
| 230 | | FATTR4_WORD1_RAWDEV |
| 231 | | FATTR4_WORD1_SPACE_USED |
| 232 | | FATTR4_WORD1_TIME_ACCESS |
| 233 | | FATTR4_WORD1_TIME_METADATA |
| 234 | | FATTR4_WORD1_TIME_MODIFY, |
| 235 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 236 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 237 | | FATTR4_WORD2_SECURITY_LABEL |
| 238 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 239 | }; |
| 240 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 241 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 242 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 243 | | FATTR4_WORD0_FILEID, |
| 244 | }; |
| 245 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 246 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | FATTR4_WORD0_FILES_AVAIL |
| 248 | | FATTR4_WORD0_FILES_FREE |
| 249 | | FATTR4_WORD0_FILES_TOTAL, |
| 250 | FATTR4_WORD1_SPACE_AVAIL |
| 251 | | FATTR4_WORD1_SPACE_FREE |
| 252 | | FATTR4_WORD1_SPACE_TOTAL |
| 253 | }; |
| 254 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 255 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | FATTR4_WORD0_MAXLINK |
| 257 | | FATTR4_WORD0_MAXNAME, |
| 258 | 0 |
| 259 | }; |
| 260 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 261 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | | FATTR4_WORD0_MAXREAD |
| 263 | | FATTR4_WORD0_MAXWRITE |
| 264 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 265 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 266 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 267 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 268 | | FATTR4_WORD2_CLONE_BLKSIZE |
Frank van der Linden | b78ef84 | 2020-06-23 22:38:55 +0000 | [diff] [blame] | 269 | | FATTR4_WORD2_XATTR_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 272 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 273 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 274 | | FATTR4_WORD0_SIZE |
| 275 | | FATTR4_WORD0_FSID |
| 276 | | FATTR4_WORD0_FILEID |
| 277 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 278 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 279 | | FATTR4_WORD1_OWNER_GROUP |
| 280 | | FATTR4_WORD1_RAWDEV |
| 281 | | FATTR4_WORD1_SPACE_USED |
| 282 | | FATTR4_WORD1_TIME_ACCESS |
| 283 | | FATTR4_WORD1_TIME_METADATA |
| 284 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 285 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 286 | }; |
| 287 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 288 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
| 289 | struct inode *inode) |
| 290 | { |
| 291 | unsigned long cache_validity; |
| 292 | |
| 293 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 294 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 295 | return; |
| 296 | |
| 297 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 298 | if (!(cache_validity & NFS_INO_REVAL_FORCED)) |
| 299 | cache_validity &= ~(NFS_INO_INVALID_CHANGE |
| 300 | | NFS_INO_INVALID_SIZE); |
| 301 | |
| 302 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 303 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 304 | |
| 305 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 306 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
| 307 | } |
| 308 | |
| 309 | static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, |
| 310 | const __u32 *src, struct inode *inode) |
| 311 | { |
| 312 | nfs4_bitmap_copy_adjust(dst, src, inode); |
| 313 | } |
| 314 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 315 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | struct nfs4_readdir_arg *readdir) |
| 317 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 318 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 319 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 322 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | readdir->cookie = 0; |
| 328 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 329 | if (cookie == 2) |
| 330 | return; |
| 331 | |
| 332 | /* |
| 333 | * NFSv4 servers do not return entries for '.' and '..' |
| 334 | * Therefore, we fake these entries here. We let '.' |
| 335 | * have cookie 0 and '..' have cookie 1. Note that |
| 336 | * when talking to the server, we always send cookie 0 |
| 337 | * instead of 1 or 2. |
| 338 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 339 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | if (cookie == 0) { |
| 342 | *p++ = xdr_one; /* next */ |
| 343 | *p++ = xdr_zero; /* cookie, first word */ |
| 344 | *p++ = xdr_one; /* cookie, second word */ |
| 345 | *p++ = xdr_one; /* entry len */ |
| 346 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 347 | p++; |
| 348 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 349 | *p++ = htonl(attrs); /* bitmap */ |
| 350 | *p++ = htonl(12); /* attribute buffer length */ |
| 351 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 352 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | *p++ = xdr_one; /* next */ |
| 356 | *p++ = xdr_zero; /* cookie, first word */ |
| 357 | *p++ = xdr_two; /* cookie, second word */ |
| 358 | *p++ = xdr_two; /* entry len */ |
| 359 | memcpy(p, "..\0\0", 4); /* entry */ |
| 360 | p++; |
| 361 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 362 | *p++ = htonl(attrs); /* bitmap */ |
| 363 | *p++ = htonl(12); /* attribute buffer length */ |
| 364 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 365 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | readdir->pgbase = (char *)p - (char *)start; |
| 368 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 369 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 372 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 373 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 374 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 375 | { |
| 376 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 377 | |
| 378 | ops->test_and_free_expired(server, stateid, cred); |
| 379 | } |
| 380 | |
| 381 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 382 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 383 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 384 | { |
| 385 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 386 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 387 | } |
| 388 | |
| 389 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 390 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 391 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 392 | { |
| 393 | nfs4_stateid tmp; |
| 394 | |
| 395 | nfs4_stateid_copy(&tmp, stateid); |
| 396 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 397 | } |
| 398 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 399 | static long nfs4_update_delay(long *timeout) |
| 400 | { |
| 401 | long ret; |
| 402 | if (!timeout) |
| 403 | return NFS4_POLL_RETRY_MAX; |
| 404 | if (*timeout <= 0) |
| 405 | *timeout = NFS4_POLL_RETRY_MIN; |
| 406 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 407 | *timeout = NFS4_POLL_RETRY_MAX; |
| 408 | ret = *timeout; |
| 409 | *timeout <<= 1; |
| 410 | return ret; |
| 411 | } |
| 412 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 413 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 414 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 415 | might_sleep(); |
| 416 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 417 | freezable_schedule_timeout_killable_unsafe( |
| 418 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 419 | if (!__fatal_signal_pending(current)) |
| 420 | return 0; |
| 421 | return -EINTR; |
| 422 | } |
| 423 | |
| 424 | static int nfs4_delay_interruptible(long *timeout) |
| 425 | { |
| 426 | might_sleep(); |
| 427 | |
He Zhe | 59679d9 | 2020-07-06 17:52:24 +0800 | [diff] [blame] | 428 | freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 429 | if (!signal_pending(current)) |
| 430 | return 0; |
| 431 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 432 | } |
| 433 | |
| 434 | static int nfs4_delay(long *timeout, bool interruptible) |
| 435 | { |
| 436 | if (interruptible) |
| 437 | return nfs4_delay_interruptible(timeout); |
| 438 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 439 | } |
| 440 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 441 | static const nfs4_stateid * |
| 442 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 443 | { |
| 444 | if (!stateid) |
| 445 | return NULL; |
| 446 | switch (stateid->type) { |
| 447 | case NFS4_OPEN_STATEID_TYPE: |
| 448 | case NFS4_LOCK_STATEID_TYPE: |
| 449 | case NFS4_DELEGATION_STATEID_TYPE: |
| 450 | return stateid; |
| 451 | default: |
| 452 | break; |
| 453 | } |
| 454 | return NULL; |
| 455 | } |
| 456 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 457 | /* This is the error handling routine for processes that are allowed |
| 458 | * to sleep. |
| 459 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 460 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 461 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 462 | { |
| 463 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 464 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 465 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 466 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 467 | int ret = errorcode; |
| 468 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 469 | exception->delay = 0; |
| 470 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 471 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 472 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 473 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 474 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 475 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 476 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 477 | switch(errorcode) { |
| 478 | case 0: |
| 479 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 480 | case -NFS4ERR_BADHANDLE: |
| 481 | case -ESTALE: |
| 482 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 483 | pnfs_destroy_layout(NFS_I(inode)); |
| 484 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 485 | case -NFS4ERR_DELEG_REVOKED: |
| 486 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 487 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 488 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame] | 489 | case -NFS4ERR_PARTNER_NO_AUTH: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 490 | if (inode != NULL && stateid != NULL) { |
| 491 | nfs_inode_find_state_and_recover(inode, |
| 492 | stateid); |
| 493 | goto wait_on_recovery; |
| 494 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 495 | fallthrough; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 496 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 497 | if (inode) { |
| 498 | int err; |
| 499 | |
| 500 | err = nfs_async_inode_return_delegation(inode, |
| 501 | stateid); |
| 502 | if (err == 0) |
| 503 | goto wait_on_recovery; |
| 504 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 505 | exception->retry = 1; |
| 506 | break; |
| 507 | } |
| 508 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 509 | if (state == NULL) |
| 510 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 511 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 512 | if (ret < 0) |
| 513 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 514 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 515 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 516 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 517 | nfs4_schedule_lease_recovery(clp); |
| 518 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 519 | case -NFS4ERR_MOVED: |
| 520 | ret = nfs4_schedule_migration_recovery(server); |
| 521 | if (ret < 0) |
| 522 | break; |
| 523 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 524 | case -NFS4ERR_LEASE_MOVED: |
| 525 | nfs4_schedule_lease_moved_recovery(clp); |
| 526 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 527 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 528 | case -NFS4ERR_BADSESSION: |
| 529 | case -NFS4ERR_BADSLOT: |
| 530 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 531 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 532 | case -NFS4ERR_DEADSESSION: |
| 533 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 534 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 535 | /* Handled in nfs41_sequence_process() */ |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 536 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 537 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 538 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 539 | if (exception->timeout > HZ) { |
| 540 | /* We have retried a decent amount, time to |
| 541 | * fail |
| 542 | */ |
| 543 | ret = -EBUSY; |
| 544 | break; |
| 545 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 546 | fallthrough; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 547 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 548 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 549 | fallthrough; |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 550 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 551 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 552 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 553 | exception->delay = 1; |
| 554 | return 0; |
| 555 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 556 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 557 | case -NFS4ERR_OLD_STATEID: |
| 558 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 559 | break; |
| 560 | case -NFS4ERR_BADOWNER: |
| 561 | /* The following works around a Linux server bug! */ |
| 562 | case -NFS4ERR_BADNAME: |
| 563 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 564 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 565 | exception->retry = 1; |
| 566 | printk(KERN_WARNING "NFS: v4 server %s " |
| 567 | "does not accept raw " |
| 568 | "uid/gids. " |
| 569 | "Reenabling the idmapper.\n", |
| 570 | server->nfs_client->cl_hostname); |
| 571 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 572 | } |
| 573 | /* We failed to handle the error */ |
| 574 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 575 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 576 | exception->recovering = 1; |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | /* This is the error handling routine for processes that are allowed |
| 581 | * to sleep. |
| 582 | */ |
| 583 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 584 | { |
| 585 | struct nfs_client *clp = server->nfs_client; |
| 586 | int ret; |
| 587 | |
| 588 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 589 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 590 | ret = nfs4_delay(&exception->timeout, |
| 591 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 592 | goto out_retry; |
| 593 | } |
| 594 | if (exception->recovering) { |
Trond Myklebust | b4651ce | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 595 | if (exception->task_is_privileged) |
| 596 | return -EDEADLOCK; |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 597 | ret = nfs4_wait_clnt_recover(clp); |
| 598 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 599 | return -EIO; |
| 600 | goto out_retry; |
| 601 | } |
| 602 | return ret; |
| 603 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 604 | if (ret == 0) |
| 605 | exception->retry = 1; |
| 606 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 607 | } |
| 608 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 609 | static int |
| 610 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 611 | int errorcode, struct nfs4_exception *exception) |
| 612 | { |
| 613 | struct nfs_client *clp = server->nfs_client; |
| 614 | int ret; |
| 615 | |
| 616 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 617 | if (exception->delay) { |
| 618 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 619 | goto out_retry; |
| 620 | } |
| 621 | if (exception->recovering) { |
Trond Myklebust | b4651ce | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 622 | if (exception->task_is_privileged) |
| 623 | return -EDEADLOCK; |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 624 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 625 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 626 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 627 | goto out_retry; |
| 628 | } |
| 629 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 630 | ret = -EIO; |
| 631 | return ret; |
| 632 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 633 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 634 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 635 | /* |
| 636 | * For NFS4ERR_MOVED, the client transport will need to |
| 637 | * be recomputed after migration recovery has completed. |
| 638 | */ |
| 639 | if (errorcode == -NFS4ERR_MOVED) |
| 640 | rpc_task_release_transport(task); |
| 641 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 642 | return ret; |
| 643 | } |
| 644 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 645 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 646 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 647 | struct nfs4_state *state, long *timeout) |
| 648 | { |
| 649 | struct nfs4_exception exception = { |
| 650 | .state = state, |
| 651 | }; |
| 652 | |
| 653 | if (task->tk_status >= 0) |
| 654 | return 0; |
| 655 | if (timeout) |
| 656 | exception.timeout = *timeout; |
| 657 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 658 | task->tk_status, |
| 659 | &exception); |
| 660 | if (exception.delay && timeout) |
| 661 | *timeout = exception.timeout; |
| 662 | if (exception.retry) |
| 663 | return -EAGAIN; |
| 664 | return 0; |
| 665 | } |
| 666 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 667 | /* |
| 668 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 669 | * or 'false' otherwise. |
| 670 | */ |
| 671 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 672 | { |
| 673 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 674 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 675 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 676 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 677 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | spin_lock(&clp->cl_lock); |
| 680 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 681 | clp->cl_last_renewal = timestamp; |
| 682 | spin_unlock(&clp->cl_lock); |
| 683 | } |
| 684 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 685 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 686 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 687 | struct nfs_client *clp = server->nfs_client; |
| 688 | |
| 689 | if (!nfs4_has_session(clp)) |
| 690 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 691 | } |
| 692 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 693 | struct nfs4_call_sync_data { |
| 694 | const struct nfs_server *seq_server; |
| 695 | struct nfs4_sequence_args *seq_args; |
| 696 | struct nfs4_sequence_res *seq_res; |
| 697 | }; |
| 698 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 699 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 700 | struct nfs4_sequence_res *res, int cache_reply, |
| 701 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 702 | { |
| 703 | args->sa_slot = NULL; |
| 704 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 705 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 706 | |
| 707 | res->sr_slot = NULL; |
| 708 | } |
| 709 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 710 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 711 | { |
| 712 | struct nfs4_slot *slot = res->sr_slot; |
| 713 | struct nfs4_slot_table *tbl; |
| 714 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 715 | tbl = slot->table; |
| 716 | spin_lock(&tbl->slot_tbl_lock); |
| 717 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 718 | nfs4_free_slot(tbl, slot); |
| 719 | spin_unlock(&tbl->slot_tbl_lock); |
| 720 | |
| 721 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static int nfs40_sequence_done(struct rpc_task *task, |
| 725 | struct nfs4_sequence_res *res) |
| 726 | { |
| 727 | if (res->sr_slot != NULL) |
| 728 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 729 | return 1; |
| 730 | } |
| 731 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 732 | #if defined(CONFIG_NFS_V4_1) |
| 733 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 734 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 735 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 736 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 737 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 738 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 739 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 740 | if (!slot) |
| 741 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 742 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 743 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 744 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 745 | /* Bump the slot sequence number */ |
| 746 | if (slot->seq_done) |
| 747 | slot->seq_nr++; |
| 748 | slot->seq_done = 0; |
| 749 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 750 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 751 | /* Be nice to the server: try to ensure that the last transmitted |
| 752 | * value for highest_user_slotid <= target_highest_slotid |
| 753 | */ |
| 754 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 755 | send_new_highest_used_slotid = true; |
| 756 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 757 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 758 | send_new_highest_used_slotid = false; |
| 759 | goto out_unlock; |
| 760 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 761 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 762 | |
| 763 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 764 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 765 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 766 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 767 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 768 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 769 | if (waitqueue_active(&tbl->slot_waitq)) |
| 770 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 773 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 774 | { |
| 775 | nfs41_release_slot(res->sr_slot); |
| 776 | res->sr_slot = NULL; |
| 777 | } |
| 778 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 779 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 780 | u32 seqnr) |
| 781 | { |
| 782 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 783 | slot->seq_nr_highest_sent = seqnr; |
| 784 | } |
| 785 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 786 | u32 seqnr) |
| 787 | { |
| 788 | slot->seq_nr_highest_sent = seqnr; |
| 789 | slot->seq_nr_last_acked = seqnr; |
| 790 | } |
| 791 | |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 792 | static void nfs4_probe_sequence(struct nfs_client *client, const struct cred *cred, |
| 793 | struct nfs4_slot *slot) |
| 794 | { |
| 795 | struct rpc_task *task = _nfs41_proc_sequence(client, cred, slot, true); |
| 796 | if (!IS_ERR(task)) |
| 797 | rpc_put_task_async(task); |
| 798 | } |
| 799 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 800 | static int nfs41_sequence_process(struct rpc_task *task, |
| 801 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 802 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 803 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 804 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 805 | struct nfs_client *clp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 806 | int status; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 807 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 808 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 809 | if (slot == NULL) |
| 810 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 811 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 812 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 813 | goto out; |
| 814 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 815 | session = slot->table->session; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 816 | clp = session->clp; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 817 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 818 | trace_nfs4_sequence_done(session, res); |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 819 | |
| 820 | status = res->sr_status; |
| 821 | if (task->tk_status == -NFS4ERR_DEADSESSION) |
| 822 | status = -NFS4ERR_DEADSESSION; |
| 823 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 824 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 825 | switch (status) { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 826 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 827 | /* Mark this sequence number as having been acked */ |
| 828 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 829 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 830 | slot->seq_done = 1; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 831 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 832 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 833 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 834 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 835 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 836 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 837 | case 1: |
| 838 | /* |
| 839 | * sr_status remains 1 if an RPC level error occurred. |
| 840 | * The server may or may not have processed the sequence |
| 841 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 842 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 843 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 844 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 845 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 846 | case -NFS4ERR_DELAY: |
| 847 | /* The server detected a resend of the RPC call and |
| 848 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 849 | * of RFC5661. |
| 850 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 851 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 852 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 853 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 854 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 855 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 856 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 857 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 858 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 859 | /* |
| 860 | * The server thinks we tried to replay a request. |
| 861 | * Retry the call after bumping the sequence ID. |
| 862 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 863 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 864 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 865 | case -NFS4ERR_BADSLOT: |
| 866 | /* |
| 867 | * The slot id we used was probably retired. Try again |
| 868 | * using a different slot id. |
| 869 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 870 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 871 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 872 | goto retry_nowait; |
| 873 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 874 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 875 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 876 | * Were one or more calls using this slot interrupted? |
| 877 | * If the server never received the request, then our |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 878 | * transmitted slot sequence number may be too high. However, |
| 879 | * if the server did receive the request then it might |
| 880 | * accidentally give us a reply with a mismatched operation. |
| 881 | * We can sort this out by sending a lone sequence operation |
| 882 | * to the server on the same slot. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 883 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 884 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 885 | slot->seq_nr--; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 886 | if (task->tk_msg.rpc_proc != &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE]) { |
| 887 | nfs4_probe_sequence(clp, task->tk_msg.rpc_cred, slot); |
| 888 | res->sr_slot = NULL; |
| 889 | } |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 890 | goto retry_nowait; |
| 891 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 892 | /* |
| 893 | * RFC5661: |
| 894 | * A retry might be sent while the original request is |
| 895 | * still in progress on the replier. The replier SHOULD |
| 896 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 897 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 898 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 899 | * |
| 900 | * Restart the search after a delay. |
| 901 | */ |
| 902 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 903 | goto out_retry; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 904 | case -NFS4ERR_BADSESSION: |
| 905 | case -NFS4ERR_DEADSESSION: |
| 906 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 907 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 908 | default: |
| 909 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 910 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 911 | } |
| 912 | out: |
| 913 | /* The session may be reset by one of the error handlers. */ |
| 914 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 915 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 916 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 917 | session_recover: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 918 | nfs4_schedule_session_recovery(session, status); |
| 919 | dprintk("%s ERROR: %d Reset session\n", __func__, status); |
| 920 | nfs41_sequence_free_slot(res); |
| 921 | goto out; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 922 | retry_new_seq: |
| 923 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 924 | retry_nowait: |
| 925 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 926 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 927 | task->tk_status = 0; |
| 928 | ret = 0; |
| 929 | } |
| 930 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 931 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 932 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 933 | goto out; |
| 934 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 935 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 936 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 937 | |
| 938 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 939 | { |
| 940 | if (!nfs41_sequence_process(task, res)) |
| 941 | return 0; |
| 942 | if (res->sr_slot != NULL) |
| 943 | nfs41_sequence_free_slot(res); |
| 944 | return 1; |
| 945 | |
| 946 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 947 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 948 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 949 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 950 | { |
| 951 | if (res->sr_slot == NULL) |
| 952 | return 1; |
| 953 | if (res->sr_slot->table->session != NULL) |
| 954 | return nfs41_sequence_process(task, res); |
| 955 | return nfs40_sequence_done(task, res); |
| 956 | } |
| 957 | |
| 958 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 959 | { |
| 960 | if (res->sr_slot != NULL) { |
| 961 | if (res->sr_slot->table->session != NULL) |
| 962 | nfs41_sequence_free_slot(res); |
| 963 | else |
| 964 | nfs40_sequence_free_slot(res); |
| 965 | } |
| 966 | } |
| 967 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 968 | 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] | 969 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 970 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 971 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 972 | if (!res->sr_slot->table->session) |
| 973 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 974 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 975 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 976 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 977 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 978 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 979 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 980 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 981 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 982 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 983 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 984 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 985 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 986 | } |
| 987 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 988 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 989 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 990 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 991 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 992 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 993 | } |
| 994 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 995 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 996 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 997 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 998 | }; |
| 999 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1000 | #else /* !CONFIG_NFS_V4_1 */ |
| 1001 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1002 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 1003 | { |
| 1004 | return nfs40_sequence_done(task, res); |
| 1005 | } |
| 1006 | |
| 1007 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1008 | { |
| 1009 | if (res->sr_slot != NULL) |
| 1010 | nfs40_sequence_free_slot(res); |
| 1011 | } |
| 1012 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1013 | int nfs4_sequence_done(struct rpc_task *task, |
| 1014 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1015 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1016 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1017 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1018 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1019 | |
| 1020 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1021 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1022 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 1023 | { |
| 1024 | res->sr_timestamp = jiffies; |
| 1025 | res->sr_status_flags = 0; |
| 1026 | res->sr_status = 1; |
| 1027 | } |
| 1028 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1029 | static |
| 1030 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 1031 | struct nfs4_sequence_res *res, |
| 1032 | struct nfs4_slot *slot) |
| 1033 | { |
| 1034 | if (!slot) |
| 1035 | return; |
| 1036 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 1037 | args->sa_slot = slot; |
| 1038 | |
| 1039 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1043 | struct nfs4_sequence_args *args, |
| 1044 | struct nfs4_sequence_res *res, |
| 1045 | struct rpc_task *task) |
| 1046 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1047 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1048 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1049 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1050 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1051 | /* slot already allocated? */ |
| 1052 | if (res->sr_slot != NULL) |
| 1053 | goto out_start; |
| 1054 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1055 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1056 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1057 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1058 | spin_lock(&tbl->slot_tbl_lock); |
| 1059 | /* The state manager will wait until the slot table is empty */ |
| 1060 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1061 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1062 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1063 | slot = nfs4_alloc_slot(tbl); |
| 1064 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1065 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1066 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1067 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1068 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1069 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1070 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1071 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1072 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1073 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1074 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1075 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1076 | rpc_call_start(task); |
| 1077 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1078 | out_sleep_timeout: |
| 1079 | /* Try again in 1/4 second */ |
| 1080 | if (args->sa_privileged) |
| 1081 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1082 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1083 | else |
| 1084 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1085 | NULL, jiffies + (HZ >> 2)); |
| 1086 | spin_unlock(&tbl->slot_tbl_lock); |
| 1087 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1088 | out_sleep: |
| 1089 | if (args->sa_privileged) |
| 1090 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1091 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1092 | else |
| 1093 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1094 | spin_unlock(&tbl->slot_tbl_lock); |
| 1095 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1096 | } |
| 1097 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1098 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1099 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1100 | { |
| 1101 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1102 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1103 | data->seq_args, data->seq_res, task); |
| 1104 | } |
| 1105 | |
| 1106 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1107 | { |
| 1108 | struct nfs4_call_sync_data *data = calldata; |
| 1109 | nfs4_sequence_done(task, data->seq_res); |
| 1110 | } |
| 1111 | |
| 1112 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1113 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1114 | .rpc_call_done = nfs40_call_sync_done, |
| 1115 | }; |
| 1116 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1117 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1118 | { |
| 1119 | int ret; |
| 1120 | struct rpc_task *task; |
| 1121 | |
| 1122 | task = rpc_run_task(task_setup); |
| 1123 | if (IS_ERR(task)) |
| 1124 | return PTR_ERR(task); |
| 1125 | |
| 1126 | ret = task->tk_status; |
| 1127 | rpc_put_task(task); |
| 1128 | return ret; |
| 1129 | } |
| 1130 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1131 | static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
| 1132 | struct nfs_server *server, |
| 1133 | struct rpc_message *msg, |
| 1134 | struct nfs4_sequence_args *args, |
| 1135 | struct nfs4_sequence_res *res, |
| 1136 | unsigned short task_flags) |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1137 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1138 | struct nfs_client *clp = server->nfs_client; |
| 1139 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1140 | .seq_server = server, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1141 | .seq_args = args, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1142 | .seq_res = res, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1143 | }; |
| 1144 | struct rpc_task_setup task_setup = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1145 | .rpc_client = clnt, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1146 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1147 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1148 | .callback_data = &data, |
| 1149 | .flags = task_flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1150 | }; |
| 1151 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1152 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1153 | } |
| 1154 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1155 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 1156 | struct nfs_server *server, |
| 1157 | struct rpc_message *msg, |
| 1158 | struct nfs4_sequence_args *args, |
| 1159 | struct nfs4_sequence_res *res) |
| 1160 | { |
| 1161 | return nfs4_do_call_sync(clnt, server, msg, args, res, 0); |
| 1162 | } |
| 1163 | |
| 1164 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1165 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1166 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1167 | struct rpc_message *msg, |
| 1168 | struct nfs4_sequence_args *args, |
| 1169 | struct nfs4_sequence_res *res, |
| 1170 | int cache_reply) |
| 1171 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1172 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1173 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1176 | static void |
| 1177 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1178 | { |
| 1179 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1180 | inc_nlink(inode); |
| 1181 | } |
| 1182 | |
| 1183 | static void |
| 1184 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1185 | { |
| 1186 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1187 | drop_nlink(inode); |
| 1188 | } |
| 1189 | |
| 1190 | static void |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1191 | nfs4_update_changeattr_locked(struct inode *inode, |
| 1192 | struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1193 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1195 | struct nfs_inode *nfsi = NFS_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1197 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1198 | | NFS_INO_INVALID_MTIME |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1199 | | cache_validity; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1200 | |
| 1201 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(inode)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1202 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1203 | nfsi->attrtimeo_timestamp = jiffies; |
| 1204 | } else { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1205 | if (S_ISDIR(inode->i_mode)) { |
| 1206 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; |
| 1207 | nfs_force_lookup_revalidate(inode); |
| 1208 | } else { |
| 1209 | if (!NFS_PROTO(inode)->have_delegation(inode, |
| 1210 | FMODE_READ)) |
| 1211 | nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE; |
| 1212 | } |
| 1213 | |
| 1214 | if (cinfo->before != inode_peek_iversion_raw(inode)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1215 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
Frank van der Linden | 0f44da5 | 2020-06-23 22:39:00 +0000 | [diff] [blame] | 1216 | NFS_INO_INVALID_ACL | |
| 1217 | NFS_INO_INVALID_XATTR; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1218 | } |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1219 | inode_set_iversion_raw(inode, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1220 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1221 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1222 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1223 | |
| 1224 | if (nfsi->cache_validity & NFS_INO_INVALID_DATA) |
| 1225 | nfs_fscache_invalidate(inode); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1228 | void |
| 1229 | nfs4_update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1230 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1231 | { |
| 1232 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1233 | nfs4_update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | spin_unlock(&dir->i_lock); |
| 1235 | } |
| 1236 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1237 | struct nfs4_open_createattrs { |
| 1238 | struct nfs4_label *label; |
| 1239 | struct iattr *sattr; |
| 1240 | const __u32 verf[2]; |
| 1241 | }; |
| 1242 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1243 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1244 | int err, struct nfs4_exception *exception) |
| 1245 | { |
| 1246 | if (err != -EINVAL) |
| 1247 | return false; |
| 1248 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1249 | return false; |
| 1250 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1251 | exception->retry = 1; |
| 1252 | return true; |
| 1253 | } |
| 1254 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1255 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1256 | { |
| 1257 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1258 | } |
| 1259 | |
| 1260 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1261 | { |
| 1262 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1263 | |
| 1264 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1265 | } |
| 1266 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1267 | static u32 |
| 1268 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1269 | fmode_t fmode, int openflags) |
| 1270 | { |
| 1271 | u32 res = 0; |
| 1272 | |
| 1273 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1274 | case FMODE_READ: |
| 1275 | res = NFS4_SHARE_ACCESS_READ; |
| 1276 | break; |
| 1277 | case FMODE_WRITE: |
| 1278 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1279 | break; |
| 1280 | case FMODE_READ|FMODE_WRITE: |
| 1281 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1282 | } |
| 1283 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1284 | goto out; |
| 1285 | /* Want no delegation if we're using O_DIRECT */ |
| 1286 | if (openflags & O_DIRECT) |
| 1287 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1288 | out: |
| 1289 | return res; |
| 1290 | } |
| 1291 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1292 | static enum open_claim_type4 |
| 1293 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1294 | enum open_claim_type4 claim) |
| 1295 | { |
| 1296 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1297 | return claim; |
| 1298 | switch (claim) { |
| 1299 | default: |
| 1300 | return claim; |
| 1301 | case NFS4_OPEN_CLAIM_FH: |
| 1302 | return NFS4_OPEN_CLAIM_NULL; |
| 1303 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1304 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1305 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1306 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1307 | } |
| 1308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
| 1310 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1311 | { |
| 1312 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1313 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1314 | p->o_res.seqid = p->o_arg.seqid; |
| 1315 | p->c_res.seqid = p->c_arg.seqid; |
| 1316 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1317 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1318 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1319 | 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] | 1320 | } |
| 1321 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1322 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1323 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1324 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1325 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1326 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1327 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1328 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1329 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1330 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1331 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1332 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1333 | struct nfs4_opendata *p; |
| 1334 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1335 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1336 | if (p == NULL) |
| 1337 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1338 | |
| 1339 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1340 | if (IS_ERR(p->f_label)) |
| 1341 | goto err_free_p; |
| 1342 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1343 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1344 | if (IS_ERR(p->a_label)) |
| 1345 | goto err_free_f; |
| 1346 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1347 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1348 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1349 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1350 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1351 | nfs_sb_active(dentry->d_sb); |
| 1352 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1353 | p->dir = parent; |
| 1354 | p->owner = sp; |
| 1355 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1356 | p->o_arg.open_flags = flags; |
| 1357 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1358 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1359 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1360 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1361 | if (flags & O_CREAT) { |
| 1362 | p->o_arg.umask = current_umask(); |
| 1363 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1364 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1365 | p->o_arg.u.attrs = &p->attrs; |
| 1366 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1367 | |
| 1368 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1369 | sizeof(p->o_arg.u.verifier.data)); |
| 1370 | } |
| 1371 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1372 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1373 | * will return permission denied for all bits until close */ |
| 1374 | if (!(flags & O_EXCL)) { |
| 1375 | /* ask server to check for all possible rights as results |
| 1376 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1377 | switch (p->o_arg.claim) { |
| 1378 | default: |
| 1379 | break; |
| 1380 | case NFS4_OPEN_CLAIM_NULL: |
| 1381 | case NFS4_OPEN_CLAIM_FH: |
| 1382 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1383 | NFS4_ACCESS_MODIFY | |
| 1384 | NFS4_ACCESS_EXTEND | |
| 1385 | NFS4_ACCESS_EXECUTE; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1386 | #ifdef CONFIG_NFS_V4_2 |
| 1387 | if (server->caps & NFS_CAP_XATTR) |
| 1388 | p->o_arg.access |= NFS4_ACCESS_XAREAD | |
| 1389 | NFS4_ACCESS_XAWRITE | |
| 1390 | NFS4_ACCESS_XALIST; |
| 1391 | #endif |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1392 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1393 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1394 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1395 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1396 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1397 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1398 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1399 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1400 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1401 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1402 | case NFS4_OPEN_CLAIM_NULL: |
| 1403 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1404 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1405 | p->o_arg.fh = NFS_FH(dir); |
| 1406 | break; |
| 1407 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1408 | case NFS4_OPEN_CLAIM_FH: |
| 1409 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1410 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1411 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1412 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1413 | p->c_arg.fh = &p->o_res.fh; |
| 1414 | p->c_arg.stateid = &p->o_res.stateid; |
| 1415 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1416 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1417 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1418 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1419 | |
| 1420 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1421 | nfs4_label_free(p->a_label); |
| 1422 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1423 | nfs4_label_free(p->f_label); |
| 1424 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1425 | kfree(p); |
| 1426 | err: |
| 1427 | dput(parent); |
| 1428 | return NULL; |
| 1429 | } |
| 1430 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1431 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1432 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1433 | struct nfs4_opendata *p = container_of(kref, |
| 1434 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1435 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1436 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1437 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1438 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1439 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1440 | if (p->state != NULL) |
| 1441 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1442 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1443 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1444 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1445 | nfs4_label_free(p->f_label); |
| 1446 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1447 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1448 | dput(p->dentry); |
| 1449 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1450 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1451 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1452 | kfree(p); |
| 1453 | } |
| 1454 | |
| 1455 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1456 | { |
| 1457 | if (p != NULL) |
| 1458 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1459 | } |
| 1460 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1461 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1462 | fmode_t fmode) |
| 1463 | { |
| 1464 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1465 | case FMODE_READ|FMODE_WRITE: |
| 1466 | return state->n_rdwr != 0; |
| 1467 | case FMODE_WRITE: |
| 1468 | return state->n_wronly != 0; |
| 1469 | case FMODE_READ: |
| 1470 | return state->n_rdonly != 0; |
| 1471 | } |
| 1472 | WARN_ON_ONCE(1); |
| 1473 | return false; |
| 1474 | } |
| 1475 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1476 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1477 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1478 | { |
| 1479 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1480 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1481 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1482 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1483 | switch (claim) { |
| 1484 | case NFS4_OPEN_CLAIM_NULL: |
| 1485 | case NFS4_OPEN_CLAIM_FH: |
| 1486 | goto out; |
| 1487 | default: |
| 1488 | break; |
| 1489 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1490 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1491 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1492 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1493 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1494 | break; |
| 1495 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1496 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1497 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1498 | break; |
| 1499 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1500 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1501 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1502 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1503 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1504 | return ret; |
| 1505 | } |
| 1506 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1507 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1508 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1509 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1510 | if (delegation == NULL) |
| 1511 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1512 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1513 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1514 | switch (claim) { |
| 1515 | case NFS4_OPEN_CLAIM_NULL: |
| 1516 | case NFS4_OPEN_CLAIM_FH: |
| 1517 | break; |
| 1518 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1519 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1520 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1521 | fallthrough; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1522 | default: |
| 1523 | return 0; |
| 1524 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1525 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1526 | return 1; |
| 1527 | } |
| 1528 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1529 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1530 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1531 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1532 | case FMODE_WRITE: |
| 1533 | state->n_wronly++; |
| 1534 | break; |
| 1535 | case FMODE_READ: |
| 1536 | state->n_rdonly++; |
| 1537 | break; |
| 1538 | case FMODE_READ|FMODE_WRITE: |
| 1539 | state->n_rdwr++; |
| 1540 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1541 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1542 | } |
| 1543 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1544 | #ifdef CONFIG_NFS_V4_1 |
| 1545 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1546 | { |
| 1547 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1548 | return true; |
| 1549 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1550 | return true; |
| 1551 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1552 | return true; |
| 1553 | return false; |
| 1554 | } |
| 1555 | #endif /* CONFIG_NFS_V4_1 */ |
| 1556 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1557 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1558 | { |
| 1559 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1560 | wake_up_all(&state->waitq); |
| 1561 | } |
| 1562 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1563 | 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] | 1564 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1565 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1566 | bool need_recover = false; |
| 1567 | |
| 1568 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1569 | need_recover = true; |
| 1570 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1571 | need_recover = true; |
| 1572 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1573 | need_recover = true; |
| 1574 | if (need_recover) |
| 1575 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1576 | } |
| 1577 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1578 | /* |
| 1579 | * Check for whether or not the caller may update the open stateid |
| 1580 | * to the value passed in by stateid. |
| 1581 | * |
| 1582 | * Note: This function relies heavily on the server implementing |
| 1583 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1584 | * correctly. |
| 1585 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1586 | * are then incremented on every state transition. |
| 1587 | */ |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1588 | static bool nfs_stateid_is_sequential(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1589 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1590 | { |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1591 | if (test_bit(NFS_OPEN_STATE, &state->flags)) { |
| 1592 | /* The common case - we're updating to a new sequence number */ |
Trond Myklebust | 8c3e204 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1593 | if (nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1594 | if (nfs4_stateid_is_next(&state->open_stateid, stateid)) |
| 1595 | return true; |
| 1596 | return false; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1597 | } |
Trond Myklebust | 8c3e204 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1598 | /* The server returned a new stateid */ |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1599 | } |
Trond Myklebust | 8c3e204 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1600 | /* This is the first OPEN in this generation */ |
| 1601 | if (stateid->seqid == cpu_to_be32(1)) |
| 1602 | return true; |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1603 | return false; |
| 1604 | } |
| 1605 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1606 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1607 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1608 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1609 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1610 | if (state->n_wronly) |
| 1611 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1612 | if (state->n_rdonly) |
| 1613 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1614 | if (state->n_rdwr) |
| 1615 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1616 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1617 | } |
| 1618 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1619 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1620 | nfs4_stateid *stateid, fmode_t fmode) |
| 1621 | { |
| 1622 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1623 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1624 | case FMODE_WRITE: |
| 1625 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1626 | break; |
| 1627 | case FMODE_READ: |
| 1628 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1629 | break; |
| 1630 | case 0: |
| 1631 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1632 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1633 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1634 | } |
| 1635 | if (stateid == NULL) |
| 1636 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1637 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1638 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1639 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1640 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1641 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1642 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1643 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1644 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1645 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1646 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1647 | out: |
| 1648 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1649 | } |
| 1650 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1651 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1652 | nfs4_stateid *arg_stateid, |
| 1653 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1654 | { |
| 1655 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1656 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1657 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1658 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1659 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1660 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1661 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1662 | } |
| 1663 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1664 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1665 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1666 | __must_hold(&state->owner->so_lock) |
| 1667 | __must_hold(&state->seqlock) |
| 1668 | __must_hold(RCU) |
| 1669 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1670 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1671 | DEFINE_WAIT(wait); |
| 1672 | int status = 0; |
| 1673 | for (;;) { |
| 1674 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1675 | if (nfs_stateid_is_sequential(state, stateid)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1676 | break; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1677 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1678 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1679 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1680 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1681 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1682 | break; |
| 1683 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1684 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1685 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1686 | /* |
| 1687 | * Ensure we process the state changes in the same order |
| 1688 | * in which the server processed them by delaying the |
| 1689 | * update of the stateid until we are in sequence. |
| 1690 | */ |
| 1691 | write_sequnlock(&state->seqlock); |
| 1692 | spin_unlock(&state->owner->so_lock); |
| 1693 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1694 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1695 | |
zhouchuangao | 1fbbcd1 | 2021-05-09 19:34:37 -0700 | [diff] [blame] | 1696 | if (!fatal_signal_pending(current)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1697 | if (schedule_timeout(5*HZ) == 0) |
| 1698 | status = -EAGAIN; |
| 1699 | else |
| 1700 | status = 0; |
| 1701 | } else |
| 1702 | status = -EINTR; |
| 1703 | finish_wait(&state->waitq, &wait); |
| 1704 | rcu_read_lock(); |
| 1705 | spin_lock(&state->owner->so_lock); |
| 1706 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1707 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1708 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1709 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1710 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1711 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1712 | nfs_test_and_clear_all_open_stateid(state); |
| 1713 | } |
| 1714 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1715 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1716 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1717 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1718 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1719 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1720 | } |
| 1721 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1722 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1723 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1724 | fmode_t fmode, |
| 1725 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1727 | /* |
| 1728 | * Protect the call to nfs4_state_set_mode_locked and |
| 1729 | * serialise the stateid update |
| 1730 | */ |
| 1731 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1732 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1733 | switch (fmode) { |
| 1734 | case FMODE_READ: |
| 1735 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1736 | break; |
| 1737 | case FMODE_WRITE: |
| 1738 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1739 | break; |
| 1740 | case FMODE_READ|FMODE_WRITE: |
| 1741 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1742 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1743 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1744 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1745 | } |
| 1746 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1747 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1748 | { |
| 1749 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1750 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1751 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1752 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1753 | } |
| 1754 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1755 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1756 | const nfs4_stateid *deleg_stateid, |
| 1757 | fmode_t fmode) |
| 1758 | { |
| 1759 | /* |
| 1760 | * Protect the call to nfs4_state_set_mode_locked and |
| 1761 | * serialise the stateid update |
| 1762 | */ |
| 1763 | write_seqlock(&state->seqlock); |
| 1764 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1765 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1766 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1769 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1770 | { |
| 1771 | write_seqlock(&state->seqlock); |
| 1772 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1773 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1774 | write_sequnlock(&state->seqlock); |
| 1775 | } |
| 1776 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1777 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1778 | const nfs4_stateid *open_stateid, |
| 1779 | const nfs4_stateid *delegation, |
| 1780 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1781 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1782 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1783 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1784 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1785 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1786 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1787 | int ret = 0; |
| 1788 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1789 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1790 | |
| 1791 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1792 | spin_lock(&state->owner->so_lock); |
| 1793 | if (open_stateid != NULL) { |
| 1794 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1795 | ret = 1; |
| 1796 | } |
| 1797 | |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1798 | deleg_cur = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1799 | if (deleg_cur == NULL) |
| 1800 | goto no_delegation; |
| 1801 | |
| 1802 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1803 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1804 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1805 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1806 | goto no_delegation_unlock; |
| 1807 | |
| 1808 | if (delegation == NULL) |
| 1809 | delegation = &deleg_cur->stateid; |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1810 | else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1811 | goto no_delegation_unlock; |
| 1812 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1813 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1814 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1815 | ret = 1; |
| 1816 | no_delegation_unlock: |
| 1817 | spin_unlock(&deleg_cur->lock); |
| 1818 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1819 | if (ret) |
| 1820 | update_open_stateflags(state, fmode); |
| 1821 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1822 | rcu_read_unlock(); |
| 1823 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1824 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1825 | nfs4_schedule_state_manager(clp); |
| 1826 | if (freeme.type != 0) |
| 1827 | nfs4_test_and_free_stateid(server, &freeme, |
| 1828 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1829 | |
| 1830 | return ret; |
| 1831 | } |
| 1832 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1833 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1834 | const nfs4_stateid *stateid) |
| 1835 | { |
| 1836 | struct nfs4_state *state = lsp->ls_state; |
| 1837 | bool ret = false; |
| 1838 | |
| 1839 | spin_lock(&state->state_lock); |
| 1840 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1841 | goto out_noupdate; |
| 1842 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1843 | goto out_noupdate; |
| 1844 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1845 | ret = true; |
| 1846 | out_noupdate: |
| 1847 | spin_unlock(&state->state_lock); |
| 1848 | return ret; |
| 1849 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1850 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1851 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1852 | { |
| 1853 | struct nfs_delegation *delegation; |
| 1854 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1855 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1856 | rcu_read_lock(); |
Trond Myklebust | 40e6aa1 | 2019-10-27 13:38:45 -0400 | [diff] [blame] | 1857 | delegation = nfs4_get_valid_delegation(inode); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1858 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1859 | rcu_read_unlock(); |
| 1860 | return; |
| 1861 | } |
| 1862 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1863 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1864 | } |
| 1865 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1866 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1867 | { |
| 1868 | struct nfs4_state *state = opendata->state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1869 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1870 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1871 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1872 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1873 | nfs4_stateid stateid; |
| 1874 | int ret = -EAGAIN; |
| 1875 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1876 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1877 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1878 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1879 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1880 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1881 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1882 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1883 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1884 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 1885 | delegation = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1886 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1887 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1888 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1889 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1890 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1891 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1892 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1893 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1894 | if (!opendata->is_recover) { |
| 1895 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1896 | if (ret != 0) |
| 1897 | goto out; |
| 1898 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1899 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1900 | |
| 1901 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1902 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1903 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1904 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1905 | out: |
| 1906 | return ERR_PTR(ret); |
| 1907 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1908 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1909 | return state; |
| 1910 | } |
| 1911 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1912 | static void |
| 1913 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1914 | { |
| 1915 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1916 | struct nfs_delegation *delegation; |
| 1917 | int delegation_flags = 0; |
| 1918 | |
| 1919 | rcu_read_lock(); |
| 1920 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1921 | if (delegation) |
| 1922 | delegation_flags = delegation->flags; |
| 1923 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1924 | switch (data->o_arg.claim) { |
| 1925 | default: |
| 1926 | break; |
| 1927 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1928 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1929 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1930 | "returning a delegation for " |
| 1931 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1932 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1933 | return; |
| 1934 | } |
| 1935 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1936 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1937 | data->owner->so_cred, |
| 1938 | data->o_res.delegation_type, |
| 1939 | &data->o_res.delegation, |
| 1940 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1941 | else |
| 1942 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1943 | data->owner->so_cred, |
| 1944 | data->o_res.delegation_type, |
| 1945 | &data->o_res.delegation, |
| 1946 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1947 | |
| 1948 | if (data->o_res.do_recall) |
| 1949 | nfs_async_inode_return_delegation(state->inode, |
| 1950 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | /* |
| 1954 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1955 | * and update the nfs4_state. |
| 1956 | */ |
| 1957 | static struct nfs4_state * |
| 1958 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1959 | { |
| 1960 | struct inode *inode = data->state->inode; |
| 1961 | struct nfs4_state *state = data->state; |
| 1962 | int ret; |
| 1963 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1964 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1965 | if (data->rpc_status) |
| 1966 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1967 | /* cached opens have already been processed */ |
| 1968 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1969 | } |
| 1970 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1971 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1972 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1973 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1974 | |
| 1975 | if (data->o_res.delegation_type != 0) |
| 1976 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1977 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1978 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1979 | NULL, data->o_arg.fmode)) |
| 1980 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1981 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1982 | |
| 1983 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1984 | } |
| 1985 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1986 | static struct inode * |
| 1987 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1988 | { |
| 1989 | struct inode *inode; |
| 1990 | |
| 1991 | switch (data->o_arg.claim) { |
| 1992 | case NFS4_OPEN_CLAIM_NULL: |
| 1993 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1994 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1995 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1996 | return ERR_PTR(-EAGAIN); |
| 1997 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1998 | &data->f_attr, data->f_label); |
| 1999 | break; |
| 2000 | default: |
| 2001 | inode = d_inode(data->dentry); |
| 2002 | ihold(inode); |
| 2003 | nfs_refresh_inode(inode, &data->f_attr); |
| 2004 | } |
| 2005 | return inode; |
| 2006 | } |
| 2007 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2008 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2009 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 2010 | { |
| 2011 | struct nfs4_state *state; |
| 2012 | struct inode *inode; |
| 2013 | |
| 2014 | inode = nfs4_opendata_get_inode(data); |
| 2015 | if (IS_ERR(inode)) |
| 2016 | return ERR_CAST(inode); |
| 2017 | if (data->state != NULL && data->state->inode == inode) { |
| 2018 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2019 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2020 | } else |
| 2021 | state = nfs4_get_open_state(inode, data->owner); |
| 2022 | iput(inode); |
| 2023 | if (state == NULL) |
| 2024 | state = ERR_PTR(-ENOMEM); |
| 2025 | return state; |
| 2026 | } |
| 2027 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2028 | static struct nfs4_state * |
| 2029 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2030 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2031 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2032 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2033 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2034 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2035 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2036 | goto out; |
| 2037 | } |
| 2038 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2039 | state = nfs4_opendata_find_nfs4_state(data); |
| 2040 | if (IS_ERR(state)) |
| 2041 | goto out; |
| 2042 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2043 | if (data->o_res.delegation_type != 0) |
| 2044 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 2045 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 2046 | NULL, data->o_arg.fmode)) { |
| 2047 | nfs4_put_open_state(state); |
| 2048 | state = ERR_PTR(-EAGAIN); |
| 2049 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2050 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 2051 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2052 | return state; |
| 2053 | } |
| 2054 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2055 | static struct nfs4_state * |
| 2056 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2057 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2058 | struct nfs4_state *ret; |
| 2059 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2060 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2061 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2062 | else |
| 2063 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2064 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2065 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2066 | } |
| 2067 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2068 | static struct nfs_open_context * |
| 2069 | nfs4_state_find_open_context_mode(struct nfs4_state *state, fmode_t mode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2070 | { |
| 2071 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2072 | struct nfs_open_context *ctx; |
| 2073 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2074 | rcu_read_lock(); |
| 2075 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2076 | if (ctx->state != state) |
| 2077 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2078 | if ((ctx->mode & mode) != mode) |
| 2079 | continue; |
| 2080 | if (!get_nfs_open_context(ctx)) |
| 2081 | continue; |
| 2082 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2083 | return ctx; |
| 2084 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2085 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2086 | return ERR_PTR(-ENOENT); |
| 2087 | } |
| 2088 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2089 | static struct nfs_open_context * |
| 2090 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2091 | { |
| 2092 | struct nfs_open_context *ctx; |
| 2093 | |
| 2094 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2095 | if (!IS_ERR(ctx)) |
| 2096 | return ctx; |
| 2097 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2098 | if (!IS_ERR(ctx)) |
| 2099 | return ctx; |
| 2100 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2101 | } |
| 2102 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2103 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2104 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2105 | { |
| 2106 | struct nfs4_opendata *opendata; |
| 2107 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2108 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2109 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2110 | if (opendata == NULL) |
| 2111 | return ERR_PTR(-ENOMEM); |
| 2112 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2113 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2114 | return opendata; |
| 2115 | } |
| 2116 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2117 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2118 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2119 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2120 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2121 | int ret; |
| 2122 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2123 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2124 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2125 | opendata->o_arg.open_flags = 0; |
| 2126 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2127 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2128 | NFS_SB(opendata->dentry->d_sb), |
| 2129 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2130 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2131 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2132 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2133 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2134 | if (ret != 0) |
| 2135 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2136 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2137 | if (IS_ERR(newstate)) |
| 2138 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2139 | if (newstate != opendata->state) |
| 2140 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2141 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2142 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2146 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2147 | int ret; |
| 2148 | |
| 2149 | /* memory barrier prior to reading state->n_* */ |
| 2150 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2151 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2152 | if (ret != 0) |
| 2153 | return ret; |
| 2154 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2155 | if (ret != 0) |
| 2156 | return ret; |
| 2157 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2158 | if (ret != 0) |
| 2159 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2160 | /* |
| 2161 | * We may have performed cached opens for all three recoveries. |
| 2162 | * Check if we need to update the current stateid. |
| 2163 | */ |
| 2164 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2165 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2166 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2167 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2168 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2169 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2170 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2171 | return 0; |
| 2172 | } |
| 2173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | /* |
| 2175 | * OPEN_RECLAIM: |
| 2176 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2178 | 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] | 2179 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2180 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2181 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2182 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | int status; |
| 2184 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2185 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2186 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2187 | if (IS_ERR(opendata)) |
| 2188 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2189 | rcu_read_lock(); |
| 2190 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2191 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2192 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2193 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2194 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2195 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2196 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | return status; |
| 2198 | } |
| 2199 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2200 | 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] | 2201 | { |
| 2202 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2203 | struct nfs4_exception exception = { }; |
| 2204 | int err; |
| 2205 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2206 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2207 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2208 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2209 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2210 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | } while (exception.retry); |
| 2214 | return err; |
| 2215 | } |
| 2216 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2217 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2218 | { |
| 2219 | struct nfs_open_context *ctx; |
| 2220 | int ret; |
| 2221 | |
| 2222 | ctx = nfs4_state_find_open_context(state); |
| 2223 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2224 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2225 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2226 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2227 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2228 | put_nfs_open_context(ctx); |
| 2229 | return ret; |
| 2230 | } |
| 2231 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2232 | 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] | 2233 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2234 | switch (err) { |
| 2235 | default: |
| 2236 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2237 | "%d.\n", __func__, err); |
| 2238 | case 0: |
| 2239 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2240 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2241 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2242 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2243 | break; |
| 2244 | case -NFS4ERR_BADSESSION: |
| 2245 | case -NFS4ERR_BADSLOT: |
| 2246 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2247 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2248 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2249 | return -EAGAIN; |
| 2250 | case -NFS4ERR_STALE_CLIENTID: |
| 2251 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2252 | /* Don't recall a delegation if it was lost */ |
| 2253 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2254 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2255 | case -NFS4ERR_MOVED: |
| 2256 | nfs4_schedule_migration_recovery(server); |
| 2257 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2258 | case -NFS4ERR_LEASE_MOVED: |
| 2259 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2260 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2261 | case -NFS4ERR_DELEG_REVOKED: |
| 2262 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2263 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2264 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2265 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2266 | nfs_inode_find_state_and_recover(state->inode, |
| 2267 | stateid); |
| 2268 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2269 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2270 | case -NFS4ERR_DELAY: |
| 2271 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2272 | ssleep(1); |
| 2273 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2274 | case -ENOMEM: |
| 2275 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2276 | if (fl) { |
| 2277 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2278 | if (lsp) |
| 2279 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2280 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2281 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2282 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | return err; |
| 2284 | } |
| 2285 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2286 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2287 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2288 | { |
| 2289 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2290 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2291 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2292 | |
| 2293 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2294 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2295 | if (IS_ERR(opendata)) |
| 2296 | return PTR_ERR(opendata); |
| 2297 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2298 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2299 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2300 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2301 | goto out; |
| 2302 | } |
| 2303 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2304 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2305 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2306 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2307 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2308 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2309 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2310 | if (err) |
| 2311 | goto out; |
| 2312 | } |
| 2313 | nfs_state_clear_delegation(state); |
| 2314 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2315 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2316 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2317 | } |
| 2318 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2319 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2320 | { |
| 2321 | struct nfs4_opendata *data = calldata; |
| 2322 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2323 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2324 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2325 | } |
| 2326 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2327 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2328 | { |
| 2329 | struct nfs4_opendata *data = calldata; |
| 2330 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2331 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2332 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2333 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2334 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2335 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2336 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2337 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2338 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2339 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | static void nfs4_open_confirm_release(void *calldata) |
| 2343 | { |
| 2344 | struct nfs4_opendata *data = calldata; |
| 2345 | struct nfs4_state *state = NULL; |
| 2346 | |
| 2347 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2348 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2349 | goto out_free; |
| 2350 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2351 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2352 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2353 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2354 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2355 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2356 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2357 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2361 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2362 | .rpc_call_done = nfs4_open_confirm_done, |
| 2363 | .rpc_release = nfs4_open_confirm_release, |
| 2364 | }; |
| 2365 | |
| 2366 | /* |
| 2367 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2368 | */ |
| 2369 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2370 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2371 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2372 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2373 | struct rpc_message msg = { |
| 2374 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2375 | .rpc_argp = &data->c_arg, |
| 2376 | .rpc_resp = &data->c_res, |
| 2377 | .rpc_cred = data->owner->so_cred, |
| 2378 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2379 | struct rpc_task_setup task_setup_data = { |
| 2380 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2381 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2382 | .callback_ops = &nfs4_open_confirm_ops, |
| 2383 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2384 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2385 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2386 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | int status; |
| 2388 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2389 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2390 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2391 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2392 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2393 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2394 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2395 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2396 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2397 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2398 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2399 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2400 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2401 | smp_wmb(); |
| 2402 | } else |
| 2403 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2404 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | return status; |
| 2406 | } |
| 2407 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2408 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2410 | struct nfs4_opendata *data = calldata; |
| 2411 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2412 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2413 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2414 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2415 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2416 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2417 | /* |
| 2418 | * Check if we still need to send an OPEN call, or if we can use |
| 2419 | * a delegation instead. |
| 2420 | */ |
| 2421 | if (data->state != NULL) { |
| 2422 | struct nfs_delegation *delegation; |
| 2423 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2424 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2425 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2426 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2427 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 2428 | delegation = nfs4_get_valid_delegation(data->state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2429 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2430 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2431 | rcu_read_unlock(); |
| 2432 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2433 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2434 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2435 | switch (claim) { |
| 2436 | default: |
| 2437 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2438 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2439 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2440 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2441 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2442 | fallthrough; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2443 | case NFS4_OPEN_CLAIM_FH: |
| 2444 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2445 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2446 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2447 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2448 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2449 | &data->o_res.seq_res, |
| 2450 | task) != 0) |
| 2451 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2452 | |
| 2453 | /* Set the create mode (note dependency on the session type) */ |
| 2454 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2455 | if (data->o_arg.open_flags & O_EXCL) { |
| 2456 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2457 | if (nfs4_has_persistent_session(clp)) |
| 2458 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2459 | else if (clp->cl_mvops->minor_version > 0) |
| 2460 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2461 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2462 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2463 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2464 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2465 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2466 | out_no_action: |
| 2467 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2468 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2469 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2470 | } |
| 2471 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2472 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2473 | { |
| 2474 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2476 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2477 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2478 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2479 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2480 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2481 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2482 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2483 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2484 | case S_IFREG: |
| 2485 | break; |
| 2486 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2487 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2488 | break; |
| 2489 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2490 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2491 | break; |
| 2492 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2493 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2494 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2495 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2496 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2497 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2498 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2499 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2500 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2501 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2502 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2503 | static void nfs4_open_release(void *calldata) |
| 2504 | { |
| 2505 | struct nfs4_opendata *data = calldata; |
| 2506 | struct nfs4_state *state = NULL; |
| 2507 | |
| 2508 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2509 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2510 | goto out_free; |
| 2511 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2512 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2513 | goto out_free; |
| 2514 | /* In case we need an open_confirm, no cleanup! */ |
| 2515 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2516 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2517 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2518 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2519 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2520 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2521 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2525 | .rpc_call_prepare = nfs4_open_prepare, |
| 2526 | .rpc_call_done = nfs4_open_done, |
| 2527 | .rpc_release = nfs4_open_release, |
| 2528 | }; |
| 2529 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2530 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2531 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2532 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2533 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2534 | struct nfs_server *server = NFS_SERVER(dir); |
| 2535 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2536 | struct nfs_openres *o_res = &data->o_res; |
| 2537 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2538 | struct rpc_message msg = { |
| 2539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2540 | .rpc_argp = o_arg, |
| 2541 | .rpc_resp = o_res, |
| 2542 | .rpc_cred = data->owner->so_cred, |
| 2543 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2544 | struct rpc_task_setup task_setup_data = { |
| 2545 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2546 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2547 | .callback_ops = &nfs4_open_ops, |
| 2548 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2549 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2550 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2551 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2552 | int status; |
| 2553 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2554 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2555 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2556 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2557 | data->cancelled = false; |
| 2558 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2559 | if (!ctx) { |
| 2560 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1, 1); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2561 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2562 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2563 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2564 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1, 0); |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2565 | pnfs_lgopen_prepare(data, ctx); |
| 2566 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2567 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2568 | if (IS_ERR(task)) |
| 2569 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2570 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2571 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2572 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2573 | smp_wmb(); |
| 2574 | } else |
| 2575 | status = data->rpc_status; |
| 2576 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2577 | |
| 2578 | return status; |
| 2579 | } |
| 2580 | |
| 2581 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2582 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2583 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2584 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2585 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2586 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2587 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2588 | if (status != 0 || !data->rpc_done) |
| 2589 | return status; |
| 2590 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2591 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2592 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2593 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2594 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2595 | |
| 2596 | return status; |
| 2597 | } |
| 2598 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2599 | /* |
| 2600 | * Additional permission checks in order to distinguish between an |
| 2601 | * open for read, and an open for execute. This works around the |
| 2602 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2603 | * the same. |
| 2604 | * Note that in the non-execute case, we want to turn off permission |
| 2605 | * checking if we just created a new file (POSIX open() semantics). |
| 2606 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2607 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2608 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2609 | struct nfs4_state *state, fmode_t fmode, |
| 2610 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2611 | { |
| 2612 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2613 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2614 | |
| 2615 | /* access call failed or for some reason the server doesn't |
| 2616 | * support any access modes -- defer access call until later */ |
| 2617 | if (opendata->o_res.access_supported == 0) |
| 2618 | return 0; |
| 2619 | |
| 2620 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2621 | /* |
| 2622 | * Use openflags to check for exec, because fmode won't |
| 2623 | * always have FMODE_EXEC set when file open for exec. |
| 2624 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2625 | if (openflags & __FMODE_EXEC) { |
| 2626 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2627 | if (S_ISDIR(state->inode->i_mode)) |
| 2628 | mask = NFS4_ACCESS_LOOKUP; |
| 2629 | else |
| 2630 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2631 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2632 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2633 | |
| 2634 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2635 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2636 | nfs_access_add_cache(state->inode, &cache); |
| 2637 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2638 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2639 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2640 | return 0; |
| 2641 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2642 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2643 | } |
| 2644 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2645 | /* |
| 2646 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2647 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2648 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2649 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2650 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2651 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2652 | struct nfs_server *server = NFS_SERVER(dir); |
| 2653 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2654 | struct nfs_openres *o_res = &data->o_res; |
| 2655 | int status; |
| 2656 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2657 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2658 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2659 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2660 | if (status != 0) { |
| 2661 | if (status == -NFS4ERR_BADNAME && |
| 2662 | !(o_arg->open_flags & O_CREAT)) |
| 2663 | return -ENOENT; |
| 2664 | return status; |
| 2665 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2666 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2667 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2668 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2669 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2670 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2671 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2672 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2673 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2674 | if (data->file_created || |
| 2675 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 2676 | nfs4_update_changeattr(dir, &o_res->cinfo, |
| 2677 | o_res->f_attr->time_start, |
| 2678 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2679 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2680 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2681 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2683 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2685 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2687 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2688 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2689 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2690 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2691 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2692 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | /* |
| 2696 | * OPEN_EXPIRED: |
| 2697 | * reclaim state on the server after a network partition. |
| 2698 | * Assumes caller holds the appropriate lock |
| 2699 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2700 | 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] | 2701 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2702 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2703 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2705 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2706 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2707 | if (IS_ERR(opendata)) |
| 2708 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2709 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2710 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2711 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2712 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2713 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2716 | 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] | 2717 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2718 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2719 | struct nfs4_exception exception = { }; |
| 2720 | int err; |
| 2721 | |
| 2722 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2723 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2724 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2725 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2726 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2727 | switch (err) { |
| 2728 | default: |
| 2729 | goto out; |
| 2730 | case -NFS4ERR_GRACE: |
| 2731 | case -NFS4ERR_DELAY: |
| 2732 | nfs4_handle_exception(server, err, &exception); |
| 2733 | err = 0; |
| 2734 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2735 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2736 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2737 | return err; |
| 2738 | } |
| 2739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2741 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2743 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2745 | ctx = nfs4_state_find_open_context(state); |
| 2746 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2747 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2748 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2749 | put_nfs_open_context(ctx); |
| 2750 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2753 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2754 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2755 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2756 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2757 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2761 | { |
| 2762 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2763 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2767 | { |
| 2768 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2769 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2770 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2771 | return nfs4_open_expired(sp, state); |
| 2772 | } |
| 2773 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2774 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2775 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2776 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2777 | { |
| 2778 | return -NFS4ERR_BAD_STATEID; |
| 2779 | } |
| 2780 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2781 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2782 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2783 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2784 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2785 | { |
| 2786 | int status; |
| 2787 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2788 | switch (stateid->type) { |
| 2789 | default: |
| 2790 | break; |
| 2791 | case NFS4_INVALID_STATEID_TYPE: |
| 2792 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2793 | return -NFS4ERR_BAD_STATEID; |
| 2794 | case NFS4_REVOKED_STATEID_TYPE: |
| 2795 | goto out_free; |
| 2796 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2797 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2798 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2799 | switch (status) { |
| 2800 | case -NFS4ERR_EXPIRED: |
| 2801 | case -NFS4ERR_ADMIN_REVOKED: |
| 2802 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2803 | break; |
| 2804 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2805 | return status; |
| 2806 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2807 | out_free: |
| 2808 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2809 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2810 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2811 | } |
| 2812 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2813 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2814 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2815 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2816 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2817 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2818 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2819 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2820 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2821 | /* Get the delegation credential for use by test/free_stateid */ |
| 2822 | rcu_read_lock(); |
| 2823 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2824 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2825 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2826 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2827 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2828 | } |
| 2829 | |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2830 | spin_lock(&delegation->lock); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2831 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2832 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2833 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2834 | &delegation->flags)) { |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2835 | spin_unlock(&delegation->lock); |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2836 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2837 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2838 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2839 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2840 | if (delegation->cred) |
| 2841 | cred = get_cred(delegation->cred); |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2842 | spin_unlock(&delegation->lock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2843 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2844 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2845 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2846 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2847 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2848 | else |
| 2849 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2850 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2851 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2852 | return ret; |
| 2853 | } |
| 2854 | |
| 2855 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2856 | { |
| 2857 | nfs4_stateid tmp; |
| 2858 | |
| 2859 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2860 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2861 | &tmp, NULL) && |
| 2862 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2863 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2864 | else |
| 2865 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2869 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2870 | * |
| 2871 | * @state: NFSv4 state for an inode |
| 2872 | * |
| 2873 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2874 | * Otherwise a negative NFS4ERR value is returned. |
| 2875 | */ |
| 2876 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2877 | { |
| 2878 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2879 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2880 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2881 | |
| 2882 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2883 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2884 | |
| 2885 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2886 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2887 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2888 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2889 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2890 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2891 | spin_unlock(&state->state_lock); |
| 2892 | |
| 2893 | nfs4_put_lock_state(prev); |
| 2894 | prev = lsp; |
| 2895 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2896 | status = nfs41_test_and_free_expired_stateid(server, |
| 2897 | &lsp->ls_stateid, |
| 2898 | cred); |
| 2899 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2900 | if (status == -NFS4ERR_EXPIRED || |
| 2901 | status == -NFS4ERR_BAD_STATEID) { |
| 2902 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2903 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2904 | if (!recover_lost_locks) |
| 2905 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2906 | } else if (status != NFS_OK) { |
| 2907 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2908 | nfs4_put_lock_state(prev); |
| 2909 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2910 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2911 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2912 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2913 | } |
| 2914 | spin_unlock(&state->state_lock); |
| 2915 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2916 | out: |
| 2917 | return ret; |
| 2918 | } |
| 2919 | |
| 2920 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2921 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2922 | * |
| 2923 | * @state: NFSv4 state for an inode |
| 2924 | * |
| 2925 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2926 | * Otherwise a negative NFS4ERR value is returned. |
| 2927 | */ |
| 2928 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2929 | { |
| 2930 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2931 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2932 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2933 | int status; |
| 2934 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2935 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2936 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2937 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2938 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2939 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2940 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2941 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2942 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2943 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2944 | if (nfs_open_stateid_recover_openmode(state)) |
| 2945 | return -NFS4ERR_OPENMODE; |
| 2946 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2950 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2951 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2952 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2953 | status = nfs41_check_delegation_stateid(state); |
| 2954 | if (status != NFS_OK) |
| 2955 | return status; |
| 2956 | nfs41_delegation_recover_stateid(state); |
| 2957 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2958 | status = nfs41_check_expired_locks(state); |
| 2959 | if (status != NFS_OK) |
| 2960 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2961 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2962 | if (status != NFS_OK) |
| 2963 | status = nfs4_open_expired(sp, state); |
| 2964 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2965 | } |
| 2966 | #endif |
| 2967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2969 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2970 | * fields corresponding to attributes that were used to store the verifier. |
| 2971 | * Make sure we clobber those fields in the later setattr call |
| 2972 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2973 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2974 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2975 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2976 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2977 | __u32 attrset[3]; |
| 2978 | unsigned ret; |
| 2979 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2980 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2981 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2982 | attrset[i] = opendata->o_res.attrset[i]; |
| 2983 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2984 | attrset[i] &= ~bitmask[i]; |
| 2985 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2986 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2987 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2988 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2989 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2990 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2991 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2992 | ret |= ATTR_ATIME_SET; |
| 2993 | else |
| 2994 | ret |= ATTR_ATIME; |
| 2995 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2996 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2997 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2998 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2999 | ret |= ATTR_MTIME_SET; |
| 3000 | else |
| 3001 | ret |= ATTR_MTIME; |
| 3002 | } |
| 3003 | |
| 3004 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3005 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3006 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3009 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3010 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3011 | { |
| 3012 | struct nfs4_state_owner *sp = opendata->owner; |
| 3013 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3014 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3015 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3016 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3017 | struct inode *dir = d_inode(opendata->dir); |
| 3018 | unsigned long dir_verifier; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3019 | unsigned int seq; |
| 3020 | int ret; |
| 3021 | |
| 3022 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3023 | dir_verifier = nfs_save_change_attribute(dir); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3024 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 3025 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 3026 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3027 | goto out; |
| 3028 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 3029 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3030 | ret = PTR_ERR(state); |
| 3031 | if (IS_ERR(state)) |
| 3032 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 3033 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3034 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 3035 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 3036 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 3037 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3038 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3039 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3040 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3041 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3042 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3043 | alias = d_exact_alias(dentry, state->inode); |
| 3044 | if (!alias) |
| 3045 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 3046 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 3047 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3048 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3049 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3050 | } |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | switch(opendata->o_arg.claim) { |
| 3054 | default: |
| 3055 | break; |
| 3056 | case NFS4_OPEN_CLAIM_NULL: |
| 3057 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 3058 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 3059 | if (!opendata->rpc_done) |
| 3060 | break; |
| 3061 | if (opendata->o_res.delegation_type != 0) |
| 3062 | dir_verifier = nfs_save_change_attribute(dir); |
| 3063 | nfs_set_verifier(dentry, dir_verifier); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3064 | } |
| 3065 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 3066 | /* Parse layoutget results before we check for access */ |
| 3067 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 3068 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3069 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 3070 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3071 | if (ret != 0) |
| 3072 | goto out; |
| 3073 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3074 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3075 | nfs_inode_attach_open_context(ctx); |
| 3076 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3077 | nfs4_schedule_stateid_recovery(server, state); |
| 3078 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3079 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3080 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3081 | if (!opendata->cancelled) |
| 3082 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3083 | return ret; |
| 3084 | } |
| 3085 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3086 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3087 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3089 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3090 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3091 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3092 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3093 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | { |
| 3095 | struct nfs4_state_owner *sp; |
| 3096 | struct nfs4_state *state = NULL; |
| 3097 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3098 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3099 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3100 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3101 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3102 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3103 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3104 | struct iattr *sattr = c->sattr; |
| 3105 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3106 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3107 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | |
| 3109 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3111 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3112 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3114 | goto out_err; |
| 3115 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3116 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3117 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3118 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3119 | if (d_really_is_positive(dentry)) |
| 3120 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3121 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3122 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3123 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3124 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3125 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3126 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3127 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3129 | if (label) { |
| 3130 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 3131 | if (IS_ERR(olabel)) { |
| 3132 | status = PTR_ERR(olabel); |
| 3133 | goto err_opendata_put; |
| 3134 | } |
| 3135 | } |
| 3136 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3137 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3138 | if (!opendata->f_attr.mdsthreshold) { |
| 3139 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3140 | if (!opendata->f_attr.mdsthreshold) |
| 3141 | goto err_free_label; |
| 3142 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3143 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3144 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3145 | if (d_really_is_positive(dentry)) |
| 3146 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3147 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3148 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3149 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3150 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3151 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3152 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3153 | 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] | 3154 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3155 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3156 | /* |
| 3157 | * send create attributes which was not set by open |
| 3158 | * with an extra setattr. |
| 3159 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3160 | if (attrs || label) { |
| 3161 | unsigned ia_old = sattr->ia_valid; |
| 3162 | |
| 3163 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3164 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3165 | status = nfs4_do_setattr(state->inode, cred, |
| 3166 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3167 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3168 | if (status == 0) { |
| 3169 | nfs_setattr_update_inode(state->inode, sattr, |
| 3170 | opendata->o_res.f_attr); |
| 3171 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 3172 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3173 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3174 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3175 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3176 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3177 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3178 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3179 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3180 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3181 | opendata->f_attr.mdsthreshold = NULL; |
| 3182 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3183 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3184 | nfs4_label_free(olabel); |
| 3185 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3186 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3189 | err_free_label: |
| 3190 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3191 | err_opendata_put: |
| 3192 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3193 | err_put_state_owner: |
| 3194 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | return status; |
| 3197 | } |
| 3198 | |
| 3199 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3200 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3201 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3202 | int flags, |
| 3203 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3204 | struct nfs4_label *label, |
| 3205 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3207 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3208 | struct nfs4_exception exception = { |
| 3209 | .interruptible = true, |
| 3210 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3212 | struct nfs4_open_createattrs c = { |
| 3213 | .label = label, |
| 3214 | .sattr = sattr, |
| 3215 | .verf = { |
| 3216 | [0] = (__u32)jiffies, |
| 3217 | [1] = (__u32)current->pid, |
| 3218 | }, |
| 3219 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | int status; |
| 3221 | |
| 3222 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3223 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3224 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3225 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | if (status == 0) |
| 3227 | break; |
| 3228 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3229 | * book-keeping w.r.t. state-changing operations |
| 3230 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3231 | * It is actually a sign of a bug on the client or on the server. |
| 3232 | * |
| 3233 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3234 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | * have unhashed the old state_owner for us, and that we can |
| 3236 | * therefore safely retry using a new one. We should still warn |
| 3237 | * the user though... |
| 3238 | */ |
| 3239 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3240 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3241 | " returned a bad sequence-id error!\n", |
| 3242 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | exception.retry = 1; |
| 3244 | continue; |
| 3245 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3246 | /* |
| 3247 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3248 | * state before it received the OPEN_CONFIRM. |
| 3249 | * Recover by retrying the request as per the discussion |
| 3250 | * on Page 181 of RFC3530. |
| 3251 | */ |
| 3252 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3253 | exception.retry = 1; |
| 3254 | continue; |
| 3255 | } |
Robert Milkowski | 924491f | 2020-01-28 08:37:47 +0000 | [diff] [blame] | 3256 | if (status == -NFS4ERR_EXPIRED) { |
| 3257 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 3258 | exception.retry = 1; |
| 3259 | continue; |
| 3260 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3261 | if (status == -EAGAIN) { |
| 3262 | /* We must have found a delegation */ |
| 3263 | exception.retry = 1; |
| 3264 | continue; |
| 3265 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3266 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3267 | continue; |
| 3268 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | status, &exception)); |
| 3270 | } while (exception.retry); |
| 3271 | return res; |
| 3272 | } |
| 3273 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3274 | static int _nfs4_do_setattr(struct inode *inode, |
| 3275 | struct nfs_setattrargs *arg, |
| 3276 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3277 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3278 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3279 | { |
| 3280 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3281 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3283 | .rpc_argp = arg, |
| 3284 | .rpc_resp = res, |
| 3285 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3286 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3287 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3288 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3289 | bool truncate; |
| 3290 | int status; |
| 3291 | |
| 3292 | nfs_fattr_init(res->fattr); |
| 3293 | |
| 3294 | /* Servers should only apply open mode checks for file size changes */ |
| 3295 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3296 | if (!truncate) { |
| 3297 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3298 | goto zero_stateid; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3299 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3300 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3301 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3302 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3303 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3304 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3305 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3306 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3307 | l_ctx = nfs_get_lock_context(ctx); |
| 3308 | if (IS_ERR(l_ctx)) |
| 3309 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3310 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3311 | &arg->stateid, &delegation_cred); |
| 3312 | nfs_put_lock_context(l_ctx); |
| 3313 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3314 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3315 | else if (status == -EAGAIN) |
| 3316 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3317 | } else { |
| 3318 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3319 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3320 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3321 | if (delegation_cred) |
| 3322 | msg.rpc_cred = delegation_cred; |
| 3323 | |
| 3324 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3325 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3326 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3327 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3328 | renew_lease(server, timestamp); |
| 3329 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3330 | return status; |
| 3331 | } |
| 3332 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3333 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3334 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3335 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3336 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3338 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3339 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3340 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3341 | struct nfs_setattrargs arg = { |
| 3342 | .fh = NFS_FH(inode), |
| 3343 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3345 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3346 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3347 | }; |
| 3348 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3350 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3352 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3353 | struct nfs4_exception exception = { |
| 3354 | .state = state, |
| 3355 | .inode = inode, |
| 3356 | .stateid = &arg.stateid, |
| 3357 | }; |
| 3358 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3361 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3362 | nfs4_bitmask(server, olabel), |
| 3363 | inode); |
| 3364 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3365 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3366 | switch (err) { |
| 3367 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3368 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3369 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3370 | "applying open mode checks to " |
| 3371 | "a SETATTR that is not " |
| 3372 | "changing file size.\n", |
| 3373 | server->nfs_client->cl_hostname); |
| 3374 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3375 | if (state && !(state->state & FMODE_WRITE)) { |
| 3376 | err = -EBADF; |
| 3377 | if (sattr->ia_valid & ATTR_OPEN) |
| 3378 | err = -EACCES; |
| 3379 | goto out; |
| 3380 | } |
| 3381 | } |
| 3382 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3384 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | return err; |
| 3386 | } |
| 3387 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3388 | static bool |
| 3389 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3390 | { |
| 3391 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3392 | return false; |
| 3393 | |
| 3394 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3395 | } |
| 3396 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3397 | /* |
| 3398 | * Update the seqid of an open stateid |
| 3399 | */ |
| 3400 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3401 | struct nfs4_state *state) |
| 3402 | { |
| 3403 | __be32 seqid_open; |
| 3404 | u32 dst_seqid; |
| 3405 | int seq; |
| 3406 | |
| 3407 | for (;;) { |
| 3408 | if (!nfs4_valid_open_stateid(state)) |
| 3409 | break; |
| 3410 | seq = read_seqbegin(&state->seqlock); |
| 3411 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3412 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3413 | if (read_seqretry(&state->seqlock, seq)) |
| 3414 | continue; |
| 3415 | break; |
| 3416 | } |
| 3417 | seqid_open = state->open_stateid.seqid; |
| 3418 | if (read_seqretry(&state->seqlock, seq)) |
| 3419 | continue; |
| 3420 | |
| 3421 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3422 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3423 | dst->seqid = seqid_open; |
| 3424 | break; |
| 3425 | } |
| 3426 | } |
| 3427 | |
| 3428 | /* |
| 3429 | * Update the seqid of an open stateid after receiving |
| 3430 | * NFS4ERR_OLD_STATEID |
| 3431 | */ |
| 3432 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3433 | struct nfs4_state *state) |
| 3434 | { |
| 3435 | __be32 seqid_open; |
| 3436 | u32 dst_seqid; |
| 3437 | bool ret; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3438 | int seq, status = -EAGAIN; |
| 3439 | DEFINE_WAIT(wait); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3440 | |
| 3441 | for (;;) { |
| 3442 | ret = false; |
| 3443 | if (!nfs4_valid_open_stateid(state)) |
| 3444 | break; |
| 3445 | seq = read_seqbegin(&state->seqlock); |
| 3446 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3447 | if (read_seqretry(&state->seqlock, seq)) |
| 3448 | continue; |
| 3449 | break; |
| 3450 | } |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3451 | |
| 3452 | write_seqlock(&state->seqlock); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3453 | seqid_open = state->open_stateid.seqid; |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3454 | |
| 3455 | dst_seqid = be32_to_cpu(dst->seqid); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3456 | |
| 3457 | /* Did another OPEN bump the state's seqid? try again: */ |
| 3458 | if ((s32)(be32_to_cpu(seqid_open) - dst_seqid) > 0) { |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3459 | dst->seqid = seqid_open; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3460 | write_sequnlock(&state->seqlock); |
| 3461 | ret = true; |
| 3462 | break; |
| 3463 | } |
| 3464 | |
| 3465 | /* server says we're behind but we haven't seen the update yet */ |
| 3466 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 3467 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 3468 | write_sequnlock(&state->seqlock); |
| 3469 | trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); |
| 3470 | |
zhouchuangao | 1fbbcd1 | 2021-05-09 19:34:37 -0700 | [diff] [blame] | 3471 | if (fatal_signal_pending(current)) |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3472 | status = -EINTR; |
| 3473 | else |
| 3474 | if (schedule_timeout(5*HZ) != 0) |
| 3475 | status = 0; |
| 3476 | |
| 3477 | finish_wait(&state->waitq, &wait); |
| 3478 | |
| 3479 | if (!status) |
| 3480 | continue; |
| 3481 | if (status == -EINTR) |
| 3482 | break; |
| 3483 | |
| 3484 | /* we slept the whole 5 seconds, we must have lost a seqid */ |
| 3485 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3486 | ret = true; |
| 3487 | break; |
| 3488 | } |
| 3489 | |
| 3490 | return ret; |
| 3491 | } |
| 3492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | struct nfs4_closedata { |
| 3494 | struct inode *inode; |
| 3495 | struct nfs4_state *state; |
| 3496 | struct nfs_closeargs arg; |
| 3497 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3498 | struct { |
| 3499 | struct nfs4_layoutreturn_args arg; |
| 3500 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3501 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3502 | u32 roc_barrier; |
| 3503 | bool roc; |
| 3504 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3505 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3506 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | }; |
| 3508 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3509 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3510 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3511 | struct nfs4_closedata *calldata = data; |
| 3512 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3513 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3514 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3515 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3516 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3517 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3518 | nfs4_put_open_state(calldata->state); |
| 3519 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3520 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3521 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3522 | kfree(calldata); |
| 3523 | } |
| 3524 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3525 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3527 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3530 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3531 | struct nfs4_exception exception = { |
| 3532 | .state = state, |
| 3533 | .inode = calldata->inode, |
| 3534 | .stateid = &calldata->arg.stateid, |
| 3535 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3537 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3538 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3539 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3540 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3541 | |
| 3542 | /* Handle Layoutreturn errors */ |
Trond Myklebust | f128de1 | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 3543 | if (pnfs_roc_done(task, &calldata->arg.lr_args, &calldata->res.lr_res, |
| 3544 | &calldata->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3545 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3546 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3547 | /* 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] | 3548 | * the state_owner. we keep this around to process errors |
| 3549 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | switch (task->tk_status) { |
| 3551 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3552 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3553 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3554 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3555 | case -NFS4ERR_ACCESS: |
| 3556 | if (calldata->arg.bitmask != NULL) { |
| 3557 | calldata->arg.bitmask = NULL; |
| 3558 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3559 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3560 | |
| 3561 | } |
| 3562 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3563 | case -NFS4ERR_OLD_STATEID: |
| 3564 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3565 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3566 | state)) |
| 3567 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3568 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3569 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3571 | case -NFS4ERR_EXPIRED: |
| 3572 | nfs4_free_revoked_stateid(server, |
| 3573 | &calldata->arg.stateid, |
| 3574 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3575 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3576 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3577 | if (calldata->arg.fmode == 0) |
| 3578 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3579 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3581 | task->tk_status = nfs4_async_handle_exception(task, |
| 3582 | server, task->tk_status, &exception); |
| 3583 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3584 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3586 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3587 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3588 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3589 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3590 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3591 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3592 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3593 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3594 | out_restart: |
| 3595 | task->tk_status = 0; |
| 3596 | rpc_restart_call_prepare(task); |
| 3597 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | } |
| 3599 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3600 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3602 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3603 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3604 | struct inode *inode = calldata->inode; |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3605 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3606 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3607 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3608 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3609 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3610 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3611 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3612 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3613 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3614 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3615 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3616 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3617 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3618 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3619 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3620 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3621 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3622 | if (state->n_rdonly == 0) |
| 3623 | call_close |= is_rdonly; |
| 3624 | else if (is_rdonly) |
| 3625 | calldata->arg.fmode |= FMODE_READ; |
| 3626 | if (state->n_wronly == 0) |
| 3627 | call_close |= is_wronly; |
| 3628 | else if (is_wronly) |
| 3629 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3630 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3631 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3632 | } else if (is_rdwr) |
| 3633 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3634 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3635 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3636 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3637 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3638 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3639 | |
| 3640 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3641 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3642 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3643 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3644 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3645 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3646 | nfs_release_seqid(calldata->arg.seqid); |
| 3647 | goto out_wait; |
| 3648 | } |
| 3649 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3650 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3651 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3652 | calldata->arg.lr_args = NULL; |
| 3653 | calldata->res.lr_res = NULL; |
| 3654 | } |
| 3655 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3656 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3657 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3658 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3659 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3660 | /* Close-to-open cache consistency revalidation */ |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3661 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3662 | nfs4_bitmask_set(calldata->arg.bitmask_store, |
| 3663 | server->cache_consistency_bitmask, |
| 3664 | inode, server, NULL); |
| 3665 | calldata->arg.bitmask = calldata->arg.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3666 | } else |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3667 | calldata->arg.bitmask = NULL; |
| 3668 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3669 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3670 | calldata->arg.share_access = |
| 3671 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3672 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3673 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3674 | if (calldata->res.fattr == NULL) |
| 3675 | calldata->arg.bitmask = NULL; |
| 3676 | else if (calldata->arg.bitmask == NULL) |
| 3677 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3678 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3679 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3680 | &calldata->arg.seq_args, |
| 3681 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3682 | task) != 0) |
| 3683 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3684 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3685 | return; |
| 3686 | out_no_action: |
| 3687 | task->tk_action = NULL; |
| 3688 | out_wait: |
| 3689 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | } |
| 3691 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3692 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3693 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3694 | .rpc_call_done = nfs4_close_done, |
| 3695 | .rpc_release = nfs4_free_closedata, |
| 3696 | }; |
| 3697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | /* |
| 3699 | * It is possible for data to be read/written from a mem-mapped file |
| 3700 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3701 | * This means that we can't safely call nfsv4 close on a file until |
| 3702 | * the inode is cleared. This in turn means that we are not good |
| 3703 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3704 | * share state even when we are done with one of the three share |
| 3705 | * stateid's in the inode. |
| 3706 | * |
| 3707 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3708 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3709 | 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] | 3710 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3711 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3712 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3714 | struct nfs4_state_owner *sp = state->owner; |
| 3715 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3716 | struct rpc_message msg = { |
| 3717 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3718 | .rpc_cred = state->owner->so_cred, |
| 3719 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3720 | struct rpc_task_setup task_setup_data = { |
| 3721 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3722 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3723 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3724 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 3725 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3726 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3727 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3729 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3730 | &task_setup_data.rpc_client, &msg); |
| 3731 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3732 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3734 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3735 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1, 0); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3736 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3738 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3739 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3740 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3742 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3743 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3744 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3745 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3746 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3747 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3748 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3749 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3750 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3751 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3752 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3753 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3754 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3755 | if (calldata->lr.roc) { |
| 3756 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3757 | calldata->res.lr_res = &calldata->lr.res; |
| 3758 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3759 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3760 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3761 | msg.rpc_argp = &calldata->arg; |
| 3762 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3763 | task_setup_data.callback_data = calldata; |
| 3764 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3765 | if (IS_ERR(task)) |
| 3766 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3767 | status = 0; |
| 3768 | if (wait) |
| 3769 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3770 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3771 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3772 | out_free_calldata: |
| 3773 | kfree(calldata); |
| 3774 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3775 | nfs4_put_open_state(state); |
| 3776 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3777 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3780 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3781 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3782 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3785 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3786 | |
| 3787 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3789 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3790 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3791 | |
| 3792 | nfs4_label_release_security(label); |
| 3793 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3794 | if (IS_ERR(state)) |
| 3795 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3796 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3799 | 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] | 3800 | { |
| 3801 | if (ctx->state == NULL) |
| 3802 | return; |
| 3803 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3804 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3805 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3806 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3809 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3810 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Frank van der Linden | b78ef84 | 2020-06-23 22:38:55 +0000 | [diff] [blame] | 3811 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3814 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3815 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3816 | struct nfs4_server_caps_arg args = { |
| 3817 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3818 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3819 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | struct nfs4_server_caps_res res = {}; |
| 3821 | struct rpc_message msg = { |
| 3822 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3823 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | .rpc_resp = &res, |
| 3825 | }; |
| 3826 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3827 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3829 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3830 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3831 | FATTR4_WORD0_LINK_SUPPORT | |
| 3832 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3833 | FATTR4_WORD0_ACLSUPPORT; |
| 3834 | if (minorversion) |
| 3835 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3836 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3837 | 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] | 3838 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3839 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3840 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3841 | case 0: |
| 3842 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3843 | res.attr_bitmask[2] = 0; |
| 3844 | break; |
| 3845 | case 1: |
| 3846 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3847 | break; |
| 3848 | case 2: |
| 3849 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3850 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3852 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3853 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3854 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3855 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3856 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3857 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3858 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3859 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | server->caps |= NFS_CAP_ACLS; |
| 3861 | if (res.has_links != 0) |
| 3862 | server->caps |= NFS_CAP_HARDLINKS; |
| 3863 | if (res.has_symlinks != 0) |
| 3864 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3865 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3866 | server->caps |= NFS_CAP_FILEID; |
| 3867 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3868 | server->caps |= NFS_CAP_MODE; |
| 3869 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3870 | server->caps |= NFS_CAP_NLINK; |
| 3871 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3872 | server->caps |= NFS_CAP_OWNER; |
| 3873 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3874 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3875 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3876 | server->caps |= NFS_CAP_ATIME; |
| 3877 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3878 | server->caps |= NFS_CAP_CTIME; |
| 3879 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3880 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3881 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3882 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3883 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3884 | #endif |
| 3885 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3886 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3887 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3888 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3889 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3890 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3891 | 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] | 3892 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3893 | |
| 3894 | /* Avoid a regression due to buggy server */ |
| 3895 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3896 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3897 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3898 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3901 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | return status; |
| 3905 | } |
| 3906 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3907 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3909 | struct nfs4_exception exception = { |
| 3910 | .interruptible = true, |
| 3911 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | int err; |
| 3913 | do { |
| 3914 | err = nfs4_handle_exception(server, |
| 3915 | _nfs4_server_capabilities(server, fhandle), |
| 3916 | &exception); |
| 3917 | } while (exception.retry); |
| 3918 | return err; |
| 3919 | } |
| 3920 | |
| 3921 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3922 | struct nfs_fsinfo *info) |
| 3923 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3924 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3926 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | }; |
| 3928 | struct nfs4_lookup_res res = { |
| 3929 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3930 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | .fh = fhandle, |
| 3932 | }; |
| 3933 | struct rpc_message msg = { |
| 3934 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3935 | .rpc_argp = &args, |
| 3936 | .rpc_resp = &res, |
| 3937 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3938 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3939 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3940 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3941 | /* |
| 3942 | * Process the label in the upcoming getfattr |
| 3943 | */ |
| 3944 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3945 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3946 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3947 | 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] | 3948 | } |
| 3949 | |
| 3950 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3951 | struct nfs_fsinfo *info) |
| 3952 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3953 | struct nfs4_exception exception = { |
| 3954 | .interruptible = true, |
| 3955 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | int err; |
| 3957 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3958 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3959 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3960 | switch (err) { |
| 3961 | case 0: |
| 3962 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3963 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3964 | default: |
| 3965 | err = nfs4_handle_exception(server, err, &exception); |
| 3966 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3968 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | return err; |
| 3970 | } |
| 3971 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3972 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3973 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3974 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3975 | struct rpc_auth_create_args auth_args = { |
| 3976 | .pseudoflavor = flavor, |
| 3977 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3978 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3979 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3980 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3981 | if (IS_ERR(auth)) |
| 3982 | return -EACCES; |
| 3983 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3984 | } |
| 3985 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3986 | /* |
| 3987 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3988 | * |
| 3989 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3990 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3991 | * |
| 3992 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3993 | * negative errno value. |
| 3994 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3995 | 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] | 3996 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3998 | /* Per 3530bis 15.33.5 */ |
| 3999 | static const rpc_authflavor_t flav_array[] = { |
| 4000 | RPC_AUTH_GSS_KRB5P, |
| 4001 | RPC_AUTH_GSS_KRB5I, |
| 4002 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 4003 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4004 | RPC_AUTH_NULL, |
| 4005 | }; |
| 4006 | int status = -EPERM; |
| 4007 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 4009 | if (server->auth_info.flavor_len > 0) { |
| 4010 | /* try each flavor specified by user */ |
| 4011 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 4012 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4013 | server->auth_info.flavors[i]); |
| 4014 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4015 | continue; |
| 4016 | break; |
| 4017 | } |
| 4018 | } else { |
| 4019 | /* no flavors specified by user, try default list */ |
| 4020 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 4021 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4022 | flav_array[i]); |
| 4023 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4024 | continue; |
| 4025 | break; |
| 4026 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4027 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4028 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4029 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 4030 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4031 | * to access the mount. It could also mean that we tried to mount |
| 4032 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 4033 | * existing mount programs don't handle -EACCES very well so it should |
| 4034 | * be mapped to -EPERM instead. |
| 4035 | */ |
| 4036 | if (status == -EACCES) |
| 4037 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4038 | return status; |
| 4039 | } |
| 4040 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4041 | /** |
| 4042 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 4043 | * @server: initialized nfs_server handle |
| 4044 | * @fhandle: we fill in the pseudo-fs root file handle |
| 4045 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4046 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4047 | * |
| 4048 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4049 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 4050 | 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] | 4051 | struct nfs_fsinfo *info, |
| 4052 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4053 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4054 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4055 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4056 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4057 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4058 | |
| 4059 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 4060 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 4061 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | if (status == 0) |
| 4064 | status = nfs4_server_capabilities(server, fhandle); |
| 4065 | if (status == 0) |
| 4066 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4067 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 4068 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | } |
| 4070 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4071 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 4072 | struct nfs_fsinfo *info) |
| 4073 | { |
| 4074 | int error; |
| 4075 | struct nfs_fattr *fattr = info->fattr; |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4076 | struct nfs4_label *label = fattr->label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4077 | |
| 4078 | error = nfs4_server_capabilities(server, mntfh); |
| 4079 | if (error < 0) { |
| 4080 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 4081 | return error; |
| 4082 | } |
| 4083 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4084 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4085 | if (error < 0) { |
| 4086 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4087 | goto out; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4091 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4092 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4093 | |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4094 | out: |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4095 | return error; |
| 4096 | } |
| 4097 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4098 | /* |
| 4099 | * Get locations and (maybe) other attributes of a referral. |
| 4100 | * Note that we'll actually follow the referral later when |
| 4101 | * we detect fsid mismatch in inode revalidation |
| 4102 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4103 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4104 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4105 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4106 | { |
| 4107 | int status = -ENOMEM; |
| 4108 | struct page *page = NULL; |
| 4109 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4110 | |
| 4111 | page = alloc_page(GFP_KERNEL); |
| 4112 | if (page == NULL) |
| 4113 | goto out; |
| 4114 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4115 | if (locations == NULL) |
| 4116 | goto out; |
| 4117 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4118 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4119 | if (status != 0) |
| 4120 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4121 | |
| 4122 | /* |
| 4123 | * If the fsid didn't change, this is a migration event, not a |
| 4124 | * referral. Cause us to drop into the exception handler, which |
| 4125 | * will kick off migration recovery. |
| 4126 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4127 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4128 | dprintk("%s: server did not return a different fsid for" |
| 4129 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4130 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4131 | goto out; |
| 4132 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4133 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4134 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4135 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4136 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4137 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4138 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4139 | out: |
| 4140 | if (page) |
| 4141 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4142 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4143 | return status; |
| 4144 | } |
| 4145 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4146 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4147 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4148 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4150 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | struct nfs4_getattr_arg args = { |
| 4152 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4153 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | }; |
| 4155 | struct nfs4_getattr_res res = { |
| 4156 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4157 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | .server = server, |
| 4159 | }; |
| 4160 | struct rpc_message msg = { |
| 4161 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4162 | .rpc_argp = &args, |
| 4163 | .rpc_resp = &res, |
| 4164 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4165 | unsigned short task_flags = 0; |
| 4166 | |
| 4167 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4168 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4169 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4170 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4171 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4172 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4173 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4174 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4175 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4176 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | } |
| 4178 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4179 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4180 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4181 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4183 | struct nfs4_exception exception = { |
| 4184 | .interruptible = true, |
| 4185 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | int err; |
| 4187 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4188 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4189 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4190 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | &exception); |
| 4192 | } while (exception.retry); |
| 4193 | return err; |
| 4194 | } |
| 4195 | |
| 4196 | /* |
| 4197 | * The file is not closed if it is opened due to the a request to change |
| 4198 | * the size of the file. The open call will not be needed once the |
| 4199 | * VFS layer lookup-intents are implemented. |
| 4200 | * |
| 4201 | * Close is called when the inode is destroyed. |
| 4202 | * If we haven't opened the file for O_WRONLY, we |
| 4203 | * need to in the size_change case to obtain a stateid. |
| 4204 | * |
| 4205 | * Got race? |
| 4206 | * Because OPEN is always done by name in nfsv4, it is |
| 4207 | * possible that we opened a different file by the same |
| 4208 | * name. We can recognize this race condition, but we |
| 4209 | * can't do anything about it besides returning an error. |
| 4210 | * |
| 4211 | * This will be fixed with VFS changes (lookup-intent). |
| 4212 | */ |
| 4213 | static int |
| 4214 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4215 | struct iattr *sattr) |
| 4216 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4217 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4218 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4219 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4220 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | int status; |
| 4222 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4223 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4224 | sattr->ia_valid & ATTR_SIZE && |
| 4225 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4226 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4227 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4228 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4230 | /* Deal with open(O_TRUNC) */ |
| 4231 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4232 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4233 | |
| 4234 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4235 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4236 | return 0; |
| 4237 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4238 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4239 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4240 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4241 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4242 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4243 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4244 | } |
| 4245 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4246 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4247 | if (IS_ERR(label)) |
| 4248 | return PTR_ERR(label); |
| 4249 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4250 | /* Return any delegations if we're going to change ACLs */ |
| 4251 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4252 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4253 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4254 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4255 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4256 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4257 | nfs_setsecurity(inode, fattr, label); |
| 4258 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4259 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | return status; |
| 4261 | } |
| 4262 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4263 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4264 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4265 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4266 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4267 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4268 | int status; |
| 4269 | struct nfs4_lookup_arg args = { |
| 4270 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4271 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4272 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4273 | }; |
| 4274 | struct nfs4_lookup_res res = { |
| 4275 | .server = server, |
| 4276 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4277 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4278 | .fh = fhandle, |
| 4279 | }; |
| 4280 | struct rpc_message msg = { |
| 4281 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4282 | .rpc_argp = &args, |
| 4283 | .rpc_resp = &res, |
| 4284 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4285 | unsigned short task_flags = 0; |
| 4286 | |
| 4287 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4288 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4289 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4290 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4291 | args.bitmask = nfs4_bitmask(server, label); |
| 4292 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4293 | nfs_fattr_init(fattr); |
| 4294 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4295 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4296 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4297 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4298 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | dprintk("NFS reply lookup: %d\n", status); |
| 4300 | return status; |
| 4301 | } |
| 4302 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4303 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4304 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4305 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4306 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4307 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4308 | fattr->nlink = 2; |
| 4309 | } |
| 4310 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4311 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4312 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4313 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4314 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4315 | struct nfs4_exception exception = { |
| 4316 | .interruptible = true, |
| 4317 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4318 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4319 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4320 | int err; |
| 4321 | do { |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4322 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4323 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4324 | switch (err) { |
| 4325 | case -NFS4ERR_BADNAME: |
| 4326 | err = -ENOENT; |
| 4327 | goto out; |
| 4328 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4329 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4330 | if (err == -NFS4ERR_MOVED) |
| 4331 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4332 | goto out; |
| 4333 | case -NFS4ERR_WRONGSEC: |
| 4334 | err = -EPERM; |
| 4335 | if (client != *clnt) |
| 4336 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4337 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4338 | if (IS_ERR(client)) |
| 4339 | return PTR_ERR(client); |
| 4340 | |
| 4341 | exception.retry = 1; |
| 4342 | break; |
| 4343 | default: |
| 4344 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4345 | } |
| 4346 | } while (exception.retry); |
| 4347 | |
| 4348 | out: |
| 4349 | if (err == 0) |
| 4350 | *clnt = client; |
| 4351 | else if (client != *clnt) |
| 4352 | rpc_shutdown_client(client); |
| 4353 | |
| 4354 | return err; |
| 4355 | } |
| 4356 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4357 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4358 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4359 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4361 | int status; |
| 4362 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4363 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4364 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4365 | if (client != NFS_CLIENT(dir)) { |
| 4366 | rpc_shutdown_client(client); |
| 4367 | nfs_fixup_secinfo_attributes(fattr); |
| 4368 | } |
| 4369 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4372 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4373 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4374 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4375 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4376 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4377 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4378 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4379 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4380 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4381 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4382 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4383 | } |
| 4384 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4385 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4386 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4387 | struct nfs4_label *label) |
| 4388 | { |
| 4389 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4390 | struct nfs_server *server = NFS_SERVER(inode); |
| 4391 | int status; |
| 4392 | struct nfs4_lookupp_arg args = { |
| 4393 | .bitmask = server->attr_bitmask, |
| 4394 | .fh = NFS_FH(inode), |
| 4395 | }; |
| 4396 | struct nfs4_lookupp_res res = { |
| 4397 | .server = server, |
| 4398 | .fattr = fattr, |
| 4399 | .label = label, |
| 4400 | .fh = fhandle, |
| 4401 | }; |
| 4402 | struct rpc_message msg = { |
| 4403 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4404 | .rpc_argp = &args, |
| 4405 | .rpc_resp = &res, |
| 4406 | }; |
| 4407 | |
| 4408 | args.bitmask = nfs4_bitmask(server, label); |
| 4409 | |
| 4410 | nfs_fattr_init(fattr); |
| 4411 | |
| 4412 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4413 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4414 | &res.seq_res, 0); |
| 4415 | dprintk("NFS reply lookupp: %d\n", status); |
| 4416 | return status; |
| 4417 | } |
| 4418 | |
| 4419 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4420 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4421 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4422 | struct nfs4_exception exception = { |
| 4423 | .interruptible = true, |
| 4424 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4425 | int err; |
| 4426 | do { |
| 4427 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4428 | trace_nfs4_lookupp(inode, err); |
| 4429 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4430 | &exception); |
| 4431 | } while (exception.retry); |
| 4432 | return err; |
| 4433 | } |
| 4434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4436 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4437 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | struct nfs4_accessargs args = { |
| 4439 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4440 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4442 | struct nfs4_accessres res = { |
| 4443 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4444 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | struct rpc_message msg = { |
| 4446 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4447 | .rpc_argp = &args, |
| 4448 | .rpc_resp = &res, |
| 4449 | .rpc_cred = entry->cred, |
| 4450 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4451 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4453 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4454 | res.fattr = nfs_alloc_fattr(); |
| 4455 | if (res.fattr == NULL) |
| 4456 | return -ENOMEM; |
| 4457 | args.bitmask = server->cache_consistency_bitmask; |
| 4458 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4459 | 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] | 4460 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4461 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4462 | if (res.fattr) |
| 4463 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4465 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | return status; |
| 4467 | } |
| 4468 | |
| 4469 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4470 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4471 | struct nfs4_exception exception = { |
| 4472 | .interruptible = true, |
| 4473 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | int err; |
| 4475 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4476 | err = _nfs4_proc_access(inode, entry); |
| 4477 | trace_nfs4_access(inode, err); |
| 4478 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | &exception); |
| 4480 | } while (exception.retry); |
| 4481 | return err; |
| 4482 | } |
| 4483 | |
| 4484 | /* |
| 4485 | * TODO: For the time being, we don't try to get any attributes |
| 4486 | * along with any of the zero-copy operations READ, READDIR, |
| 4487 | * READLINK, WRITE. |
| 4488 | * |
| 4489 | * In the case of the first three, we want to put the GETATTR |
| 4490 | * after the read-type operation -- this is because it is hard |
| 4491 | * to predict the length of a GETATTR response in v4, and thus |
| 4492 | * align the READ data correctly. This means that the GETATTR |
| 4493 | * may end up partially falling into the page cache, and we should |
| 4494 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4495 | * To do this efficiently, we need to know the total length |
| 4496 | * of data received, which doesn't seem to be available outside |
| 4497 | * of the RPC layer. |
| 4498 | * |
| 4499 | * In the case of WRITE, we also want to put the GETATTR after |
| 4500 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4501 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | * |
| 4503 | * Both of these changes to the XDR layer would in fact be quite |
| 4504 | * minor, but I decided to leave them for a subsequent patch. |
| 4505 | */ |
| 4506 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4507 | unsigned int pgbase, unsigned int pglen) |
| 4508 | { |
| 4509 | struct nfs4_readlink args = { |
| 4510 | .fh = NFS_FH(inode), |
| 4511 | .pgbase = pgbase, |
| 4512 | .pglen = pglen, |
| 4513 | .pages = &page, |
| 4514 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4515 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | struct rpc_message msg = { |
| 4517 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4518 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4519 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | }; |
| 4521 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4522 | 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] | 4523 | } |
| 4524 | |
| 4525 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4526 | unsigned int pgbase, unsigned int pglen) |
| 4527 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4528 | struct nfs4_exception exception = { |
| 4529 | .interruptible = true, |
| 4530 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | int err; |
| 4532 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4533 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4534 | trace_nfs4_readlink(inode, err); |
| 4535 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | &exception); |
| 4537 | } while (exception.retry); |
| 4538 | return err; |
| 4539 | } |
| 4540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4542 | * 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] | 4543 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | static int |
| 4545 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4546 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4548 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4549 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4550 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | int status = 0; |
| 4553 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4554 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4555 | if (IS_ERR(ctx)) |
| 4556 | return PTR_ERR(ctx); |
| 4557 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4558 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4559 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4560 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4561 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4562 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | if (IS_ERR(state)) { |
| 4564 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4565 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4568 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4569 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | return status; |
| 4571 | } |
| 4572 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4573 | static int |
| 4574 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4576 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4577 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4579 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4581 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4582 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4583 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4585 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4586 | .rpc_argp = &args, |
| 4587 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4589 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4590 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4591 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4592 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4593 | if (status == 0) { |
| 4594 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4595 | nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, |
| 4596 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4597 | /* Removing a directory decrements nlink in the parent */ |
| 4598 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4599 | nfs4_dec_nlink_locked(dir); |
| 4600 | spin_unlock(&dir->i_lock); |
| 4601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | return status; |
| 4603 | } |
| 4604 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4605 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4606 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4607 | struct nfs4_exception exception = { |
| 4608 | .interruptible = true, |
| 4609 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4610 | struct inode *inode = d_inode(dentry); |
| 4611 | int err; |
| 4612 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4613 | if (inode) { |
| 4614 | if (inode->i_nlink == 1) |
| 4615 | nfs4_inode_return_delegation(inode); |
| 4616 | else |
| 4617 | nfs4_inode_make_writeable(inode); |
| 4618 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4619 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4620 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4621 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4622 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4623 | &exception); |
| 4624 | } while (exception.retry); |
| 4625 | return err; |
| 4626 | } |
| 4627 | |
| 4628 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4630 | struct nfs4_exception exception = { |
| 4631 | .interruptible = true, |
| 4632 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4636 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4637 | trace_nfs4_remove(dir, name, err); |
| 4638 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | &exception); |
| 4640 | } while (exception.retry); |
| 4641 | return err; |
| 4642 | } |
| 4643 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4644 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4645 | struct dentry *dentry, |
| 4646 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4648 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4649 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4651 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4653 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4654 | |
| 4655 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4656 | |
| 4657 | if (inode) |
| 4658 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4661 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4662 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4663 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4664 | &data->args.seq_args, |
| 4665 | &data->res.seq_res, |
| 4666 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | } |
| 4668 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4669 | 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] | 4670 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4671 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4672 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4673 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4674 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4675 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4676 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4677 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4678 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4679 | if (task->tk_status == 0) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4680 | nfs4_update_changeattr(dir, &res->cinfo, |
| 4681 | res->dir_attr->time_start, |
| 4682 | NFS_INO_INVALID_DATA); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4683 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4686 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4687 | struct dentry *old_dentry, |
| 4688 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4689 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4690 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4691 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4692 | struct inode *old_inode = d_inode(old_dentry); |
| 4693 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4694 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4695 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4696 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4697 | if (new_inode) |
| 4698 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4699 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4700 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4701 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4702 | } |
| 4703 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4704 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4705 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4706 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4707 | &data->args.seq_args, |
| 4708 | &data->res.seq_res, |
| 4709 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4713 | struct inode *new_dir) |
| 4714 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4715 | struct nfs_renamedata *data = task->tk_calldata; |
| 4716 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4717 | |
| 4718 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4719 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4720 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4721 | return 0; |
| 4722 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4723 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4724 | if (new_dir != old_dir) { |
| 4725 | /* Note: If we moved a directory, nlink will change */ |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4726 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4727 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4728 | NFS_INO_INVALID_OTHER | |
| 4729 | NFS_INO_INVALID_DATA); |
| 4730 | nfs4_update_changeattr(new_dir, &res->new_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4731 | res->new_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4732 | NFS_INO_INVALID_OTHER | |
| 4733 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4734 | } else |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4735 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4736 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4737 | NFS_INO_INVALID_DATA); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4738 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4739 | return 1; |
| 4740 | } |
| 4741 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4742 | 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] | 4743 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4744 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4745 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | struct nfs4_link_arg arg = { |
| 4747 | .fh = NFS_FH(inode), |
| 4748 | .dir_fh = NFS_FH(dir), |
| 4749 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4750 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4752 | struct nfs4_link_res res = { |
| 4753 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4754 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4755 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | struct rpc_message msg = { |
| 4757 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4758 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4759 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4761 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4763 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4764 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4765 | goto out; |
| 4766 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4767 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4768 | if (IS_ERR(res.label)) { |
| 4769 | status = PTR_ERR(res.label); |
| 4770 | goto out; |
| 4771 | } |
| 4772 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4773 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4774 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4775 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4776 | 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] | 4777 | if (!status) { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4778 | nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, |
| 4779 | NFS_INO_INVALID_DATA); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4780 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4781 | if (!status) |
| 4782 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4783 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4784 | |
| 4785 | |
| 4786 | nfs4_label_free(res.label); |
| 4787 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4788 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4789 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | return status; |
| 4791 | } |
| 4792 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4793 | 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] | 4794 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4795 | struct nfs4_exception exception = { |
| 4796 | .interruptible = true, |
| 4797 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | int err; |
| 4799 | do { |
| 4800 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4801 | _nfs4_proc_link(inode, dir, name), |
| 4802 | &exception); |
| 4803 | } while (exception.retry); |
| 4804 | return err; |
| 4805 | } |
| 4806 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4807 | struct nfs4_createdata { |
| 4808 | struct rpc_message msg; |
| 4809 | struct nfs4_create_arg arg; |
| 4810 | struct nfs4_create_res res; |
| 4811 | struct nfs_fh fh; |
| 4812 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4813 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4814 | }; |
| 4815 | |
| 4816 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4817 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4818 | { |
| 4819 | struct nfs4_createdata *data; |
| 4820 | |
| 4821 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4822 | if (data != NULL) { |
| 4823 | struct nfs_server *server = NFS_SERVER(dir); |
| 4824 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4825 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4826 | if (IS_ERR(data->label)) |
| 4827 | goto out_free; |
| 4828 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4829 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4830 | data->msg.rpc_argp = &data->arg; |
| 4831 | data->msg.rpc_resp = &data->res; |
| 4832 | data->arg.dir_fh = NFS_FH(dir); |
| 4833 | data->arg.server = server; |
| 4834 | data->arg.name = name; |
| 4835 | data->arg.attrs = sattr; |
| 4836 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4837 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4838 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4839 | data->res.server = server; |
| 4840 | data->res.fh = &data->fh; |
| 4841 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4842 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4843 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4844 | } |
| 4845 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4846 | out_free: |
| 4847 | kfree(data); |
| 4848 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4852 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4853 | 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] | 4854 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4855 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4856 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4857 | nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, |
| 4858 | data->res.fattr->time_start, |
| 4859 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4860 | /* Creating a directory bumps nlink in the parent */ |
| 4861 | if (data->arg.ftype == NF4DIR) |
| 4862 | nfs4_inc_nlink_locked(dir); |
| 4863 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4864 | 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] | 4865 | } |
| 4866 | return status; |
| 4867 | } |
| 4868 | |
| 4869 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4870 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4871 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4872 | kfree(data); |
| 4873 | } |
| 4874 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4875 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4876 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4877 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4879 | struct nfs4_createdata *data; |
| 4880 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4882 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4883 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4884 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4885 | status = -ENOMEM; |
| 4886 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4887 | if (data == NULL) |
| 4888 | goto out; |
| 4889 | |
| 4890 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4891 | data->arg.u.symlink.pages = &page; |
| 4892 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4893 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4895 | status = nfs4_do_create(dir, dentry, data); |
| 4896 | |
| 4897 | nfs4_free_createdata(data); |
| 4898 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | return status; |
| 4900 | } |
| 4901 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4902 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4903 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4904 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4905 | struct nfs4_exception exception = { |
| 4906 | .interruptible = true, |
| 4907 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4908 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4910 | |
| 4911 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4914 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4915 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4916 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | &exception); |
| 4918 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4919 | |
| 4920 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | return err; |
| 4922 | } |
| 4923 | |
| 4924 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4925 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4927 | struct nfs4_createdata *data; |
| 4928 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4930 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4931 | if (data == NULL) |
| 4932 | goto out; |
| 4933 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4934 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4935 | status = nfs4_do_create(dir, dentry, data); |
| 4936 | |
| 4937 | nfs4_free_createdata(data); |
| 4938 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | return status; |
| 4940 | } |
| 4941 | |
| 4942 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4943 | struct iattr *sattr) |
| 4944 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4945 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4946 | struct nfs4_exception exception = { |
| 4947 | .interruptible = true, |
| 4948 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4949 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4951 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4952 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4953 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4954 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4955 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4956 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4957 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4958 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4959 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | &exception); |
| 4961 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4962 | nfs4_label_release_security(label); |
| 4963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4964 | return err; |
| 4965 | } |
| 4966 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4967 | static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4968 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4970 | struct inode *dir = d_inode(dentry); |
Olga Kornievskaia | 78c9026 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4971 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | struct nfs4_readdir_arg args = { |
| 4973 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4974 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | .pgbase = 0, |
| 4976 | .count = count, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4977 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | }; |
| 4979 | struct nfs4_readdir_res res; |
| 4980 | struct rpc_message msg = { |
| 4981 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4982 | .rpc_argp = &args, |
| 4983 | .rpc_resp = &res, |
| 4984 | .rpc_cred = cred, |
| 4985 | }; |
| 4986 | int status; |
| 4987 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4988 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4989 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4990 | (unsigned long long)cookie); |
Olga Kornievskaia | 78c9026 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4991 | if (!(server->caps & NFS_CAP_SECURITY_LABEL)) |
| 4992 | args.bitmask = server->attr_bitmask_nl; |
| 4993 | else |
| 4994 | args.bitmask = server->attr_bitmask; |
| 4995 | |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4996 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4997 | res.pgbase = args.pgbase; |
Olga Kornievskaia | 78c9026 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4998 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 4999 | &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 5000 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 5001 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 5002 | status += args.pgbase; |
| 5003 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 5004 | |
| 5005 | nfs_invalidate_atime(dir); |
| 5006 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5007 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | return status; |
| 5009 | } |
| 5010 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 5011 | static int nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 5012 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5014 | struct nfs4_exception exception = { |
| 5015 | .interruptible = true, |
| 5016 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | int err; |
| 5018 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5019 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 5020 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5021 | trace_nfs4_readdir(d_inode(dentry), err); |
| 5022 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | &exception); |
| 5024 | } while (exception.retry); |
| 5025 | return err; |
| 5026 | } |
| 5027 | |
| 5028 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5029 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5031 | struct nfs4_createdata *data; |
| 5032 | int mode = sattr->ia_mode; |
| 5033 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5035 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 5036 | if (data == NULL) |
| 5037 | goto out; |
| 5038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5040 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5042 | data->arg.ftype = NF4BLK; |
| 5043 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5044 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | } |
| 5046 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5047 | data->arg.ftype = NF4CHR; |
| 5048 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5049 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5050 | } else if (!S_ISSOCK(mode)) { |
| 5051 | status = -EINVAL; |
| 5052 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5054 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5055 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5056 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5057 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5058 | nfs4_free_createdata(data); |
| 5059 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | return status; |
| 5061 | } |
| 5062 | |
| 5063 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 5064 | struct iattr *sattr, dev_t rdev) |
| 5065 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5066 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5067 | struct nfs4_exception exception = { |
| 5068 | .interruptible = true, |
| 5069 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5070 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 5072 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5073 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5074 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5075 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 5076 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5078 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 5079 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 5080 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | &exception); |
| 5082 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5083 | |
| 5084 | nfs4_label_release_security(label); |
| 5085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | return err; |
| 5087 | } |
| 5088 | |
| 5089 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5090 | struct nfs_fsstat *fsstat) |
| 5091 | { |
| 5092 | struct nfs4_statfs_arg args = { |
| 5093 | .fh = fhandle, |
| 5094 | .bitmask = server->attr_bitmask, |
| 5095 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5096 | struct nfs4_statfs_res res = { |
| 5097 | .fsstat = fsstat, |
| 5098 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | struct rpc_message msg = { |
| 5100 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5101 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5102 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 | }; |
| 5104 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5105 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5106 | 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] | 5107 | } |
| 5108 | |
| 5109 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5110 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5111 | struct nfs4_exception exception = { |
| 5112 | .interruptible = true, |
| 5113 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5114 | int err; |
| 5115 | do { |
| 5116 | err = nfs4_handle_exception(server, |
| 5117 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5118 | &exception); |
| 5119 | } while (exception.retry); |
| 5120 | return err; |
| 5121 | } |
| 5122 | |
| 5123 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5124 | struct nfs_fsinfo *fsinfo) |
| 5125 | { |
| 5126 | struct nfs4_fsinfo_arg args = { |
| 5127 | .fh = fhandle, |
| 5128 | .bitmask = server->attr_bitmask, |
| 5129 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5130 | struct nfs4_fsinfo_res res = { |
| 5131 | .fsinfo = fsinfo, |
| 5132 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | struct rpc_message msg = { |
| 5134 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5135 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5136 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | }; |
| 5138 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5139 | 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] | 5140 | } |
| 5141 | |
| 5142 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5143 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5144 | struct nfs4_exception exception = { |
| 5145 | .interruptible = true, |
| 5146 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | int err; |
| 5148 | |
| 5149 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5150 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5151 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5152 | if (err == 0) { |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 5153 | nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5154 | break; |
| 5155 | } |
| 5156 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | } while (exception.retry); |
| 5158 | return err; |
| 5159 | } |
| 5160 | |
| 5161 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5162 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5163 | int error; |
| 5164 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5165 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5166 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5167 | if (error == 0) { |
| 5168 | /* block layout checks this! */ |
| 5169 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5170 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5171 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5172 | |
| 5173 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5177 | struct nfs_pathconf *pathconf) |
| 5178 | { |
| 5179 | struct nfs4_pathconf_arg args = { |
| 5180 | .fh = fhandle, |
| 5181 | .bitmask = server->attr_bitmask, |
| 5182 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5183 | struct nfs4_pathconf_res res = { |
| 5184 | .pathconf = pathconf, |
| 5185 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | struct rpc_message msg = { |
| 5187 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5188 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5189 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | }; |
| 5191 | |
| 5192 | /* None of the pathconf attributes are mandatory to implement */ |
| 5193 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5194 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5195 | return 0; |
| 5196 | } |
| 5197 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5198 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5199 | 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] | 5200 | } |
| 5201 | |
| 5202 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5203 | struct nfs_pathconf *pathconf) |
| 5204 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5205 | struct nfs4_exception exception = { |
| 5206 | .interruptible = true, |
| 5207 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | int err; |
| 5209 | |
| 5210 | do { |
| 5211 | err = nfs4_handle_exception(server, |
| 5212 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5213 | &exception); |
| 5214 | } while (exception.retry); |
| 5215 | return err; |
| 5216 | } |
| 5217 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5218 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5219 | const struct nfs_open_context *ctx, |
| 5220 | const struct nfs_lock_context *l_ctx, |
| 5221 | fmode_t fmode) |
| 5222 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5223 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5224 | } |
| 5225 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5226 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5227 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5228 | const struct nfs_open_context *ctx, |
| 5229 | const struct nfs_lock_context *l_ctx, |
| 5230 | fmode_t fmode) |
| 5231 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5232 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5233 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5234 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5235 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5236 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5237 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5238 | } |
| 5239 | |
| 5240 | static bool nfs4_error_stateid_expired(int err) |
| 5241 | { |
| 5242 | switch (err) { |
| 5243 | case -NFS4ERR_DELEG_REVOKED: |
| 5244 | case -NFS4ERR_ADMIN_REVOKED: |
| 5245 | case -NFS4ERR_BAD_STATEID: |
| 5246 | case -NFS4ERR_STALE_STATEID: |
| 5247 | case -NFS4ERR_OLD_STATEID: |
| 5248 | case -NFS4ERR_OPENMODE: |
| 5249 | case -NFS4ERR_EXPIRED: |
| 5250 | return true; |
| 5251 | } |
| 5252 | return false; |
| 5253 | } |
| 5254 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5255 | 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] | 5256 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5257 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5259 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5260 | if (task->tk_status < 0) { |
| 5261 | struct nfs4_exception exception = { |
| 5262 | .inode = hdr->inode, |
| 5263 | .state = hdr->args.context->state, |
| 5264 | .stateid = &hdr->args.stateid, |
| 5265 | }; |
| 5266 | task->tk_status = nfs4_async_handle_exception(task, |
| 5267 | server, task->tk_status, &exception); |
| 5268 | if (exception.retry) { |
| 5269 | rpc_restart_call_prepare(task); |
| 5270 | return -EAGAIN; |
| 5271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5274 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5275 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5276 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | } |
| 5278 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5279 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5280 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5281 | { |
| 5282 | |
| 5283 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5284 | nfs4_stateid_is_current(&args->stateid, |
| 5285 | args->context, |
| 5286 | args->lock_context, |
| 5287 | FMODE_READ)) |
| 5288 | return false; |
| 5289 | rpc_restart_call_prepare(task); |
| 5290 | return true; |
| 5291 | } |
| 5292 | |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5293 | static bool nfs4_read_plus_not_supported(struct rpc_task *task, |
| 5294 | struct nfs_pgio_header *hdr) |
| 5295 | { |
| 5296 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
| 5297 | struct rpc_message *msg = &task->tk_msg; |
| 5298 | |
| 5299 | if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS] && |
| 5300 | server->caps & NFS_CAP_READ_PLUS && task->tk_status == -ENOTSUPP) { |
| 5301 | server->caps &= ~NFS_CAP_READ_PLUS; |
| 5302 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5303 | rpc_restart_call_prepare(task); |
| 5304 | return true; |
| 5305 | } |
| 5306 | return false; |
| 5307 | } |
| 5308 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5309 | 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] | 5310 | { |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5311 | dprintk("--> %s\n", __func__); |
| 5312 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5313 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5314 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5315 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5316 | return -EAGAIN; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5317 | if (nfs4_read_plus_not_supported(task, hdr)) |
| 5318 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5319 | if (task->tk_status > 0) |
| 5320 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5321 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5322 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5323 | } |
| 5324 | |
Anna Schumaker | 21e3140 | 2020-12-03 15:18:39 -0500 | [diff] [blame] | 5325 | #if defined CONFIG_NFS_V4_2 && defined CONFIG_NFS_V4_2_READ_PLUS |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5326 | static void nfs42_read_plus_support(struct nfs_server *server, struct rpc_message *msg) |
| 5327 | { |
| 5328 | if (server->caps & NFS_CAP_READ_PLUS) |
| 5329 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS]; |
| 5330 | else |
| 5331 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5332 | } |
| 5333 | #else |
| 5334 | static void nfs42_read_plus_support(struct nfs_server *server, struct rpc_message *msg) |
| 5335 | { |
| 5336 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5337 | } |
| 5338 | #endif /* CONFIG_NFS_V4_2 */ |
| 5339 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5340 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5341 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5343 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5344 | if (!hdr->pgio_done_cb) |
| 5345 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5346 | nfs42_read_plus_support(NFS_SERVER(hdr->inode), msg); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5347 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5348 | } |
| 5349 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5350 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5351 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5352 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5353 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5354 | &hdr->args.seq_args, |
| 5355 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5356 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5357 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5358 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5359 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5360 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5361 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5362 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5363 | return -EIO; |
| 5364 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5367 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5368 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5370 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5371 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5372 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5373 | if (task->tk_status < 0) { |
| 5374 | struct nfs4_exception exception = { |
| 5375 | .inode = hdr->inode, |
| 5376 | .state = hdr->args.context->state, |
| 5377 | .stateid = &hdr->args.stateid, |
| 5378 | }; |
| 5379 | task->tk_status = nfs4_async_handle_exception(task, |
| 5380 | NFS_SERVER(inode), task->tk_status, |
| 5381 | &exception); |
| 5382 | if (exception.retry) { |
| 5383 | rpc_restart_call_prepare(task); |
| 5384 | return -EAGAIN; |
| 5385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5387 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5388 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5389 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5390 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5391 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5392 | } |
| 5393 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5394 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5395 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5396 | { |
| 5397 | |
| 5398 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5399 | nfs4_stateid_is_current(&args->stateid, |
| 5400 | args->context, |
| 5401 | args->lock_context, |
| 5402 | FMODE_WRITE)) |
| 5403 | return false; |
| 5404 | rpc_restart_call_prepare(task); |
| 5405 | return true; |
| 5406 | } |
| 5407 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5408 | 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] | 5409 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5410 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5411 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5412 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5413 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5414 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5415 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5416 | } |
| 5417 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5418 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5419 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5420 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5421 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5422 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5423 | return false; |
| 5424 | /* Otherwise, request attributes if and only if we don't hold |
| 5425 | * a delegation |
| 5426 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5427 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5428 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5429 | |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5430 | static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src, |
| 5431 | struct inode *inode, struct nfs_server *server, |
| 5432 | struct nfs4_label *label) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5433 | { |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5434 | unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5435 | unsigned int i; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5436 | |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5437 | memcpy(bitmask, src, sizeof(*bitmask) * NFS4_BITMASK_SZ); |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5438 | |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5439 | if (cache_validity & (NFS_INO_INVALID_CHANGE | NFS_INO_REVAL_PAGECACHE)) |
| 5440 | bitmask[0] |= FATTR4_WORD0_CHANGE; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5441 | if (cache_validity & NFS_INO_INVALID_ATIME) |
| 5442 | bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; |
Trond Myklebust | 9468ab8 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5443 | if (cache_validity & NFS_INO_INVALID_OTHER) |
| 5444 | bitmask[1] |= FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | |
| 5445 | FATTR4_WORD1_OWNER_GROUP | |
| 5446 | FATTR4_WORD1_NUMLINKS; |
| 5447 | if (label && label->len && cache_validity & NFS_INO_INVALID_LABEL) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5448 | bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 9468ab8 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5449 | if (cache_validity & NFS_INO_INVALID_CTIME) |
| 5450 | bitmask[1] |= FATTR4_WORD1_TIME_METADATA; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5451 | if (cache_validity & NFS_INO_INVALID_MTIME) |
| 5452 | bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5453 | if (cache_validity & NFS_INO_INVALID_BLOCKS) |
| 5454 | bitmask[1] |= FATTR4_WORD1_SPACE_USED; |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5455 | |
| 5456 | if (nfs4_have_delegation(inode, FMODE_READ) && |
| 5457 | !(cache_validity & NFS_INO_REVAL_FORCED)) |
| 5458 | bitmask[0] &= ~FATTR4_WORD0_SIZE; |
| 5459 | else if (cache_validity & |
| 5460 | (NFS_INO_INVALID_SIZE | NFS_INO_REVAL_PAGECACHE)) |
| 5461 | bitmask[0] |= FATTR4_WORD0_SIZE; |
| 5462 | |
| 5463 | for (i = 0; i < NFS4_BITMASK_SZ; i++) |
| 5464 | bitmask[i] &= server->attr_bitmask[i]; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5465 | } |
| 5466 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5467 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5468 | struct rpc_message *msg, |
| 5469 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5471 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5472 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5473 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5474 | hdr->args.bitmask = NULL; |
| 5475 | hdr->res.fattr = NULL; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5476 | } else { |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5477 | nfs4_bitmask_set(hdr->args.bitmask_store, |
| 5478 | server->cache_consistency_bitmask, |
| 5479 | hdr->inode, server, NULL); |
| 5480 | hdr->args.bitmask = hdr->args.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5481 | } |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5482 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5483 | if (!hdr->pgio_done_cb) |
| 5484 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5485 | hdr->res.server = server; |
| 5486 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5488 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Olga Kornievskaia | cd1b659 | 2020-02-12 17:32:12 -0500 | [diff] [blame] | 5489 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0); |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5490 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | } |
| 5492 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5493 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5494 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5495 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5496 | &data->args.seq_args, |
| 5497 | &data->res.seq_res, |
| 5498 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | } |
| 5500 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5501 | 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] | 5502 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5504 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5505 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5506 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5507 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5508 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5509 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5511 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | } |
| 5513 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5514 | 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] | 5515 | { |
| 5516 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5517 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5518 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5521 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5522 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5523 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5524 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5525 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5526 | if (data->commit_done_cb == NULL) |
| 5527 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5528 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5529 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5530 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5531 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_COMMIT, clnt, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | } |
| 5533 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5534 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5535 | struct nfs_commitres *res) |
| 5536 | { |
| 5537 | struct inode *dst_inode = file_inode(dst); |
| 5538 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5539 | struct rpc_message msg = { |
| 5540 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5541 | .rpc_argp = args, |
| 5542 | .rpc_resp = res, |
| 5543 | }; |
| 5544 | |
| 5545 | args->fh = NFS_FH(dst_inode); |
| 5546 | return nfs4_call_sync(server->client, server, &msg, |
| 5547 | &args->seq_args, &res->seq_res, 1); |
| 5548 | } |
| 5549 | |
| 5550 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5551 | { |
| 5552 | struct nfs_commitargs args = { |
| 5553 | .offset = offset, |
| 5554 | .count = count, |
| 5555 | }; |
| 5556 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5557 | struct nfs4_exception exception = { }; |
| 5558 | int status; |
| 5559 | |
| 5560 | do { |
| 5561 | status = _nfs4_proc_commit(dst, &args, res); |
| 5562 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5563 | } while (exception.retry); |
| 5564 | |
| 5565 | return status; |
| 5566 | } |
| 5567 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5568 | struct nfs4_renewdata { |
| 5569 | struct nfs_client *client; |
| 5570 | unsigned long timestamp; |
| 5571 | }; |
| 5572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | /* |
| 5574 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5575 | * standalone procedure for queueing an asynchronous RENEW. |
| 5576 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5577 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5578 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5579 | struct nfs4_renewdata *data = calldata; |
| 5580 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5581 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5582 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5583 | nfs4_schedule_state_renewal(clp); |
| 5584 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5585 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5586 | } |
| 5587 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5588 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5589 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5590 | struct nfs4_renewdata *data = calldata; |
| 5591 | struct nfs_client *clp = data->client; |
| 5592 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5593 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5594 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5595 | switch (task->tk_status) { |
| 5596 | case 0: |
| 5597 | break; |
| 5598 | case -NFS4ERR_LEASE_MOVED: |
| 5599 | nfs4_schedule_lease_moved_recovery(clp); |
| 5600 | break; |
| 5601 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5602 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5603 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5604 | return; |
| 5605 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5606 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5607 | return; |
| 5608 | } |
| 5609 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5611 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | } |
| 5613 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5614 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5615 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5616 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5617 | }; |
| 5618 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5619 | static int nfs4_proc_async_renew(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | { |
| 5621 | struct rpc_message msg = { |
| 5622 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5623 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5624 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5626 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5628 | if (renew_flags == 0) |
| 5629 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5630 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5631 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5632 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5633 | if (data == NULL) { |
| 5634 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5635 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5636 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5637 | data->client = clp; |
| 5638 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5639 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5640 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5641 | } |
| 5642 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5643 | static int nfs4_proc_renew(struct nfs_client *clp, const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | { |
| 5645 | struct rpc_message msg = { |
| 5646 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5647 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5648 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5649 | }; |
| 5650 | unsigned long now = jiffies; |
| 5651 | int status; |
| 5652 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5653 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | if (status < 0) |
| 5655 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5656 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5657 | return 0; |
| 5658 | } |
| 5659 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5660 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5661 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5662 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5663 | } |
| 5664 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5665 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5666 | * 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] | 5667 | * the stack. |
| 5668 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5669 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5670 | |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5671 | int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5672 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5673 | { |
| 5674 | struct page *newpage, **spages; |
| 5675 | int rc = 0; |
| 5676 | size_t len; |
| 5677 | spages = pages; |
| 5678 | |
| 5679 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5680 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5681 | newpage = alloc_page(GFP_KERNEL); |
| 5682 | |
| 5683 | if (newpage == NULL) |
| 5684 | goto unwind; |
| 5685 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5686 | buf += len; |
| 5687 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5688 | *pages++ = newpage; |
| 5689 | rc++; |
| 5690 | } while (buflen != 0); |
| 5691 | |
| 5692 | return rc; |
| 5693 | |
| 5694 | unwind: |
| 5695 | for(; rc > 0; rc--) |
| 5696 | __free_page(spages[rc-1]); |
| 5697 | return -ENOMEM; |
| 5698 | } |
| 5699 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5700 | struct nfs4_cached_acl { |
| 5701 | int cached; |
| 5702 | size_t len; |
Gustavo A. R. Silva | 5601cda | 2020-03-09 13:24:42 -0500 | [diff] [blame] | 5703 | char data[]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5704 | }; |
| 5705 | |
| 5706 | 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] | 5707 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5708 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5709 | |
| 5710 | spin_lock(&inode->i_lock); |
| 5711 | kfree(nfsi->nfs4_acl); |
| 5712 | nfsi->nfs4_acl = acl; |
| 5713 | spin_unlock(&inode->i_lock); |
| 5714 | } |
| 5715 | |
| 5716 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5717 | { |
| 5718 | nfs4_set_cached_acl(inode, NULL); |
| 5719 | } |
| 5720 | |
| 5721 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5722 | { |
| 5723 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5724 | struct nfs4_cached_acl *acl; |
| 5725 | int ret = -ENOENT; |
| 5726 | |
| 5727 | spin_lock(&inode->i_lock); |
| 5728 | acl = nfsi->nfs4_acl; |
| 5729 | if (acl == NULL) |
| 5730 | goto out; |
| 5731 | if (buf == NULL) /* user is just asking for length */ |
| 5732 | goto out_len; |
| 5733 | if (acl->cached == 0) |
| 5734 | goto out; |
| 5735 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5736 | if (acl->len > buflen) |
| 5737 | goto out; |
| 5738 | memcpy(buf, acl->data, acl->len); |
| 5739 | out_len: |
| 5740 | ret = acl->len; |
| 5741 | out: |
| 5742 | spin_unlock(&inode->i_lock); |
| 5743 | return ret; |
| 5744 | } |
| 5745 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5746 | 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] | 5747 | { |
| 5748 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5749 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5750 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5751 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5752 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5753 | if (acl == NULL) |
| 5754 | goto out; |
| 5755 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5756 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5757 | } else { |
| 5758 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5759 | if (acl == NULL) |
| 5760 | goto out; |
| 5761 | acl->cached = 0; |
| 5762 | } |
| 5763 | acl->len = acl_len; |
| 5764 | out: |
| 5765 | nfs4_set_cached_acl(inode, acl); |
| 5766 | } |
| 5767 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5768 | /* |
| 5769 | * The getxattr API returns the required buffer length when called with a |
| 5770 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5771 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5772 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5773 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5774 | * the cache. If not so, we throw away the page, and cache the required |
| 5775 | * length. The next getxattr call will then produce another round trip to |
| 5776 | * the server, this time with the input buf of the required size. |
| 5777 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5778 | 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] | 5779 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5780 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5781 | struct nfs_getaclargs args = { |
| 5782 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5783 | .acl_len = buflen, |
| 5784 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5785 | struct nfs_getaclres res = { |
| 5786 | .acl_len = buflen, |
| 5787 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5788 | struct rpc_message msg = { |
| 5789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5790 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5791 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5792 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5793 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5794 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5795 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5796 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5797 | if (buflen == 0) |
| 5798 | buflen = server->rsize; |
| 5799 | |
| 5800 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5801 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5802 | if (!pages) |
| 5803 | return -ENOMEM; |
| 5804 | |
| 5805 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5806 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5807 | for (i = 0; i < npages; i++) { |
| 5808 | pages[i] = alloc_page(GFP_KERNEL); |
| 5809 | if (!pages[i]) |
| 5810 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5811 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5812 | |
| 5813 | /* for decoding across pages */ |
| 5814 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5815 | if (!res.acl_scratch) |
| 5816 | goto out_free; |
| 5817 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5818 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5819 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5820 | 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] | 5821 | __func__, buf, buflen, npages, args.acl_len); |
| 5822 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5823 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5824 | if (ret) |
| 5825 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5826 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5827 | /* Handle the case where the passed-in buffer is too short */ |
| 5828 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5829 | /* Did the user only issue a request for the acl length? */ |
| 5830 | if (buf == NULL) |
| 5831 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5832 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5833 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5834 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5835 | 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] | 5836 | if (buf) { |
| 5837 | if (res.acl_len > buflen) { |
| 5838 | ret = -ERANGE; |
| 5839 | goto out_free; |
| 5840 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5841 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5842 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5843 | out_ok: |
| 5844 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5845 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5846 | for (i = 0; i < npages; i++) |
| 5847 | if (pages[i]) |
| 5848 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5849 | if (res.acl_scratch) |
| 5850 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5851 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5852 | return ret; |
| 5853 | } |
| 5854 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5855 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5856 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5857 | struct nfs4_exception exception = { |
| 5858 | .interruptible = true, |
| 5859 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5860 | ssize_t ret; |
| 5861 | do { |
| 5862 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5863 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5864 | if (ret >= 0) |
| 5865 | break; |
| 5866 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5867 | } while (exception.retry); |
| 5868 | return ret; |
| 5869 | } |
| 5870 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5871 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5872 | { |
| 5873 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5874 | int ret; |
| 5875 | |
| 5876 | if (!nfs4_server_supports_acls(server)) |
| 5877 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5878 | ret = nfs_revalidate_inode(server, inode); |
| 5879 | if (ret < 0) |
| 5880 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5881 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5882 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5883 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5884 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5885 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5886 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5887 | return ret; |
| 5888 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5889 | } |
| 5890 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5891 | 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] | 5892 | { |
| 5893 | struct nfs_server *server = NFS_SERVER(inode); |
| 5894 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5895 | struct nfs_setaclargs arg = { |
| 5896 | .fh = NFS_FH(inode), |
| 5897 | .acl_pages = pages, |
| 5898 | .acl_len = buflen, |
| 5899 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5900 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5901 | struct rpc_message msg = { |
| 5902 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5903 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5904 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5905 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5906 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5907 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5908 | |
J. Bruce Fields | 9f70460 | 2021-01-28 17:36:38 -0500 | [diff] [blame] | 5909 | /* You can't remove system.nfs4_acl: */ |
| 5910 | if (buflen == 0) |
| 5911 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5912 | if (!nfs4_server_supports_acls(server)) |
| 5913 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5914 | if (npages > ARRAY_SIZE(pages)) |
| 5915 | return -ERANGE; |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5916 | i = nfs4_buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5917 | if (i < 0) |
| 5918 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5919 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5920 | 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] | 5921 | |
| 5922 | /* |
| 5923 | * Free each page after tx, so the only ref left is |
| 5924 | * held by the network stack |
| 5925 | */ |
| 5926 | for (; i > 0; i--) |
| 5927 | put_page(pages[i-1]); |
| 5928 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5929 | /* |
| 5930 | * Acl update can result in inode attribute update. |
| 5931 | * so mark the attribute cache invalid. |
| 5932 | */ |
| 5933 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5934 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5935 | | NFS_INO_INVALID_CTIME |
| 5936 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5937 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5938 | nfs_access_zap_cache(inode); |
| 5939 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5940 | return ret; |
| 5941 | } |
| 5942 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5943 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5944 | { |
| 5945 | struct nfs4_exception exception = { }; |
| 5946 | int err; |
| 5947 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5948 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5949 | trace_nfs4_set_acl(inode, err); |
Dai Ngo | 6e13b9b | 2021-05-19 17:15:10 -0400 | [diff] [blame] | 5950 | if (err == -NFS4ERR_BADOWNER || err == -NFS4ERR_BADNAME) { |
| 5951 | /* |
| 5952 | * no need to retry since the kernel |
| 5953 | * isn't involved in encoding the ACEs. |
| 5954 | */ |
| 5955 | err = -EINVAL; |
| 5956 | break; |
| 5957 | } |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5958 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5959 | &exception); |
| 5960 | } while (exception.retry); |
| 5961 | return err; |
| 5962 | } |
| 5963 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5964 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5965 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5966 | size_t buflen) |
| 5967 | { |
| 5968 | struct nfs_server *server = NFS_SERVER(inode); |
| 5969 | struct nfs_fattr fattr; |
| 5970 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5971 | |
| 5972 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5973 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5974 | .fh = NFS_FH(inode), |
| 5975 | .bitmask = bitmask, |
| 5976 | }; |
| 5977 | struct nfs4_getattr_res res = { |
| 5978 | .fattr = &fattr, |
| 5979 | .label = &label, |
| 5980 | .server = server, |
| 5981 | }; |
| 5982 | struct rpc_message msg = { |
| 5983 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5984 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5985 | .rpc_resp = &res, |
| 5986 | }; |
| 5987 | int ret; |
| 5988 | |
| 5989 | nfs_fattr_init(&fattr); |
| 5990 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5991 | 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] | 5992 | if (ret) |
| 5993 | return ret; |
| 5994 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5995 | return -ENOENT; |
Ondrej Mosnacek | caa8690 | 2021-01-15 18:43:56 +0100 | [diff] [blame] | 5996 | return label.len; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 6000 | size_t buflen) |
| 6001 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6002 | struct nfs4_exception exception = { |
| 6003 | .interruptible = true, |
| 6004 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6005 | int err; |
| 6006 | |
| 6007 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6008 | return -EOPNOTSUPP; |
| 6009 | |
| 6010 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6011 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 6012 | trace_nfs4_get_security_label(inode, err); |
| 6013 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6014 | &exception); |
| 6015 | } while (exception.retry); |
| 6016 | return err; |
| 6017 | } |
| 6018 | |
| 6019 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 6020 | struct nfs4_label *ilabel, |
| 6021 | struct nfs_fattr *fattr, |
| 6022 | struct nfs4_label *olabel) |
| 6023 | { |
| 6024 | |
| 6025 | struct iattr sattr = {0}; |
| 6026 | struct nfs_server *server = NFS_SERVER(inode); |
| 6027 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6028 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6029 | .fh = NFS_FH(inode), |
| 6030 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6031 | .server = server, |
| 6032 | .bitmask = bitmask, |
| 6033 | .label = ilabel, |
| 6034 | }; |
| 6035 | struct nfs_setattrres res = { |
| 6036 | .fattr = fattr, |
| 6037 | .label = olabel, |
| 6038 | .server = server, |
| 6039 | }; |
| 6040 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6041 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 6042 | .rpc_argp = &arg, |
| 6043 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6044 | }; |
| 6045 | int status; |
| 6046 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6047 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6048 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6049 | 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] | 6050 | if (status) |
| 6051 | dprintk("%s failed: %d\n", __func__, status); |
| 6052 | |
| 6053 | return status; |
| 6054 | } |
| 6055 | |
| 6056 | static int nfs4_do_set_security_label(struct inode *inode, |
| 6057 | struct nfs4_label *ilabel, |
| 6058 | struct nfs_fattr *fattr, |
| 6059 | struct nfs4_label *olabel) |
| 6060 | { |
| 6061 | struct nfs4_exception exception = { }; |
| 6062 | int err; |
| 6063 | |
| 6064 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6065 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 6066 | fattr, olabel); |
| 6067 | trace_nfs4_set_security_label(inode, err); |
| 6068 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6069 | &exception); |
| 6070 | } while (exception.retry); |
| 6071 | return err; |
| 6072 | } |
| 6073 | |
| 6074 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6075 | 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] | 6076 | { |
| 6077 | struct nfs4_label ilabel, *olabel = NULL; |
| 6078 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6079 | int status; |
| 6080 | |
| 6081 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6082 | return -EOPNOTSUPP; |
| 6083 | |
| 6084 | nfs_fattr_init(&fattr); |
| 6085 | |
| 6086 | ilabel.pi = 0; |
| 6087 | ilabel.lfs = 0; |
| 6088 | ilabel.label = (char *)buf; |
| 6089 | ilabel.len = buflen; |
| 6090 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6091 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 6092 | if (IS_ERR(olabel)) { |
| 6093 | status = -PTR_ERR(olabel); |
| 6094 | goto out; |
| 6095 | } |
| 6096 | |
| 6097 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 6098 | if (status == 0) |
| 6099 | nfs_setsecurity(inode, &fattr, olabel); |
| 6100 | |
| 6101 | nfs4_label_free(olabel); |
| 6102 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6103 | return status; |
| 6104 | } |
| 6105 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 6106 | |
| 6107 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6108 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 6109 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6110 | { |
| 6111 | __be32 verf[2]; |
| 6112 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6113 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 6114 | /* An impossible timestamp guarantees this value |
| 6115 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6116 | verf[0] = cpu_to_be32(U32_MAX); |
| 6117 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6118 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6119 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6120 | u64 ns = ktime_to_ns(nn->boot_time); |
| 6121 | |
| 6122 | verf[0] = cpu_to_be32(ns >> 32); |
| 6123 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6124 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6125 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 6126 | } |
| 6127 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6128 | static size_t |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6129 | nfs4_get_uniquifier(struct nfs_client *clp, char *buf, size_t buflen) |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6130 | { |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6131 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 6132 | struct nfs_netns_client *nn_clp = nn->nfs_client; |
| 6133 | const char *id; |
| 6134 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6135 | buf[0] = '\0'; |
| 6136 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6137 | if (nn_clp) { |
| 6138 | rcu_read_lock(); |
| 6139 | id = rcu_dereference(nn_clp->identifier); |
| 6140 | if (id) |
| 6141 | strscpy(buf, id, buflen); |
| 6142 | rcu_read_unlock(); |
| 6143 | } |
| 6144 | |
| 6145 | if (nfs4_client_id_uniquifier[0] != '\0' && buf[0] == '\0') |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6146 | strscpy(buf, nfs4_client_id_uniquifier, buflen); |
| 6147 | |
| 6148 | return strlen(buf); |
| 6149 | } |
| 6150 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6151 | static int |
| 6152 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6153 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6154 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6155 | size_t buflen; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6156 | size_t len; |
| 6157 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6158 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6159 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6160 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 6161 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6162 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6163 | len = 14 + |
| 6164 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 6165 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6166 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6167 | 1; |
| 6168 | rcu_read_unlock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6169 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6170 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6171 | if (buflen) |
| 6172 | len += buflen + 1; |
| 6173 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6174 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6175 | return -EINVAL; |
| 6176 | |
| 6177 | /* |
| 6178 | * Since this string is allocated at mount time, and held until the |
| 6179 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6180 | * about a memory-reclaim deadlock. |
| 6181 | */ |
| 6182 | str = kmalloc(len, GFP_KERNEL); |
| 6183 | if (!str) |
| 6184 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6185 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6186 | rcu_read_lock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6187 | if (buflen) |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6188 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6189 | clp->cl_rpcclient->cl_nodename, buf, |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6190 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6191 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6192 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6193 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6194 | clp->cl_rpcclient->cl_nodename, |
| 6195 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6196 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6197 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6198 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6199 | clp->cl_owner_id = str; |
| 6200 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6201 | } |
| 6202 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6203 | static int |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6204 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6205 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6206 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6207 | size_t buflen; |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6208 | size_t len; |
| 6209 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6210 | |
| 6211 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6212 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6213 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6214 | len = 10 + 10 + 1 + 10 + 1 + |
| 6215 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6216 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6217 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6218 | if (buflen) |
| 6219 | len += buflen + 1; |
| 6220 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6221 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6222 | return -EINVAL; |
| 6223 | |
| 6224 | /* |
| 6225 | * Since this string is allocated at mount time, and held until the |
| 6226 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6227 | * about a memory-reclaim deadlock. |
| 6228 | */ |
| 6229 | str = kmalloc(len, GFP_KERNEL); |
| 6230 | if (!str) |
| 6231 | return -ENOMEM; |
| 6232 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6233 | if (buflen) |
| 6234 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
| 6235 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6236 | buf, clp->cl_rpcclient->cl_nodename); |
| 6237 | else |
| 6238 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
| 6239 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6240 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6241 | clp->cl_owner_id = str; |
| 6242 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6243 | } |
| 6244 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6245 | /* |
| 6246 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6247 | * services. Advertise one based on the address family of the |
| 6248 | * clientaddr. |
| 6249 | */ |
| 6250 | static unsigned int |
| 6251 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6252 | { |
| 6253 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6254 | return scnprintf(buf, len, "tcp6"); |
| 6255 | else |
| 6256 | return scnprintf(buf, len, "tcp"); |
| 6257 | } |
| 6258 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6259 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6260 | { |
| 6261 | struct nfs4_setclientid *sc = calldata; |
| 6262 | |
| 6263 | if (task->tk_status == 0) |
| 6264 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6265 | } |
| 6266 | |
| 6267 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6268 | .rpc_call_done = nfs4_setclientid_done, |
| 6269 | }; |
| 6270 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6271 | /** |
| 6272 | * nfs4_proc_setclientid - Negotiate client ID |
| 6273 | * @clp: state data structure |
| 6274 | * @program: RPC program for NFSv4 callback service |
| 6275 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6276 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6277 | * @res: where to place the result |
| 6278 | * |
| 6279 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6280 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6281 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6282 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6283 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | { |
| 6285 | nfs4_verifier sc_verifier; |
| 6286 | struct nfs4_setclientid setclientid = { |
| 6287 | .sc_verifier = &sc_verifier, |
| 6288 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6289 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | }; |
| 6291 | struct rpc_message msg = { |
| 6292 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6293 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6294 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6295 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6297 | struct rpc_task_setup task_setup_data = { |
| 6298 | .rpc_client = clp->cl_rpcclient, |
| 6299 | .rpc_message = &msg, |
| 6300 | .callback_ops = &nfs4_setclientid_ops, |
| 6301 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6302 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6303 | }; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6304 | unsigned long now = jiffies; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6305 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6306 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6307 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6308 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6309 | |
| 6310 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6311 | status = nfs4_init_uniform_client_string(clp); |
| 6312 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6313 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6314 | |
| 6315 | if (status) |
| 6316 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6317 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6318 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6319 | setclientid.sc_netid_len = |
| 6320 | nfs4_init_callback_netid(clp, |
| 6321 | setclientid.sc_netid, |
| 6322 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6323 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6324 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6325 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6326 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6327 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6328 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6329 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6330 | |
| 6331 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6332 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6333 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6334 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6335 | put_rpccred(setclientid.sc_cred); |
| 6336 | } |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6337 | |
| 6338 | if (status == 0) |
| 6339 | do_renew_lease(clp, now); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6340 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6341 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6342 | dprintk("NFS reply setclientid: %d\n", status); |
| 6343 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6344 | } |
| 6345 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6346 | /** |
| 6347 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6348 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6349 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6350 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6351 | * |
| 6352 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6353 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6354 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6355 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6356 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6357 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6358 | struct rpc_message msg = { |
| 6359 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6360 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6361 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6362 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6363 | int status; |
| 6364 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6365 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6366 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6367 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6368 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6369 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6370 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6371 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6372 | return status; |
| 6373 | } |
| 6374 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6375 | struct nfs4_delegreturndata { |
| 6376 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6377 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6378 | struct nfs_fh fh; |
| 6379 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6380 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6381 | struct { |
| 6382 | struct nfs4_layoutreturn_args arg; |
| 6383 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6384 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6385 | u32 roc_barrier; |
| 6386 | bool roc; |
| 6387 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6388 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6389 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6390 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6391 | }; |
| 6392 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6393 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6394 | { |
| 6395 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6396 | struct nfs4_exception exception = { |
| 6397 | .inode = data->inode, |
| 6398 | .stateid = &data->stateid, |
Trond Myklebust | b4651ce | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 6399 | .task_is_privileged = data->args.seq_args.sa_privileged, |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6400 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6401 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6402 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6403 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6404 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6405 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6406 | |
| 6407 | /* Handle Layoutreturn errors */ |
Trond Myklebust | f128de1 | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6408 | if (pnfs_roc_done(task, &data->args.lr_args, &data->res.lr_res, |
| 6409 | &data->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6410 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6411 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6412 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6413 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6414 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6415 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6416 | case -NFS4ERR_ADMIN_REVOKED: |
| 6417 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6418 | case -NFS4ERR_EXPIRED: |
| 6419 | nfs4_free_revoked_stateid(data->res.server, |
| 6420 | data->args.stateid, |
| 6421 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6422 | fallthrough; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6423 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6424 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 244fcd2 | 2019-12-20 10:43:37 -0500 | [diff] [blame] | 6425 | case -ETIMEDOUT: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6426 | task->tk_status = 0; |
| 6427 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6428 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6429 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6430 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6431 | if (data->args.bitmask) { |
| 6432 | data->args.bitmask = NULL; |
| 6433 | data->res.fattr = NULL; |
| 6434 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6435 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6436 | case -NFS4ERR_ACCESS: |
| 6437 | if (data->args.bitmask) { |
| 6438 | data->args.bitmask = NULL; |
| 6439 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6440 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6441 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6442 | fallthrough; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6443 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6444 | task->tk_status = nfs4_async_handle_exception(task, |
| 6445 | data->res.server, task->tk_status, |
| 6446 | &exception); |
| 6447 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6448 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6449 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6450 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6451 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6452 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6453 | out_restart: |
| 6454 | task->tk_status = 0; |
| 6455 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6456 | } |
| 6457 | |
| 6458 | static void nfs4_delegreturn_release(void *calldata) |
| 6459 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6460 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6461 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6462 | |
Trond Myklebust | f128de1 | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6463 | if (data->lr.roc) |
| 6464 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6465 | data->res.lr_ret); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6466 | if (inode) { |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6467 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6468 | nfs_iput_and_deactive(inode); |
| 6469 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6470 | kfree(calldata); |
| 6471 | } |
| 6472 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6473 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6474 | { |
| 6475 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6476 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6477 | |
| 6478 | d_data = (struct nfs4_delegreturndata *)data; |
| 6479 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6480 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6481 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6482 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6483 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6484 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6485 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6486 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6487 | d_data->args.lr_args = NULL; |
| 6488 | d_data->res.lr_res = NULL; |
| 6489 | } |
| 6490 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6491 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6492 | &d_data->args.seq_args, |
| 6493 | &d_data->res.seq_res, |
| 6494 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6495 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6496 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6497 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6498 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6499 | .rpc_call_done = nfs4_delegreturn_done, |
| 6500 | .rpc_release = nfs4_delegreturn_release, |
| 6501 | }; |
| 6502 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6503 | static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6504 | { |
| 6505 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6506 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6507 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6508 | struct rpc_message msg = { |
| 6509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6510 | .rpc_cred = cred, |
| 6511 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6512 | struct rpc_task_setup task_setup_data = { |
| 6513 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6514 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6515 | .callback_ops = &nfs4_delegreturn_ops, |
Trond Myklebust | f304a80 | 2020-05-11 10:42:04 -0400 | [diff] [blame] | 6516 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6517 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6518 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6519 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6520 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6521 | if (data == NULL) |
| 6522 | return -ENOMEM; |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6523 | |
| 6524 | nfs4_state_protect(server->nfs_client, |
| 6525 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6526 | &task_setup_data.rpc_client, &msg); |
| 6527 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6528 | data->args.fhandle = &data->fh; |
| 6529 | data->args.stateid = &data->stateid; |
Trond Myklebust | ce2b470 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 6530 | nfs4_bitmask_set(data->args.bitmask_store, |
| 6531 | server->cache_consistency_bitmask, inode, server, |
| 6532 | NULL); |
| 6533 | data->args.bitmask = data->args.bitmask_store; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6534 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6535 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6536 | data->res.fattr = &data->fattr; |
| 6537 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6538 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6539 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6540 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6541 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6542 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6543 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | f128de1 | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6544 | if (data->inode || issync) { |
| 6545 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, |
| 6546 | cred); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6547 | if (data->lr.roc) { |
| 6548 | data->args.lr_args = &data->lr.arg; |
| 6549 | data->res.lr_res = &data->lr.res; |
| 6550 | } |
| 6551 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6552 | |
Trond Myklebust | b4651ce | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 6553 | if (!data->inode) |
| 6554 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, |
| 6555 | 1); |
| 6556 | else |
| 6557 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, |
| 6558 | 0); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6559 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6560 | msg.rpc_argp = &data->args; |
| 6561 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6562 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6563 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6564 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6565 | if (!issync) |
| 6566 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6567 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6568 | if (status != 0) |
| 6569 | goto out; |
| 6570 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6571 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6572 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6573 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6574 | } |
| 6575 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6576 | int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6577 | { |
| 6578 | struct nfs_server *server = NFS_SERVER(inode); |
| 6579 | struct nfs4_exception exception = { }; |
| 6580 | int err; |
| 6581 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6582 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6583 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6584 | switch (err) { |
| 6585 | case -NFS4ERR_STALE_STATEID: |
| 6586 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6587 | case 0: |
| 6588 | return 0; |
| 6589 | } |
| 6590 | err = nfs4_handle_exception(server, err, &exception); |
| 6591 | } while (exception.retry); |
| 6592 | return err; |
| 6593 | } |
| 6594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6595 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6596 | { |
| 6597 | struct inode *inode = state->inode; |
| 6598 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6599 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6600 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6601 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6602 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6603 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6604 | struct nfs_lockt_res res = { |
| 6605 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6606 | }; |
| 6607 | struct rpc_message msg = { |
| 6608 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6609 | .rpc_argp = &arg, |
| 6610 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6611 | .rpc_cred = state->owner->so_cred, |
| 6612 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6613 | struct nfs4_lock_state *lsp; |
| 6614 | int status; |
| 6615 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6616 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6617 | status = nfs4_set_lock_state(state, request); |
| 6618 | if (status != 0) |
| 6619 | goto out; |
| 6620 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6621 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6622 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6623 | 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] | 6624 | switch (status) { |
| 6625 | case 0: |
| 6626 | request->fl_type = F_UNLCK; |
| 6627 | break; |
| 6628 | case -NFS4ERR_DENIED: |
| 6629 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6630 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6631 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6632 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6633 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6634 | return status; |
| 6635 | } |
| 6636 | |
| 6637 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6638 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6639 | struct nfs4_exception exception = { |
| 6640 | .interruptible = true, |
| 6641 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6642 | int err; |
| 6643 | |
| 6644 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6645 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6646 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6647 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6648 | &exception); |
| 6649 | } while (exception.retry); |
| 6650 | return err; |
| 6651 | } |
| 6652 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6653 | /* |
| 6654 | * Update the seqid of a lock stateid after receiving |
| 6655 | * NFS4ERR_OLD_STATEID |
| 6656 | */ |
| 6657 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6658 | struct nfs4_lock_state *lsp) |
| 6659 | { |
| 6660 | struct nfs4_state *state = lsp->ls_state; |
| 6661 | bool ret = false; |
| 6662 | |
| 6663 | spin_lock(&state->state_lock); |
| 6664 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6665 | goto out; |
| 6666 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6667 | nfs4_stateid_seqid_inc(dst); |
| 6668 | else |
| 6669 | dst->seqid = lsp->ls_stateid.seqid; |
| 6670 | ret = true; |
| 6671 | out: |
| 6672 | spin_unlock(&state->state_lock); |
| 6673 | return ret; |
| 6674 | } |
| 6675 | |
| 6676 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6677 | struct nfs4_lock_state *lsp) |
| 6678 | { |
| 6679 | struct nfs4_state *state = lsp->ls_state; |
| 6680 | bool ret; |
| 6681 | |
| 6682 | spin_lock(&state->state_lock); |
| 6683 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6684 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6685 | spin_unlock(&state->state_lock); |
| 6686 | return ret; |
| 6687 | } |
| 6688 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6689 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6690 | struct nfs_locku_args arg; |
| 6691 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6692 | struct nfs4_lock_state *lsp; |
| 6693 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6694 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6695 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6696 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6697 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6698 | }; |
| 6699 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6700 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6701 | struct nfs_open_context *ctx, |
| 6702 | struct nfs4_lock_state *lsp, |
| 6703 | struct nfs_seqid *seqid) |
| 6704 | { |
| 6705 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6706 | struct nfs4_state *state = lsp->ls_state; |
| 6707 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6708 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6709 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6710 | if (p == NULL) |
| 6711 | return NULL; |
| 6712 | p->arg.fh = NFS_FH(inode); |
| 6713 | p->arg.fl = &p->fl; |
| 6714 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6715 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6716 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6717 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6718 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6719 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6720 | locks_init_lock(&p->fl); |
| 6721 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6722 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6723 | spin_lock(&state->state_lock); |
| 6724 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6725 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6726 | return p; |
| 6727 | } |
| 6728 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6729 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6730 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6731 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6732 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6733 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6734 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6735 | put_nfs_open_context(calldata->ctx); |
| 6736 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6737 | } |
| 6738 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6739 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6740 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6741 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6742 | struct nfs4_exception exception = { |
| 6743 | .inode = calldata->lsp->ls_state->inode, |
| 6744 | .stateid = &calldata->arg.stateid, |
| 6745 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6746 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6747 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6748 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6749 | switch (task->tk_status) { |
| 6750 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6751 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6752 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6753 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6754 | &calldata->res.stateid)) |
| 6755 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6756 | fallthrough; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6757 | case -NFS4ERR_ADMIN_REVOKED: |
| 6758 | case -NFS4ERR_EXPIRED: |
| 6759 | nfs4_free_revoked_stateid(calldata->server, |
| 6760 | &calldata->arg.stateid, |
| 6761 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6762 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6763 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6764 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6765 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6766 | calldata->lsp)) |
| 6767 | rpc_restart_call_prepare(task); |
| 6768 | break; |
| 6769 | case -NFS4ERR_OLD_STATEID: |
| 6770 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6771 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6772 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6773 | break; |
| 6774 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6775 | task->tk_status = nfs4_async_handle_exception(task, |
| 6776 | calldata->server, task->tk_status, |
| 6777 | &exception); |
| 6778 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6779 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6780 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6781 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6782 | } |
| 6783 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6784 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6785 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6786 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6787 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6788 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6789 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6790 | return; |
| 6791 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6792 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6793 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6794 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6795 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6796 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6797 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6798 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6799 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6800 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6801 | &calldata->res.seq_res, |
| 6802 | task) != 0) |
| 6803 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6804 | return; |
| 6805 | out_no_action: |
| 6806 | task->tk_action = NULL; |
| 6807 | out_wait: |
| 6808 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6809 | } |
| 6810 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6811 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6812 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6813 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6814 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6815 | }; |
| 6816 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6817 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6818 | struct nfs_open_context *ctx, |
| 6819 | struct nfs4_lock_state *lsp, |
| 6820 | struct nfs_seqid *seqid) |
| 6821 | { |
| 6822 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6823 | struct rpc_message msg = { |
| 6824 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6825 | .rpc_cred = ctx->cred, |
| 6826 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6827 | struct rpc_task_setup task_setup_data = { |
| 6828 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6829 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6830 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6831 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6832 | .flags = RPC_TASK_ASYNC, |
| 6833 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6834 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6835 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6836 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6837 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6838 | /* Ensure this is an unlock - when canceling a lock, the |
| 6839 | * canceled lock is passed in, and it won't be an unlock. |
| 6840 | */ |
| 6841 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6842 | if (fl->fl_flags & FL_CLOSE) |
| 6843 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6844 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6845 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6846 | if (data == NULL) { |
| 6847 | nfs_free_seqid(seqid); |
| 6848 | return ERR_PTR(-ENOMEM); |
| 6849 | } |
| 6850 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6851 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, 0); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6852 | msg.rpc_argp = &data->arg; |
| 6853 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6854 | task_setup_data.callback_data = data; |
| 6855 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6856 | } |
| 6857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6858 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6859 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6860 | struct inode *inode = state->inode; |
| 6861 | struct nfs4_state_owner *sp = state->owner; |
| 6862 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6863 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6864 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6865 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6866 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6867 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6868 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6869 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6870 | status = nfs4_set_lock_state(state, request); |
| 6871 | /* Unlock _before_ we do the RPC call */ |
| 6872 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6873 | /* Exclude nfs_delegation_claim_locks() */ |
| 6874 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6875 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6876 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6877 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6878 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6879 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6880 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6881 | } |
| 6882 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6883 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6884 | if (status != 0) |
| 6885 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6886 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6887 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6888 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6889 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6890 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6891 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6892 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6893 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6894 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6895 | 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] | 6896 | status = PTR_ERR(task); |
| 6897 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6898 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6899 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6900 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6901 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6902 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6903 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6904 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6905 | } |
| 6906 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6907 | struct nfs4_lockdata { |
| 6908 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6909 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6910 | struct nfs4_lock_state *lsp; |
| 6911 | struct nfs_open_context *ctx; |
| 6912 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6913 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6914 | int rpc_status; |
| 6915 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6916 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6917 | }; |
| 6918 | |
| 6919 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6920 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6921 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6922 | { |
| 6923 | struct nfs4_lockdata *p; |
| 6924 | struct inode *inode = lsp->ls_state->inode; |
| 6925 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6926 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6927 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6928 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6929 | if (p == NULL) |
| 6930 | return NULL; |
| 6931 | |
| 6932 | p->arg.fh = NFS_FH(inode); |
| 6933 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6934 | 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] | 6935 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6936 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6937 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6938 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6939 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6940 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6941 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6942 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6943 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6944 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6945 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6946 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6947 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6948 | locks_init_lock(&p->fl); |
| 6949 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6950 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6951 | out_free_seqid: |
| 6952 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6953 | out_free: |
| 6954 | kfree(p); |
| 6955 | return NULL; |
| 6956 | } |
| 6957 | |
| 6958 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6959 | { |
| 6960 | struct nfs4_lockdata *data = calldata; |
| 6961 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6962 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6963 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6964 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6965 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6966 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6967 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6968 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6969 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6970 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6971 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6972 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6973 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6974 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6975 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6976 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6977 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6978 | &data->lsp->ls_stateid); |
| 6979 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6980 | if (!nfs4_valid_open_stateid(state)) { |
| 6981 | data->rpc_status = -EBADF; |
| 6982 | task->tk_action = NULL; |
| 6983 | goto out_release_open_seqid; |
| 6984 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6985 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6986 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6987 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6988 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6989 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6990 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6991 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6992 | nfs_release_seqid(data->arg.open_seqid); |
| 6993 | out_release_lock_seqid: |
| 6994 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6995 | out_wait: |
| 6996 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6997 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6998 | } |
| 6999 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7000 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 7001 | { |
| 7002 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7003 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7004 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7005 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7006 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7007 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 7008 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 7009 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7010 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7011 | switch (task->tk_status) { |
| 7012 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 7013 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7014 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7015 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7016 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7017 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7018 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7019 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7020 | if (data->arg.new_lock_owner != 0) { |
| 7021 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 7022 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 7023 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7024 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 7025 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7026 | break; |
| 7027 | case -NFS4ERR_BAD_STATEID: |
| 7028 | case -NFS4ERR_OLD_STATEID: |
| 7029 | case -NFS4ERR_STALE_STATEID: |
| 7030 | case -NFS4ERR_EXPIRED: |
| 7031 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7032 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7033 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7034 | goto out_restart; |
| 7035 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7036 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7037 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7038 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7039 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7040 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7041 | return; |
| 7042 | out_restart: |
| 7043 | if (!data->cancelled) |
| 7044 | rpc_restart_call_prepare(task); |
| 7045 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7046 | } |
| 7047 | |
| 7048 | static void nfs4_lock_release(void *calldata) |
| 7049 | { |
| 7050 | struct nfs4_lockdata *data = calldata; |
| 7051 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7052 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7053 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7054 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7055 | struct rpc_task *task; |
| 7056 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 7057 | data->arg.lock_seqid); |
| 7058 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7059 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7060 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7061 | } else |
| 7062 | nfs_free_seqid(data->arg.lock_seqid); |
| 7063 | nfs4_put_lock_state(data->lsp); |
| 7064 | put_nfs_open_context(data->ctx); |
| 7065 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7066 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7067 | } |
| 7068 | |
| 7069 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 7070 | .rpc_call_prepare = nfs4_lock_prepare, |
| 7071 | .rpc_call_done = nfs4_lock_done, |
| 7072 | .rpc_release = nfs4_lock_release, |
| 7073 | }; |
| 7074 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7075 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 7076 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7077 | switch (error) { |
| 7078 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 7079 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7080 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7081 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7082 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 7083 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7084 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7085 | break; |
| 7086 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7087 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7088 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 7089 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7090 | } |
| 7091 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7092 | 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] | 7093 | { |
| 7094 | struct nfs4_lockdata *data; |
| 7095 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7096 | struct rpc_message msg = { |
| 7097 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 7098 | .rpc_cred = state->owner->so_cred, |
| 7099 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7100 | struct rpc_task_setup task_setup_data = { |
| 7101 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7102 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7103 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 7104 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 7105 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7106 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7107 | int ret; |
| 7108 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7109 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7110 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7111 | fl->fl_u.nfs4_fl.owner, |
| 7112 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7113 | if (data == NULL) |
| 7114 | return -ENOMEM; |
| 7115 | if (IS_SETLKW(cmd)) |
| 7116 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7117 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 7118 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 7119 | msg.rpc_argp = &data->arg; |
| 7120 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7121 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7122 | if (recovery_type > NFS_LOCK_NEW) { |
| 7123 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 7124 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7125 | } else |
| 7126 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7127 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 7128 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7129 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 7130 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7131 | if (ret == 0) { |
| 7132 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7133 | if (ret) |
| 7134 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 7135 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7136 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 7137 | data->cancelled = true; |
Dave Wysochanski | 1b42712 | 2020-12-11 05:12:51 -0500 | [diff] [blame] | 7138 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 7139 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7140 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7141 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7142 | } |
| 7143 | |
| 7144 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 7145 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7146 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7147 | struct nfs4_exception exception = { |
| 7148 | .inode = state->inode, |
| 7149 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7150 | int err; |
| 7151 | |
| 7152 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7153 | /* Cache the lock if possible... */ |
| 7154 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7155 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7156 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 7157 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7158 | break; |
| 7159 | nfs4_handle_exception(server, err, &exception); |
| 7160 | } while (exception.retry); |
| 7161 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7165 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7166 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7167 | struct nfs4_exception exception = { |
| 7168 | .inode = state->inode, |
| 7169 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7170 | int err; |
| 7171 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 7172 | err = nfs4_set_lock_state(state, request); |
| 7173 | if (err != 0) |
| 7174 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 7175 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 7176 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 7177 | return 0; |
| 7178 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7179 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7180 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7181 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7182 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7183 | switch (err) { |
| 7184 | default: |
| 7185 | goto out; |
| 7186 | case -NFS4ERR_GRACE: |
| 7187 | case -NFS4ERR_DELAY: |
| 7188 | nfs4_handle_exception(server, err, &exception); |
| 7189 | err = 0; |
| 7190 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7191 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7192 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7193 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7194 | } |
| 7195 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7196 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7197 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7198 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7199 | struct nfs4_lock_state *lsp; |
| 7200 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7201 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7202 | status = nfs4_set_lock_state(state, request); |
| 7203 | if (status != 0) |
| 7204 | return status; |
| 7205 | lsp = request->fl_u.nfs4_fl.owner; |
| 7206 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7207 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7208 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7209 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7210 | } |
| 7211 | #endif |
| 7212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7213 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7214 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7215 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7216 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7217 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7218 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7219 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7220 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7221 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7222 | if (status < 0) |
| 7223 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7224 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7225 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7226 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7227 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7228 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7229 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7230 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7231 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7232 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7233 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7234 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7235 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7236 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7237 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7238 | out: |
| 7239 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7240 | return status; |
| 7241 | } |
| 7242 | |
| 7243 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7244 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7245 | struct nfs4_exception exception = { |
| 7246 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7247 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7248 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7249 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7250 | int err; |
| 7251 | |
| 7252 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7253 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7254 | if (err == -NFS4ERR_DENIED) |
| 7255 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7256 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7257 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7258 | } while (exception.retry); |
| 7259 | return err; |
| 7260 | } |
| 7261 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7262 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7263 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7264 | |
| 7265 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7266 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7267 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7268 | { |
| 7269 | int status = -ERESTARTSYS; |
| 7270 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7271 | |
| 7272 | while(!signalled()) { |
| 7273 | status = nfs4_proc_setlk(state, cmd, request); |
| 7274 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7275 | break; |
| 7276 | freezable_schedule_timeout_interruptible(timeout); |
| 7277 | timeout *= 2; |
| 7278 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7279 | status = -ERESTARTSYS; |
| 7280 | } |
| 7281 | return status; |
| 7282 | } |
| 7283 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7284 | #ifdef CONFIG_NFS_V4_1 |
| 7285 | struct nfs4_lock_waiter { |
| 7286 | struct task_struct *task; |
| 7287 | struct inode *inode; |
| 7288 | struct nfs_lowner *owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7289 | }; |
| 7290 | |
| 7291 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7292 | 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] | 7293 | { |
| 7294 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7295 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7296 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7297 | /* NULL key means to wake up everyone */ |
| 7298 | if (key) { |
| 7299 | struct cb_notify_lock_args *cbnl = key; |
| 7300 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 7301 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7302 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7303 | /* Only wake if the callback was for the same owner. */ |
| 7304 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7305 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7306 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7307 | /* Make sure it's for the right inode */ |
| 7308 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7309 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7310 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7311 | |
| 7312 | /* override "private" so we can use default_wake_function */ |
| 7313 | wait->private = waiter->task; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7314 | ret = woken_wake_function(wait, mode, flags, key); |
| 7315 | if (ret) |
| 7316 | list_del_init(&wait->entry); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7317 | wait->private = waiter; |
| 7318 | return ret; |
| 7319 | } |
| 7320 | |
| 7321 | static int |
| 7322 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7323 | { |
| 7324 | int status = -ERESTARTSYS; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7325 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7326 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7327 | struct nfs_client *clp = server->nfs_client; |
| 7328 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 7329 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 7330 | .id = lsp->ls_seqid.owner_id, |
| 7331 | .s_dev = server->s_dev }; |
| 7332 | struct nfs4_lock_waiter waiter = { .task = current, |
| 7333 | .inode = state->inode, |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7334 | .owner = &owner}; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7335 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7336 | |
| 7337 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7338 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7339 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7340 | |
| 7341 | init_wait(&wait); |
| 7342 | wait.private = &waiter; |
| 7343 | wait.func = nfs4_wake_lock_waiter; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7344 | |
| 7345 | while(!signalled()) { |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7346 | add_wait_queue(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7347 | status = nfs4_proc_setlk(state, cmd, request); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7348 | if ((status != -EAGAIN) || IS_SETLK(cmd)) { |
| 7349 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7350 | break; |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7351 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7352 | |
| 7353 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7354 | freezer_do_not_count(); |
| 7355 | wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT); |
| 7356 | freezer_count(); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7357 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7358 | } |
| 7359 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7360 | return status; |
| 7361 | } |
| 7362 | #else /* !CONFIG_NFS_V4_1 */ |
| 7363 | static inline int |
| 7364 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7365 | { |
| 7366 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7367 | } |
| 7368 | #endif |
| 7369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7370 | static int |
| 7371 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7372 | { |
| 7373 | struct nfs_open_context *ctx; |
| 7374 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7375 | int status; |
| 7376 | |
| 7377 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7378 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7379 | state = ctx->state; |
| 7380 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7381 | if (IS_GETLK(cmd)) { |
| 7382 | if (state != NULL) |
| 7383 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7384 | return 0; |
| 7385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7386 | |
| 7387 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7388 | return -EINVAL; |
| 7389 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7390 | if (request->fl_type == F_UNLCK) { |
| 7391 | if (state != NULL) |
| 7392 | return nfs4_proc_unlck(state, cmd, request); |
| 7393 | return 0; |
| 7394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7395 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7396 | if (state == NULL) |
| 7397 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7398 | |
| 7399 | if ((request->fl_flags & FL_POSIX) && |
| 7400 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7401 | return -ENOLCK; |
| 7402 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7403 | /* |
| 7404 | * Don't rely on the VFS having checked the file open mode, |
| 7405 | * since it won't do this for flock() locks. |
| 7406 | */ |
| 7407 | switch (request->fl_type) { |
| 7408 | case F_RDLCK: |
| 7409 | if (!(filp->f_mode & FMODE_READ)) |
| 7410 | return -EBADF; |
| 7411 | break; |
| 7412 | case F_WRLCK: |
| 7413 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7414 | return -EBADF; |
| 7415 | } |
| 7416 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7417 | status = nfs4_set_lock_state(state, request); |
| 7418 | if (status != 0) |
| 7419 | return status; |
| 7420 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7421 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7422 | } |
| 7423 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7424 | 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] | 7425 | { |
| 7426 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7427 | int err; |
| 7428 | |
| 7429 | err = nfs4_set_lock_state(state, fl); |
| 7430 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7431 | return err; |
Olga Kornievskaia | 3d7a952 | 2020-08-20 18:52:43 -0400 | [diff] [blame] | 7432 | do { |
| 7433 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
| 7434 | if (err != -NFS4ERR_DELAY) |
| 7435 | break; |
| 7436 | ssleep(1); |
| 7437 | } while (err == -NFS4ERR_DELAY); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7438 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7439 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7440 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7441 | struct nfs_release_lockowner_data { |
| 7442 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7443 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7444 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7445 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7446 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7447 | }; |
| 7448 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7449 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7450 | { |
| 7451 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7452 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7453 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7454 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7455 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7456 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7457 | } |
| 7458 | |
| 7459 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7460 | { |
| 7461 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7462 | struct nfs_server *server = data->server; |
| 7463 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7464 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7465 | |
| 7466 | switch (task->tk_status) { |
| 7467 | case 0: |
| 7468 | renew_lease(server, data->timestamp); |
| 7469 | break; |
| 7470 | case -NFS4ERR_STALE_CLIENTID: |
| 7471 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7472 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7473 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7474 | case -NFS4ERR_LEASE_MOVED: |
| 7475 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7476 | if (nfs4_async_handle_error(task, server, |
| 7477 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7478 | rpc_restart_call_prepare(task); |
| 7479 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7480 | } |
| 7481 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7482 | static void nfs4_release_lockowner_release(void *calldata) |
| 7483 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7484 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7485 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7486 | kfree(calldata); |
| 7487 | } |
| 7488 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7489 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7490 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7491 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7492 | .rpc_release = nfs4_release_lockowner_release, |
| 7493 | }; |
| 7494 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7495 | static void |
| 7496 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7497 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7498 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7499 | struct rpc_message msg = { |
| 7500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7501 | }; |
| 7502 | |
| 7503 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7504 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7505 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7506 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7507 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7508 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7509 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7510 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7511 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7512 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7513 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7514 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7515 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7516 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7517 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7518 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7519 | } |
| 7520 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7521 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7522 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7523 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7524 | struct dentry *unused, struct inode *inode, |
| 7525 | const char *key, const void *buf, |
| 7526 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7527 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7528 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7529 | } |
| 7530 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7531 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7532 | struct dentry *unused, struct inode *inode, |
Mark Salyzyn | 3484eba | 2019-11-04 08:57:10 -0800 | [diff] [blame] | 7533 | const char *key, void *buf, size_t buflen, |
| 7534 | int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7535 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7536 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7537 | } |
| 7538 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7539 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7540 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7541 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7542 | } |
| 7543 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7544 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7545 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7546 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7547 | struct dentry *unused, struct inode *inode, |
| 7548 | const char *key, const void *buf, |
| 7549 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7550 | { |
| 7551 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7552 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7553 | |
| 7554 | return -EOPNOTSUPP; |
| 7555 | } |
| 7556 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7557 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7558 | struct dentry *unused, struct inode *inode, |
Mark Salyzyn | 3484eba | 2019-11-04 08:57:10 -0800 | [diff] [blame] | 7559 | const char *key, void *buf, size_t buflen, |
| 7560 | int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7561 | { |
| 7562 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7563 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7564 | return -EOPNOTSUPP; |
| 7565 | } |
| 7566 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7567 | static ssize_t |
| 7568 | 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] | 7569 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7570 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7571 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7572 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7573 | len = security_inode_listsecurity(inode, list, list_len); |
Chengguang Xu | 82c596e | 2020-06-17 09:09:39 +0800 | [diff] [blame] | 7574 | if (len >= 0 && list_len && len > list_len) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7575 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7576 | } |
| 7577 | return len; |
| 7578 | } |
| 7579 | |
| 7580 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7581 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7582 | .get = nfs4_xattr_get_nfs4_label, |
| 7583 | .set = nfs4_xattr_set_nfs4_label, |
| 7584 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7585 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7586 | #else |
| 7587 | |
| 7588 | static ssize_t |
| 7589 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7590 | { |
| 7591 | return 0; |
| 7592 | } |
| 7593 | |
| 7594 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7595 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7596 | #ifdef CONFIG_NFS_V4_2 |
| 7597 | static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler, |
| 7598 | struct dentry *unused, struct inode *inode, |
| 7599 | const char *key, const void *buf, |
| 7600 | size_t buflen, int flags) |
| 7601 | { |
| 7602 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7603 | int ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7604 | |
| 7605 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7606 | return -EOPNOTSUPP; |
| 7607 | |
| 7608 | /* |
| 7609 | * There is no mapping from the MAY_* flags to the NFS_ACCESS_XA* |
| 7610 | * flags right now. Handling of xattr operations use the normal |
| 7611 | * file read/write permissions. |
| 7612 | * |
| 7613 | * Just in case the server has other ideas (which RFC 8276 allows), |
| 7614 | * do a cached access check for the XA* flags to possibly avoid |
| 7615 | * doing an RPC and getting EACCES back. |
| 7616 | */ |
| 7617 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7618 | if (!(cache.mask & NFS_ACCESS_XAWRITE)) |
| 7619 | return -EACCES; |
| 7620 | } |
| 7621 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7622 | if (buf == NULL) { |
| 7623 | ret = nfs42_proc_removexattr(inode, key); |
| 7624 | if (!ret) |
| 7625 | nfs4_xattr_cache_remove(inode, key); |
| 7626 | } else { |
| 7627 | ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags); |
| 7628 | if (!ret) |
| 7629 | nfs4_xattr_cache_add(inode, key, buf, NULL, buflen); |
| 7630 | } |
| 7631 | |
| 7632 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7633 | } |
| 7634 | |
| 7635 | static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler, |
| 7636 | struct dentry *unused, struct inode *inode, |
Greg Kroah-Hartman | 4aeb613 | 2020-08-17 09:24:44 +0200 | [diff] [blame] | 7637 | const char *key, void *buf, size_t buflen, |
| 7638 | int flags) |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7639 | { |
| 7640 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7641 | ssize_t ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7642 | |
| 7643 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7644 | return -EOPNOTSUPP; |
| 7645 | |
| 7646 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7647 | if (!(cache.mask & NFS_ACCESS_XAREAD)) |
| 7648 | return -EACCES; |
| 7649 | } |
| 7650 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7651 | ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); |
| 7652 | if (ret) |
| 7653 | return ret; |
| 7654 | |
| 7655 | ret = nfs4_xattr_cache_get(inode, key, buf, buflen); |
| 7656 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7657 | return ret; |
| 7658 | |
| 7659 | ret = nfs42_proc_getxattr(inode, key, buf, buflen); |
| 7660 | |
| 7661 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7662 | } |
| 7663 | |
| 7664 | static ssize_t |
| 7665 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7666 | { |
| 7667 | u64 cookie; |
| 7668 | bool eof; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7669 | ssize_t ret, size; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7670 | char *buf; |
| 7671 | size_t buflen; |
| 7672 | struct nfs_access_entry cache; |
| 7673 | |
| 7674 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7675 | return 0; |
| 7676 | |
| 7677 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7678 | if (!(cache.mask & NFS_ACCESS_XALIST)) |
| 7679 | return 0; |
| 7680 | } |
| 7681 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7682 | ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); |
| 7683 | if (ret) |
| 7684 | return ret; |
| 7685 | |
| 7686 | ret = nfs4_xattr_cache_list(inode, list, list_len); |
| 7687 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7688 | return ret; |
| 7689 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7690 | cookie = 0; |
| 7691 | eof = false; |
| 7692 | buflen = list_len ? list_len : XATTR_LIST_MAX; |
| 7693 | buf = list_len ? list : NULL; |
| 7694 | size = 0; |
| 7695 | |
| 7696 | while (!eof) { |
| 7697 | ret = nfs42_proc_listxattrs(inode, buf, buflen, |
| 7698 | &cookie, &eof); |
| 7699 | if (ret < 0) |
| 7700 | return ret; |
| 7701 | |
| 7702 | if (list_len) { |
| 7703 | buf += ret; |
| 7704 | buflen -= ret; |
| 7705 | } |
| 7706 | size += ret; |
| 7707 | } |
| 7708 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7709 | if (list_len) |
| 7710 | nfs4_xattr_cache_set_list(inode, list, size); |
| 7711 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7712 | return size; |
| 7713 | } |
| 7714 | |
| 7715 | #else |
| 7716 | |
| 7717 | static ssize_t |
| 7718 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7719 | { |
| 7720 | return 0; |
| 7721 | } |
| 7722 | #endif /* CONFIG_NFS_V4_2 */ |
| 7723 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7724 | /* |
| 7725 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7726 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7727 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7728 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7729 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7730 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7731 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7732 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7733 | return; |
| 7734 | |
| 7735 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7736 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7737 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7738 | fattr->nlink = 2; |
| 7739 | } |
| 7740 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7741 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7742 | const struct qstr *name, |
| 7743 | struct nfs4_fs_locations *fs_locations, |
| 7744 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7745 | { |
| 7746 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7747 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7748 | struct nfs4_fs_locations_arg args = { |
| 7749 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7750 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7751 | .page = page, |
| 7752 | .bitmask = bitmask, |
| 7753 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7754 | struct nfs4_fs_locations_res res = { |
| 7755 | .fs_locations = fs_locations, |
| 7756 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7757 | struct rpc_message msg = { |
| 7758 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7759 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7760 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7761 | }; |
| 7762 | int status; |
| 7763 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7764 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7765 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7766 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7767 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7768 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7769 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7770 | * is not supported */ |
| 7771 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7772 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7773 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7774 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7775 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7776 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7777 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7778 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7779 | 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] | 7780 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7781 | return status; |
| 7782 | } |
| 7783 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7784 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7785 | const struct qstr *name, |
| 7786 | struct nfs4_fs_locations *fs_locations, |
| 7787 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7788 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7789 | struct nfs4_exception exception = { |
| 7790 | .interruptible = true, |
| 7791 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7792 | int err; |
| 7793 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7794 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7795 | fs_locations, page); |
| 7796 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7797 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7798 | &exception); |
| 7799 | } while (exception.retry); |
| 7800 | return err; |
| 7801 | } |
| 7802 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7803 | /* |
| 7804 | * This operation also signals the server that this client is |
| 7805 | * performing migration recovery. The server can stop returning |
| 7806 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7807 | * appended to this compound to identify the client ID which is |
| 7808 | * performing recovery. |
| 7809 | */ |
| 7810 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7811 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7812 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7813 | { |
| 7814 | struct nfs_server *server = NFS_SERVER(inode); |
| 7815 | struct rpc_clnt *clnt = server->client; |
| 7816 | u32 bitmask[2] = { |
| 7817 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7818 | }; |
| 7819 | struct nfs4_fs_locations_arg args = { |
| 7820 | .clientid = server->nfs_client->cl_clientid, |
| 7821 | .fh = NFS_FH(inode), |
| 7822 | .page = page, |
| 7823 | .bitmask = bitmask, |
| 7824 | .migration = 1, /* skip LOOKUP */ |
| 7825 | .renew = 1, /* append RENEW */ |
| 7826 | }; |
| 7827 | struct nfs4_fs_locations_res res = { |
| 7828 | .fs_locations = locations, |
| 7829 | .migration = 1, |
| 7830 | .renew = 1, |
| 7831 | }; |
| 7832 | struct rpc_message msg = { |
| 7833 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7834 | .rpc_argp = &args, |
| 7835 | .rpc_resp = &res, |
| 7836 | .rpc_cred = cred, |
| 7837 | }; |
| 7838 | unsigned long now = jiffies; |
| 7839 | int status; |
| 7840 | |
| 7841 | nfs_fattr_init(&locations->fattr); |
| 7842 | locations->server = server; |
| 7843 | locations->nlocations = 0; |
| 7844 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7845 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7846 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7847 | &args.seq_args, &res.seq_res); |
| 7848 | if (status) |
| 7849 | return status; |
| 7850 | |
| 7851 | renew_lease(server, now); |
| 7852 | return 0; |
| 7853 | } |
| 7854 | |
| 7855 | #ifdef CONFIG_NFS_V4_1 |
| 7856 | |
| 7857 | /* |
| 7858 | * This operation also signals the server that this client is |
| 7859 | * performing migration recovery. The server can stop asserting |
| 7860 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7861 | * performing this operation is identified in the SEQUENCE |
| 7862 | * operation in this compound. |
| 7863 | * |
| 7864 | * When the client supports GETATTR(fs_locations_info), it can |
| 7865 | * be plumbed in here. |
| 7866 | */ |
| 7867 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7868 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7869 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7870 | { |
| 7871 | struct nfs_server *server = NFS_SERVER(inode); |
| 7872 | struct rpc_clnt *clnt = server->client; |
| 7873 | u32 bitmask[2] = { |
| 7874 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7875 | }; |
| 7876 | struct nfs4_fs_locations_arg args = { |
| 7877 | .fh = NFS_FH(inode), |
| 7878 | .page = page, |
| 7879 | .bitmask = bitmask, |
| 7880 | .migration = 1, /* skip LOOKUP */ |
| 7881 | }; |
| 7882 | struct nfs4_fs_locations_res res = { |
| 7883 | .fs_locations = locations, |
| 7884 | .migration = 1, |
| 7885 | }; |
| 7886 | struct rpc_message msg = { |
| 7887 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7888 | .rpc_argp = &args, |
| 7889 | .rpc_resp = &res, |
| 7890 | .rpc_cred = cred, |
| 7891 | }; |
| 7892 | int status; |
| 7893 | |
| 7894 | nfs_fattr_init(&locations->fattr); |
| 7895 | locations->server = server; |
| 7896 | locations->nlocations = 0; |
| 7897 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7898 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7899 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7900 | &args.seq_args, &res.seq_res); |
| 7901 | if (status == NFS4_OK && |
| 7902 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7903 | status = -NFS4ERR_LEASE_MOVED; |
| 7904 | return status; |
| 7905 | } |
| 7906 | |
| 7907 | #endif /* CONFIG_NFS_V4_1 */ |
| 7908 | |
| 7909 | /** |
| 7910 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7911 | * @inode: inode on FSID that is migrating |
| 7912 | * @locations: result of query |
| 7913 | * @page: buffer |
| 7914 | * @cred: credential to use for this operation |
| 7915 | * |
| 7916 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7917 | * operation failed, or a negative errno if a local error occurred. |
| 7918 | * |
| 7919 | * On success, "locations" is filled in, but if the server has |
| 7920 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7921 | * asserted. |
| 7922 | * |
| 7923 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7924 | * from this client that require migration recovery. |
| 7925 | */ |
| 7926 | int nfs4_proc_get_locations(struct inode *inode, |
| 7927 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7928 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7929 | { |
| 7930 | struct nfs_server *server = NFS_SERVER(inode); |
| 7931 | struct nfs_client *clp = server->nfs_client; |
| 7932 | const struct nfs4_mig_recovery_ops *ops = |
| 7933 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7934 | struct nfs4_exception exception = { |
| 7935 | .interruptible = true, |
| 7936 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7937 | int status; |
| 7938 | |
| 7939 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7940 | (unsigned long long)server->fsid.major, |
| 7941 | (unsigned long long)server->fsid.minor, |
| 7942 | clp->cl_hostname); |
| 7943 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7944 | |
| 7945 | do { |
| 7946 | status = ops->get_locations(inode, locations, page, cred); |
| 7947 | if (status != -NFS4ERR_DELAY) |
| 7948 | break; |
| 7949 | nfs4_handle_exception(server, status, &exception); |
| 7950 | } while (exception.retry); |
| 7951 | return status; |
| 7952 | } |
| 7953 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7954 | /* |
| 7955 | * This operation also signals the server that this client is |
| 7956 | * performing "lease moved" recovery. The server can stop |
| 7957 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7958 | * is appended to this compound to identify the client ID which is |
| 7959 | * performing recovery. |
| 7960 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7961 | static int _nfs40_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7962 | { |
| 7963 | struct nfs_server *server = NFS_SERVER(inode); |
| 7964 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7965 | struct rpc_clnt *clnt = server->client; |
| 7966 | struct nfs4_fsid_present_arg args = { |
| 7967 | .fh = NFS_FH(inode), |
| 7968 | .clientid = clp->cl_clientid, |
| 7969 | .renew = 1, /* append RENEW */ |
| 7970 | }; |
| 7971 | struct nfs4_fsid_present_res res = { |
| 7972 | .renew = 1, |
| 7973 | }; |
| 7974 | struct rpc_message msg = { |
| 7975 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7976 | .rpc_argp = &args, |
| 7977 | .rpc_resp = &res, |
| 7978 | .rpc_cred = cred, |
| 7979 | }; |
| 7980 | unsigned long now = jiffies; |
| 7981 | int status; |
| 7982 | |
| 7983 | res.fh = nfs_alloc_fhandle(); |
| 7984 | if (res.fh == NULL) |
| 7985 | return -ENOMEM; |
| 7986 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7987 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7988 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7989 | &args.seq_args, &res.seq_res); |
| 7990 | nfs_free_fhandle(res.fh); |
| 7991 | if (status) |
| 7992 | return status; |
| 7993 | |
| 7994 | do_renew_lease(clp, now); |
| 7995 | return 0; |
| 7996 | } |
| 7997 | |
| 7998 | #ifdef CONFIG_NFS_V4_1 |
| 7999 | |
| 8000 | /* |
| 8001 | * This operation also signals the server that this client is |
| 8002 | * performing "lease moved" recovery. The server can stop asserting |
| 8003 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 8004 | * this operation is identified in the SEQUENCE operation in this |
| 8005 | * compound. |
| 8006 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8007 | static int _nfs41_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8008 | { |
| 8009 | struct nfs_server *server = NFS_SERVER(inode); |
| 8010 | struct rpc_clnt *clnt = server->client; |
| 8011 | struct nfs4_fsid_present_arg args = { |
| 8012 | .fh = NFS_FH(inode), |
| 8013 | }; |
| 8014 | struct nfs4_fsid_present_res res = { |
| 8015 | }; |
| 8016 | struct rpc_message msg = { |
| 8017 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 8018 | .rpc_argp = &args, |
| 8019 | .rpc_resp = &res, |
| 8020 | .rpc_cred = cred, |
| 8021 | }; |
| 8022 | int status; |
| 8023 | |
| 8024 | res.fh = nfs_alloc_fhandle(); |
| 8025 | if (res.fh == NULL) |
| 8026 | return -ENOMEM; |
| 8027 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8028 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8029 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 8030 | &args.seq_args, &res.seq_res); |
| 8031 | nfs_free_fhandle(res.fh); |
| 8032 | if (status == NFS4_OK && |
| 8033 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 8034 | status = -NFS4ERR_LEASE_MOVED; |
| 8035 | return status; |
| 8036 | } |
| 8037 | |
| 8038 | #endif /* CONFIG_NFS_V4_1 */ |
| 8039 | |
| 8040 | /** |
| 8041 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 8042 | * @inode: inode on FSID to check |
| 8043 | * @cred: credential to use for this operation |
| 8044 | * |
| 8045 | * Server indicates whether the FSID is present, moved, or not |
| 8046 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 8047 | * condition for this client ID. |
| 8048 | * |
| 8049 | * Returns NFS4_OK if the FSID is present on this server, |
| 8050 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 8051 | * NFS4ERR code if some error occurred on the server, or a |
| 8052 | * negative errno if a local failure occurred. |
| 8053 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8054 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8055 | { |
| 8056 | struct nfs_server *server = NFS_SERVER(inode); |
| 8057 | struct nfs_client *clp = server->nfs_client; |
| 8058 | const struct nfs4_mig_recovery_ops *ops = |
| 8059 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8060 | struct nfs4_exception exception = { |
| 8061 | .interruptible = true, |
| 8062 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8063 | int status; |
| 8064 | |
| 8065 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 8066 | (unsigned long long)server->fsid.major, |
| 8067 | (unsigned long long)server->fsid.minor, |
| 8068 | clp->cl_hostname); |
| 8069 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 8070 | |
| 8071 | do { |
| 8072 | status = ops->fsid_present(inode, cred); |
| 8073 | if (status != -NFS4ERR_DELAY) |
| 8074 | break; |
| 8075 | nfs4_handle_exception(server, status, &exception); |
| 8076 | } while (exception.retry); |
| 8077 | return status; |
| 8078 | } |
| 8079 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 8080 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8081 | * If 'use_integrity' is true and the state managment nfs_client |
| 8082 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 8083 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 8084 | * Considerations sections. Otherwise, just use the user cred with the |
| 8085 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 8086 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8087 | 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] | 8088 | { |
| 8089 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8090 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 8091 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8092 | struct nfs4_secinfo_arg args = { |
| 8093 | .dir_fh = NFS_FH(dir), |
| 8094 | .name = name, |
| 8095 | }; |
| 8096 | struct nfs4_secinfo_res res = { |
| 8097 | .flavors = flavors, |
| 8098 | }; |
| 8099 | struct rpc_message msg = { |
| 8100 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 8101 | .rpc_argp = &args, |
| 8102 | .rpc_resp = &res, |
| 8103 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8104 | struct nfs4_call_sync_data data = { |
| 8105 | .seq_server = NFS_SERVER(dir), |
| 8106 | .seq_args = &args.seq_args, |
| 8107 | .seq_res = &res.seq_res, |
| 8108 | }; |
| 8109 | struct rpc_task_setup task_setup = { |
| 8110 | .rpc_client = clnt, |
| 8111 | .rpc_message = &msg, |
| 8112 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 8113 | .callback_data = &data, |
| 8114 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 8115 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8116 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8117 | |
| 8118 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8119 | clnt = clp->cl_rpcclient; |
| 8120 | task_setup.rpc_client = clnt; |
| 8121 | |
| 8122 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8123 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8124 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8125 | |
| 8126 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8127 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8128 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 8129 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 8130 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8131 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8132 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8133 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8134 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8135 | return status; |
| 8136 | } |
| 8137 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 8138 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 8139 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8140 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8141 | struct nfs4_exception exception = { |
| 8142 | .interruptible = true, |
| 8143 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8144 | int err; |
| 8145 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8146 | err = -NFS4ERR_WRONGSEC; |
| 8147 | |
| 8148 | /* try to use integrity protection with machine cred */ |
| 8149 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 8150 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 8151 | |
| 8152 | /* |
| 8153 | * if unable to use integrity protection, or SECINFO with |
| 8154 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8155 | * disallowed by spec, but exists in deployed servers) use |
| 8156 | * the current filesystem's rpc_client and the user cred. |
| 8157 | */ |
| 8158 | if (err == -NFS4ERR_WRONGSEC) |
| 8159 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 8160 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 8161 | trace_nfs4_secinfo(dir, name, err); |
| 8162 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8163 | &exception); |
| 8164 | } while (exception.retry); |
| 8165 | return err; |
| 8166 | } |
| 8167 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8168 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8169 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8170 | * Check the exchange flags returned by the server for invalid flags, having |
| 8171 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 8172 | * DS flags set. |
| 8173 | */ |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8174 | static int nfs4_check_cl_exchange_flags(u32 flags, u32 version) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8175 | { |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8176 | if (version >= 2 && (flags & ~EXCHGID4_2_FLAG_MASK_R)) |
| 8177 | goto out_inval; |
| 8178 | else if (version < 2 && (flags & ~EXCHGID4_FLAG_MASK_R)) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8179 | goto out_inval; |
| 8180 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 8181 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 8182 | goto out_inval; |
| 8183 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 8184 | goto out_inval; |
| 8185 | return NFS_OK; |
| 8186 | out_inval: |
| 8187 | return -NFS4ERR_INVAL; |
| 8188 | } |
| 8189 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8190 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 8191 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 8192 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8193 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 8194 | if (a->server_scope_sz != b->server_scope_sz) |
| 8195 | return false; |
| 8196 | 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] | 8197 | } |
| 8198 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8199 | static void |
| 8200 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 8201 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8202 | struct nfs41_bind_conn_to_session_args *args = task->tk_msg.rpc_argp; |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8203 | struct nfs41_bind_conn_to_session_res *res = task->tk_msg.rpc_resp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8204 | struct nfs_client *clp = args->client; |
| 8205 | |
| 8206 | switch (task->tk_status) { |
| 8207 | case -NFS4ERR_BADSESSION: |
| 8208 | case -NFS4ERR_DEADSESSION: |
| 8209 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8210 | task->tk_status); |
| 8211 | } |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8212 | if (args->dir == NFS4_CDFC4_FORE_OR_BOTH && |
| 8213 | res->dir != NFS4_CDFS4_BOTH) { |
| 8214 | rpc_task_close_connection(task); |
| 8215 | if (args->retries++ < MAX_BIND_CONN_TO_SESSION_RETRIES) |
| 8216 | rpc_restart_call(task); |
| 8217 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8218 | } |
| 8219 | |
| 8220 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
Olga Kornievskaia | 1c709b7 | 2020-04-26 11:30:00 -0400 | [diff] [blame] | 8221 | .rpc_call_done = nfs4_bind_one_conn_to_session_done, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8222 | }; |
| 8223 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8224 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8225 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8226 | * |
| 8227 | * The 4.1 client currently uses the same TCP connection for the |
| 8228 | * fore and backchannel. |
| 8229 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8230 | static |
| 8231 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 8232 | struct rpc_xprt *xprt, |
| 8233 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8234 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8235 | { |
| 8236 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8237 | struct nfs41_bind_conn_to_session_args args = { |
| 8238 | .client = clp, |
| 8239 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8240 | .retries = 0, |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8241 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8242 | struct nfs41_bind_conn_to_session_res res; |
| 8243 | struct rpc_message msg = { |
| 8244 | .rpc_proc = |
| 8245 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8246 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8247 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 8248 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8249 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8250 | struct rpc_task_setup task_setup_data = { |
| 8251 | .rpc_client = clnt, |
| 8252 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8253 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8254 | .rpc_message = &msg, |
| 8255 | .flags = RPC_TASK_TIMEOUT, |
| 8256 | }; |
| 8257 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8258 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8259 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 8260 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 8261 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8262 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8263 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 8264 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 8265 | args.dir = NFS4_CDFC4_FORE; |
| 8266 | |
| 8267 | task = rpc_run_task(&task_setup_data); |
| 8268 | if (!IS_ERR(task)) { |
| 8269 | status = task->tk_status; |
| 8270 | rpc_put_task(task); |
| 8271 | } else |
| 8272 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8273 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8274 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8275 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8276 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 8277 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8278 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8279 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8280 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8281 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 8282 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8283 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8284 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8285 | 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] | 8286 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 8287 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8288 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8289 | } |
| 8290 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8291 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8292 | return status; |
| 8293 | } |
| 8294 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8295 | struct rpc_bind_conn_calldata { |
| 8296 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8297 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8298 | }; |
| 8299 | |
| 8300 | static int |
| 8301 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 8302 | struct rpc_xprt *xprt, |
| 8303 | void *calldata) |
| 8304 | { |
| 8305 | struct rpc_bind_conn_calldata *p = calldata; |
| 8306 | |
| 8307 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 8308 | } |
| 8309 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8310 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, const struct cred *cred) |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8311 | { |
| 8312 | struct rpc_bind_conn_calldata data = { |
| 8313 | .clp = clp, |
| 8314 | .cred = cred, |
| 8315 | }; |
| 8316 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 8317 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 8318 | } |
| 8319 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8320 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8321 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 8322 | * 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] | 8323 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8324 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 8325 | .how = SP4_MACH_CRED, |
| 8326 | .enforce.u.words = { |
| 8327 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8328 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8329 | 1 << (OP_CREATE_SESSION - 32) | |
| 8330 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8331 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8332 | }, |
| 8333 | .allow.u.words = { |
| 8334 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8335 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8336 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8337 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8338 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8339 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8340 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8341 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8342 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8343 | 1 << (OP_FREE_STATEID - 32) | |
| 8344 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8345 | } |
| 8346 | }; |
| 8347 | |
| 8348 | /* |
| 8349 | * Select the state protection mode for client `clp' given the server results |
| 8350 | * from exchange_id in `sp'. |
| 8351 | * |
| 8352 | * Returns 0 on success, negative errno otherwise. |
| 8353 | */ |
| 8354 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8355 | struct nfs41_state_protection *sp) |
| 8356 | { |
| 8357 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8358 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8359 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8360 | 1 << (OP_CREATE_SESSION - 32) | |
| 8361 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8362 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8363 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8364 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8365 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8366 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8367 | |
| 8368 | if (sp->how == SP4_MACH_CRED) { |
| 8369 | /* Print state protect result */ |
| 8370 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8371 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8372 | if (test_bit(i, sp->enforce.u.longs)) |
| 8373 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8374 | if (test_bit(i, sp->allow.u.longs)) |
| 8375 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8376 | } |
| 8377 | |
| 8378 | /* make sure nothing is on enforce list that isn't supported */ |
| 8379 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8380 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8381 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8382 | ret = -EINVAL; |
| 8383 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | /* |
| 8388 | * Minimal mode - state operations are allowed to use machine |
| 8389 | * credential. Note this already happens by default, so the |
| 8390 | * client doesn't have to do anything more than the negotiation. |
| 8391 | * |
| 8392 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8393 | * we're already using the machine cred for exchange_id |
| 8394 | * and will never use a different cred. |
| 8395 | */ |
| 8396 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8397 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8398 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8399 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8400 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8401 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8402 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8403 | } else { |
| 8404 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8405 | ret = -EINVAL; |
| 8406 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8407 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8408 | |
| 8409 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8410 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8411 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8412 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8413 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8414 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8415 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8416 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8417 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8418 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8419 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8420 | } |
| 8421 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8422 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8423 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8424 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8425 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8426 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8427 | |
| 8428 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8429 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8430 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8431 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8432 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8433 | |
| 8434 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8435 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8436 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8437 | } |
| 8438 | |
| 8439 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8440 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8441 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8442 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8443 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8444 | out: |
| 8445 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8446 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8447 | } |
| 8448 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8449 | struct nfs41_exchange_id_data { |
| 8450 | struct nfs41_exchange_id_res res; |
| 8451 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8452 | }; |
| 8453 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8454 | static void nfs4_exchange_id_release(void *data) |
| 8455 | { |
| 8456 | struct nfs41_exchange_id_data *cdata = |
| 8457 | (struct nfs41_exchange_id_data *)data; |
| 8458 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8459 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8460 | kfree(cdata->res.impl_id); |
| 8461 | kfree(cdata->res.server_scope); |
| 8462 | kfree(cdata->res.server_owner); |
| 8463 | kfree(cdata); |
| 8464 | } |
| 8465 | |
| 8466 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8467 | .rpc_release = nfs4_exchange_id_release, |
| 8468 | }; |
| 8469 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8470 | /* |
| 8471 | * _nfs4_proc_exchange_id() |
| 8472 | * |
| 8473 | * Wrapper for EXCHANGE_ID operation. |
| 8474 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8475 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8476 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8477 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8478 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8479 | struct rpc_message msg = { |
| 8480 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8481 | .rpc_cred = cred, |
| 8482 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8483 | struct rpc_task_setup task_setup_data = { |
| 8484 | .rpc_client = clp->cl_rpcclient, |
| 8485 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8486 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8487 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8488 | }; |
| 8489 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8490 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8491 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8492 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8493 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8494 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8495 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8496 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8497 | if (!calldata) |
| 8498 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8499 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8500 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8501 | |
| 8502 | status = nfs4_init_uniform_client_string(clp); |
| 8503 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8504 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8505 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8506 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8507 | GFP_NOFS); |
| 8508 | status = -ENOMEM; |
| 8509 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8510 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8511 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8512 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8513 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8514 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8515 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8516 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8517 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8518 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8519 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8520 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8521 | switch (sp4_how) { |
| 8522 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8523 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8524 | break; |
| 8525 | |
| 8526 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8527 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8528 | break; |
| 8529 | |
| 8530 | default: |
| 8531 | /* unsupported! */ |
| 8532 | WARN_ON_ONCE(1); |
| 8533 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8534 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8535 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8536 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8537 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8538 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8539 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8540 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8541 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8542 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8543 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8544 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8545 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8546 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8547 | #endif |
| 8548 | msg.rpc_argp = &calldata->args; |
| 8549 | msg.rpc_resp = &calldata->res; |
| 8550 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8551 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8552 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8553 | |
| 8554 | out_impl_id: |
| 8555 | kfree(calldata->res.impl_id); |
| 8556 | out_server_scope: |
| 8557 | kfree(calldata->res.server_scope); |
| 8558 | out_server_owner: |
| 8559 | kfree(calldata->res.server_owner); |
| 8560 | out_calldata: |
| 8561 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8562 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8563 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8564 | return ERR_PTR(status); |
| 8565 | } |
| 8566 | |
| 8567 | /* |
| 8568 | * _nfs4_proc_exchange_id() |
| 8569 | * |
| 8570 | * Wrapper for EXCHANGE_ID operation. |
| 8571 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8572 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8573 | u32 sp4_how) |
| 8574 | { |
| 8575 | struct rpc_task *task; |
| 8576 | struct nfs41_exchange_id_args *argp; |
| 8577 | struct nfs41_exchange_id_res *resp; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8578 | unsigned long now = jiffies; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8579 | int status; |
| 8580 | |
| 8581 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8582 | if (IS_ERR(task)) |
| 8583 | return PTR_ERR(task); |
| 8584 | |
| 8585 | argp = task->tk_msg.rpc_argp; |
| 8586 | resp = task->tk_msg.rpc_resp; |
| 8587 | status = task->tk_status; |
| 8588 | if (status != 0) |
| 8589 | goto out; |
| 8590 | |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8591 | status = nfs4_check_cl_exchange_flags(resp->flags, |
| 8592 | clp->cl_mvops->minor_version); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8593 | if (status != 0) |
| 8594 | goto out; |
| 8595 | |
| 8596 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8597 | if (status != 0) |
| 8598 | goto out; |
| 8599 | |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8600 | do_renew_lease(clp, now); |
| 8601 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8602 | clp->cl_clientid = resp->clientid; |
| 8603 | clp->cl_exchange_flags = resp->flags; |
| 8604 | clp->cl_seqid = resp->seqid; |
| 8605 | /* Client ID is not confirmed */ |
| 8606 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8607 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8608 | &clp->cl_session->session_state); |
| 8609 | |
| 8610 | if (clp->cl_serverscope != NULL && |
| 8611 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8612 | resp->server_scope)) { |
| 8613 | dprintk("%s: server_scope mismatch detected\n", |
| 8614 | __func__); |
| 8615 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8616 | } |
| 8617 | |
| 8618 | swap(clp->cl_serverowner, resp->server_owner); |
| 8619 | swap(clp->cl_serverscope, resp->server_scope); |
| 8620 | swap(clp->cl_implid, resp->impl_id); |
| 8621 | |
| 8622 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8623 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8624 | sizeof(clp->cl_confirm.data)); |
| 8625 | out: |
| 8626 | trace_nfs4_exchange_id(clp, status); |
| 8627 | rpc_put_task(task); |
| 8628 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8629 | } |
| 8630 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8631 | /* |
| 8632 | * nfs4_proc_exchange_id() |
| 8633 | * |
| 8634 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8635 | * |
| 8636 | * Since the clientid has expired, all compounds using sessions |
| 8637 | * associated with the stale clientid will be returning |
| 8638 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8639 | * be in some phase of session reset. |
| 8640 | * |
| 8641 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8642 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8643 | int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8644 | { |
| 8645 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8646 | int status; |
| 8647 | |
| 8648 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8649 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8650 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8651 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8652 | if (!status) |
| 8653 | return 0; |
| 8654 | } |
| 8655 | |
| 8656 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8657 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8658 | } |
| 8659 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8660 | /** |
| 8661 | * nfs4_test_session_trunk |
| 8662 | * |
| 8663 | * This is an add_xprt_test() test function called from |
| 8664 | * rpc_clnt_setup_test_and_add_xprt. |
| 8665 | * |
| 8666 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8667 | * and is dereferrenced in nfs4_exchange_id_release |
| 8668 | * |
| 8669 | * Upon success, add the new transport to the rpc_clnt |
| 8670 | * |
| 8671 | * @clnt: struct rpc_clnt to get new transport |
| 8672 | * @xprt: the rpc_xprt to test |
| 8673 | * @data: call data for _nfs4_proc_exchange_id. |
| 8674 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8675 | void nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8676 | void *data) |
| 8677 | { |
| 8678 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8679 | struct rpc_task *task; |
| 8680 | int status; |
| 8681 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8682 | u32 sp4_how; |
| 8683 | |
| 8684 | dprintk("--> %s try %s\n", __func__, |
| 8685 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8686 | |
| 8687 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8688 | |
| 8689 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8690 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8691 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8692 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8693 | |
| 8694 | status = task->tk_status; |
| 8695 | if (status == 0) |
| 8696 | status = nfs4_detect_session_trunking(adata->clp, |
| 8697 | task->tk_msg.rpc_resp, xprt); |
| 8698 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8699 | if (status == 0) |
| 8700 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8701 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8702 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8703 | } |
| 8704 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8705 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8706 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8707 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8708 | { |
| 8709 | struct rpc_message msg = { |
| 8710 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8711 | .rpc_argp = clp, |
| 8712 | .rpc_cred = cred, |
| 8713 | }; |
| 8714 | int status; |
| 8715 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8716 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8717 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8718 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8719 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8720 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8721 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8722 | return status; |
| 8723 | } |
| 8724 | |
| 8725 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8726 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8727 | { |
| 8728 | unsigned int loop; |
| 8729 | int ret; |
| 8730 | |
| 8731 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8732 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8733 | switch (ret) { |
| 8734 | case -NFS4ERR_DELAY: |
| 8735 | case -NFS4ERR_CLIENTID_BUSY: |
| 8736 | ssleep(1); |
| 8737 | break; |
| 8738 | default: |
| 8739 | return ret; |
| 8740 | } |
| 8741 | } |
| 8742 | return 0; |
| 8743 | } |
| 8744 | |
| 8745 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8746 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8747 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8748 | int ret = 0; |
| 8749 | |
| 8750 | if (clp->cl_mvops->minor_version < 1) |
| 8751 | goto out; |
| 8752 | if (clp->cl_exchange_flags == 0) |
| 8753 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8754 | if (clp->cl_preserve_clid) |
| 8755 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8756 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8757 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8758 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8759 | switch (ret) { |
| 8760 | case 0: |
| 8761 | case -NFS4ERR_STALE_CLIENTID: |
| 8762 | clp->cl_exchange_flags = 0; |
| 8763 | } |
| 8764 | out: |
| 8765 | return ret; |
| 8766 | } |
| 8767 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8768 | #endif /* CONFIG_NFS_V4_1 */ |
| 8769 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8770 | struct nfs4_get_lease_time_data { |
| 8771 | struct nfs4_get_lease_time_args *args; |
| 8772 | struct nfs4_get_lease_time_res *res; |
| 8773 | struct nfs_client *clp; |
| 8774 | }; |
| 8775 | |
| 8776 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8777 | void *calldata) |
| 8778 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8779 | struct nfs4_get_lease_time_data *data = |
| 8780 | (struct nfs4_get_lease_time_data *)calldata; |
| 8781 | |
| 8782 | dprintk("--> %s\n", __func__); |
| 8783 | /* just setup sequence, do not trigger session recovery |
| 8784 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8785 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8786 | &data->args->la_seq_args, |
| 8787 | &data->res->lr_seq_res, |
| 8788 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8789 | dprintk("<-- %s\n", __func__); |
| 8790 | } |
| 8791 | |
| 8792 | /* |
| 8793 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8794 | * from sequence operation or clientid errors. |
| 8795 | */ |
| 8796 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8797 | { |
| 8798 | struct nfs4_get_lease_time_data *data = |
| 8799 | (struct nfs4_get_lease_time_data *)calldata; |
| 8800 | |
| 8801 | dprintk("--> %s\n", __func__); |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8802 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8803 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8804 | switch (task->tk_status) { |
| 8805 | case -NFS4ERR_DELAY: |
| 8806 | case -NFS4ERR_GRACE: |
| 8807 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8808 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8809 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 8810 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8811 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8812 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8813 | return; |
| 8814 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8815 | dprintk("<-- %s\n", __func__); |
| 8816 | } |
| 8817 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8818 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8819 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8820 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8821 | }; |
| 8822 | |
| 8823 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8824 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8825 | struct nfs4_get_lease_time_args args; |
| 8826 | struct nfs4_get_lease_time_res res = { |
| 8827 | .lr_fsinfo = fsinfo, |
| 8828 | }; |
| 8829 | struct nfs4_get_lease_time_data data = { |
| 8830 | .args = &args, |
| 8831 | .res = &res, |
| 8832 | .clp = clp, |
| 8833 | }; |
| 8834 | struct rpc_message msg = { |
| 8835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8836 | .rpc_argp = &args, |
| 8837 | .rpc_resp = &res, |
| 8838 | }; |
| 8839 | struct rpc_task_setup task_setup = { |
| 8840 | .rpc_client = clp->cl_rpcclient, |
| 8841 | .rpc_message = &msg, |
| 8842 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8843 | .callback_data = &data, |
| 8844 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8845 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8846 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8847 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0, 1); |
Anna Schumaker | f836b27 | 2019-08-19 10:18:28 -0400 | [diff] [blame] | 8848 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8849 | } |
| 8850 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8851 | #ifdef CONFIG_NFS_V4_1 |
| 8852 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8853 | /* |
| 8854 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8855 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8856 | * use them. |
| 8857 | * |
| 8858 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8859 | * always set csa_cachethis to FALSE because the current implementation |
| 8860 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8861 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8862 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8863 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8864 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8865 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8866 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8867 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8868 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8869 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8870 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8871 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8872 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8873 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8874 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8875 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8876 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8877 | |
| 8878 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8879 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8880 | __func__, |
| 8881 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8882 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8883 | |
| 8884 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8885 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8886 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8887 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8888 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8889 | args->bc_attrs.max_reqs = max_t(unsigned short, max_session_cb_slots, 1); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8890 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8891 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8892 | |
| 8893 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8894 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8895 | __func__, |
| 8896 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8897 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8898 | args->bc_attrs.max_reqs); |
| 8899 | } |
| 8900 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8901 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8902 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8903 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8904 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8905 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8906 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8907 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8908 | return -EINVAL; |
| 8909 | /* |
| 8910 | * Our requested max_ops is the minimum we need; we're not |
| 8911 | * prepared to break up compounds into smaller pieces than that. |
| 8912 | * So, no point even trying to continue if the server won't |
| 8913 | * cooperate: |
| 8914 | */ |
| 8915 | if (rcvd->max_ops < sent->max_ops) |
| 8916 | return -EINVAL; |
| 8917 | if (rcvd->max_reqs == 0) |
| 8918 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8919 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8920 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8921 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8922 | } |
| 8923 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8924 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8925 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8926 | { |
| 8927 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8928 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8929 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8930 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8931 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8932 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8933 | return -EINVAL; |
| 8934 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8935 | return -EINVAL; |
| 8936 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8937 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8938 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8939 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8940 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8941 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8942 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8943 | return 0; |
| 8944 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8945 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8946 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8947 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8948 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8949 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8950 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8951 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8952 | if (ret) |
| 8953 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8954 | return nfs4_verify_back_channel_attrs(args, res); |
| 8955 | } |
| 8956 | |
| 8957 | static void nfs4_update_session(struct nfs4_session *session, |
| 8958 | struct nfs41_create_session_res *res) |
| 8959 | { |
| 8960 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8961 | /* Mark client id and session as being confirmed */ |
| 8962 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8963 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8964 | session->flags = res->flags; |
| 8965 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8966 | if (res->flags & SESSION4_BACK_CHAN) |
| 8967 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8968 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8969 | } |
| 8970 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8971 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8972 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8973 | { |
| 8974 | struct nfs4_session *session = clp->cl_session; |
| 8975 | struct nfs41_create_session_args args = { |
| 8976 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8977 | .clientid = clp->cl_clientid, |
| 8978 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8979 | .cb_program = NFS4_CALLBACK, |
| 8980 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8981 | struct nfs41_create_session_res res; |
| 8982 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8983 | struct rpc_message msg = { |
| 8984 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8985 | .rpc_argp = &args, |
| 8986 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8987 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8988 | }; |
| 8989 | int status; |
| 8990 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8991 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8992 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8993 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8994 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8995 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8996 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8997 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8998 | switch (status) { |
| 8999 | case -NFS4ERR_STALE_CLIENTID: |
| 9000 | case -NFS4ERR_DELAY: |
| 9001 | case -ETIMEDOUT: |
| 9002 | case -EACCES: |
| 9003 | case -EAGAIN: |
| 9004 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 9005 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 9006 | |
| 9007 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 9008 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9009 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9010 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9011 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9012 | if (status) |
| 9013 | goto out; |
| 9014 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9015 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9016 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9017 | return status; |
| 9018 | } |
| 9019 | |
| 9020 | /* |
| 9021 | * Issues a CREATE_SESSION operation to the server. |
| 9022 | * It is the responsibility of the caller to verify the session is |
| 9023 | * expired before calling this routine. |
| 9024 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9025 | int nfs4_proc_create_session(struct nfs_client *clp, const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9026 | { |
| 9027 | int status; |
| 9028 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9029 | struct nfs4_session *session = clp->cl_session; |
| 9030 | |
| 9031 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 9032 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9033 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9034 | if (status) |
| 9035 | goto out; |
| 9036 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 9037 | /* Init or reset the session slot tables */ |
| 9038 | status = nfs4_setup_session_slot_tables(session); |
| 9039 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9040 | if (status) |
| 9041 | goto out; |
| 9042 | |
| 9043 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 9044 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 9045 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9046 | out: |
| 9047 | dprintk("<-- %s\n", __func__); |
| 9048 | return status; |
| 9049 | } |
| 9050 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9051 | /* |
| 9052 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 9053 | * The caller must serialize access to this routine. |
| 9054 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9055 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9056 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9057 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9058 | struct rpc_message msg = { |
| 9059 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 9060 | .rpc_argp = session, |
| 9061 | .rpc_cred = cred, |
| 9062 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9063 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9064 | |
| 9065 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 9066 | |
| 9067 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 9068 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 9069 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9070 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9071 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9072 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9073 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9074 | |
| 9075 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 9076 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9077 | "Session has been destroyed regardless...\n", status); |
| 9078 | |
| 9079 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 9080 | return status; |
| 9081 | } |
| 9082 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 9083 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9084 | * Renew the cl_session lease. |
| 9085 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9086 | struct nfs4_sequence_data { |
| 9087 | struct nfs_client *clp; |
| 9088 | struct nfs4_sequence_args args; |
| 9089 | struct nfs4_sequence_res res; |
| 9090 | }; |
| 9091 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9092 | static void nfs41_sequence_release(void *data) |
| 9093 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9094 | struct nfs4_sequence_data *calldata = data; |
| 9095 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9096 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9097 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9098 | nfs4_schedule_state_renewal(clp); |
| 9099 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9100 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9101 | } |
| 9102 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9103 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9104 | { |
| 9105 | switch(task->tk_status) { |
| 9106 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9107 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 9108 | return -EAGAIN; |
| 9109 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9110 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9111 | } |
| 9112 | return 0; |
| 9113 | } |
| 9114 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9115 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9116 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9117 | struct nfs4_sequence_data *calldata = data; |
| 9118 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9119 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9120 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 9121 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9122 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9123 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9124 | if (task->tk_status < 0) { |
| 9125 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9126 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9127 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9128 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9129 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 9130 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9131 | return; |
| 9132 | } |
| 9133 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9134 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9135 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9136 | dprintk("<-- %s\n", __func__); |
| 9137 | } |
| 9138 | |
| 9139 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 9140 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9141 | struct nfs4_sequence_data *calldata = data; |
| 9142 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9143 | struct nfs4_sequence_args *args; |
| 9144 | struct nfs4_sequence_res *res; |
| 9145 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9146 | args = task->tk_msg.rpc_argp; |
| 9147 | res = task->tk_msg.rpc_resp; |
| 9148 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9149 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9150 | } |
| 9151 | |
| 9152 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 9153 | .rpc_call_done = nfs41_sequence_call_done, |
| 9154 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9155 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9156 | }; |
| 9157 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9158 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9159 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9160 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9161 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9162 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9163 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9164 | struct rpc_message msg = { |
| 9165 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 9166 | .rpc_cred = cred, |
| 9167 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9168 | struct rpc_task_setup task_setup_data = { |
| 9169 | .rpc_client = clp->cl_rpcclient, |
| 9170 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9171 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 9172 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9173 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9174 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9175 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9176 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9177 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9178 | goto out_err; |
| 9179 | |
| 9180 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 9181 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9182 | if (calldata == NULL) |
| 9183 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9184 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9185 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9186 | msg.rpc_argp = &calldata->args; |
| 9187 | msg.rpc_resp = &calldata->res; |
| 9188 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9189 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9190 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9191 | ret = rpc_run_task(&task_setup_data); |
| 9192 | if (IS_ERR(ret)) |
| 9193 | goto out_err; |
| 9194 | return ret; |
| 9195 | out_put_clp: |
| 9196 | nfs_put_client(clp); |
| 9197 | out_err: |
| 9198 | nfs41_release_slot(slot); |
| 9199 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9200 | } |
| 9201 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9202 | static int nfs41_proc_async_sequence(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9203 | { |
| 9204 | struct rpc_task *task; |
| 9205 | int ret = 0; |
| 9206 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 9207 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 9208 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9209 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9210 | if (IS_ERR(task)) |
| 9211 | ret = PTR_ERR(task); |
| 9212 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 9213 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9214 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9215 | return ret; |
| 9216 | } |
| 9217 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9218 | static int nfs4_proc_sequence(struct nfs_client *clp, const struct cred *cred) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9219 | { |
| 9220 | struct rpc_task *task; |
| 9221 | int ret; |
| 9222 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9223 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9224 | if (IS_ERR(task)) { |
| 9225 | ret = PTR_ERR(task); |
| 9226 | goto out; |
| 9227 | } |
| 9228 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 9229 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9230 | ret = task->tk_status; |
| 9231 | rpc_put_task(task); |
| 9232 | out: |
| 9233 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9234 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9235 | } |
| 9236 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9237 | struct nfs4_reclaim_complete_data { |
| 9238 | struct nfs_client *clp; |
| 9239 | struct nfs41_reclaim_complete_args arg; |
| 9240 | struct nfs41_reclaim_complete_res res; |
| 9241 | }; |
| 9242 | |
| 9243 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 9244 | { |
| 9245 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9246 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9247 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9248 | &calldata->arg.seq_args, |
| 9249 | &calldata->res.seq_res, |
| 9250 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9251 | } |
| 9252 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9253 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9254 | { |
| 9255 | switch(task->tk_status) { |
| 9256 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 9257 | wake_up_all(&clp->cl_lock_waitq); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9258 | fallthrough; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9259 | case -NFS4ERR_COMPLETE_ALREADY: |
| 9260 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 9261 | break; |
| 9262 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9263 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9264 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 9265 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9266 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9267 | case -NFS4ERR_BADSESSION: |
| 9268 | case -NFS4ERR_DEADSESSION: |
| 9269 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9270 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9271 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9272 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9273 | } |
| 9274 | return 0; |
| 9275 | } |
| 9276 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9277 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 9278 | { |
| 9279 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9280 | struct nfs_client *clp = calldata->clp; |
| 9281 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 9282 | |
| 9283 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9284 | if (!nfs41_sequence_done(task, res)) |
| 9285 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9286 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9287 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9288 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 9289 | rpc_restart_call_prepare(task); |
| 9290 | return; |
| 9291 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9292 | dprintk("<-- %s\n", __func__); |
| 9293 | } |
| 9294 | |
| 9295 | static void nfs4_free_reclaim_complete_data(void *data) |
| 9296 | { |
| 9297 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9298 | |
| 9299 | kfree(calldata); |
| 9300 | } |
| 9301 | |
| 9302 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 9303 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 9304 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 9305 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 9306 | }; |
| 9307 | |
| 9308 | /* |
| 9309 | * Issue a global reclaim complete. |
| 9310 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9311 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9312 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9313 | { |
| 9314 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9315 | struct rpc_message msg = { |
| 9316 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9317 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9318 | }; |
| 9319 | struct rpc_task_setup task_setup_data = { |
| 9320 | .rpc_client = clp->cl_rpcclient, |
| 9321 | .rpc_message = &msg, |
| 9322 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9323 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9324 | }; |
| 9325 | int status = -ENOMEM; |
| 9326 | |
| 9327 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 9328 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9329 | if (calldata == NULL) |
| 9330 | goto out; |
| 9331 | calldata->clp = clp; |
| 9332 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9333 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9334 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0, 1); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9335 | msg.rpc_argp = &calldata->arg; |
| 9336 | msg.rpc_resp = &calldata->res; |
| 9337 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9338 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9339 | out: |
| 9340 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9341 | return status; |
| 9342 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9343 | |
| 9344 | static void |
| 9345 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9346 | { |
| 9347 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9348 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9349 | |
| 9350 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9351 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9352 | &lgp->res.seq_res, task); |
| 9353 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9354 | } |
| 9355 | |
| 9356 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9357 | { |
| 9358 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9359 | |
| 9360 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9361 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9362 | dprintk("<-- %s\n", __func__); |
| 9363 | } |
| 9364 | |
| 9365 | static int |
| 9366 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9367 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9368 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9369 | struct inode *inode = lgp->args.inode; |
| 9370 | struct nfs_server *server = NFS_SERVER(inode); |
| 9371 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9372 | int nfs4err = task->tk_status; |
| 9373 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9374 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9375 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9376 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9377 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9378 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9379 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9380 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9381 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9382 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9383 | |
| 9384 | /* |
| 9385 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9386 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9387 | * retry go inband. |
| 9388 | */ |
| 9389 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9390 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9391 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9392 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9393 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9394 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9395 | */ |
| 9396 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9397 | status = -EOVERFLOW; |
| 9398 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9399 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9400 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9401 | * (or clients) writing to the same RAID stripe except when |
| 9402 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9403 | * |
| 9404 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9405 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9406 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9407 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9408 | if (lgp->args.minlength == 0) { |
| 9409 | status = -EOVERFLOW; |
| 9410 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9411 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9412 | status = -EBUSY; |
| 9413 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9414 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9415 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9416 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9417 | case -NFS4ERR_DELEG_REVOKED: |
| 9418 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9419 | case -NFS4ERR_EXPIRED: |
| 9420 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9421 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9422 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9423 | lo = NFS_I(inode)->layout; |
| 9424 | /* If the open stateid was bad, then recover it. */ |
| 9425 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9426 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9427 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9428 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9429 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9430 | break; |
| 9431 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9432 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9433 | /* |
| 9434 | * Mark the bad layout state as invalid, then retry |
| 9435 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9436 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9437 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9438 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9439 | pnfs_free_lseg_list(&head); |
| 9440 | status = -EAGAIN; |
| 9441 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9442 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9443 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9444 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9445 | if (!status) { |
| 9446 | if (exception->retry) |
| 9447 | status = -EAGAIN; |
| 9448 | else |
| 9449 | status = err; |
| 9450 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9451 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9452 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9453 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9454 | } |
| 9455 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9456 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9457 | { |
| 9458 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9459 | return nfs_page_array_len(0, max_resp_sz); |
| 9460 | } |
| 9461 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9462 | static void nfs4_layoutget_release(void *calldata) |
| 9463 | { |
| 9464 | struct nfs4_layoutget *lgp = calldata; |
| 9465 | |
| 9466 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9467 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9468 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9469 | dprintk("<-- %s\n", __func__); |
| 9470 | } |
| 9471 | |
| 9472 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9473 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9474 | .rpc_call_done = nfs4_layoutget_done, |
| 9475 | .rpc_release = nfs4_layoutget_release, |
| 9476 | }; |
| 9477 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9478 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9479 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9480 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9481 | struct inode *inode = lgp->args.inode; |
| 9482 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9483 | struct rpc_task *task; |
| 9484 | struct rpc_message msg = { |
| 9485 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9486 | .rpc_argp = &lgp->args, |
| 9487 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9488 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9489 | }; |
| 9490 | struct rpc_task_setup task_setup_data = { |
| 9491 | .rpc_client = server->client, |
| 9492 | .rpc_message = &msg, |
| 9493 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9494 | .callback_data = lgp, |
Trond Myklebust | 63ec2b6 | 2020-02-07 19:40:14 -0500 | [diff] [blame] | 9495 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9496 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9497 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9498 | struct nfs4_exception exception = { |
| 9499 | .inode = inode, |
| 9500 | .timeout = *timeout, |
| 9501 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9502 | int status = 0; |
| 9503 | |
| 9504 | dprintk("--> %s\n", __func__); |
| 9505 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 9506 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 9507 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 9508 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9509 | nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9510 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9511 | task = rpc_run_task(&task_setup_data); |
Xiyu Yang | 6e47666 | 2020-04-25 21:04:40 +0800 | [diff] [blame] | 9512 | |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9513 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9514 | if (status != 0) |
| 9515 | goto out; |
| 9516 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9517 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9518 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9519 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9520 | } else if (lgp->res.layoutp->len == 0) { |
| 9521 | status = -EAGAIN; |
| 9522 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9523 | } else |
| 9524 | lseg = pnfs_layout_process(lgp); |
| 9525 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9526 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9527 | &lgp->args.range, |
| 9528 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9529 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9530 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9531 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9532 | rpc_put_task(task); |
| 9533 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9534 | if (status) |
| 9535 | return ERR_PTR(status); |
| 9536 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9537 | } |
| 9538 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9539 | static void |
| 9540 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9541 | { |
| 9542 | struct nfs4_layoutreturn *lrp = calldata; |
| 9543 | |
| 9544 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9545 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9546 | &lrp->args.seq_args, |
| 9547 | &lrp->res.seq_res, |
| 9548 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9549 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9550 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9551 | } |
| 9552 | |
| 9553 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9554 | { |
| 9555 | struct nfs4_layoutreturn *lrp = calldata; |
| 9556 | struct nfs_server *server; |
| 9557 | |
| 9558 | dprintk("--> %s\n", __func__); |
| 9559 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9560 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9561 | return; |
| 9562 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9563 | /* |
| 9564 | * Was there an RPC level error? Assume the call succeeded, |
| 9565 | * and that we need to release the layout |
| 9566 | */ |
| 9567 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9568 | lrp->res.lrs_present = 0; |
| 9569 | return; |
| 9570 | } |
| 9571 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9572 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9573 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9574 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9575 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9576 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9577 | lrp->args.inode)) |
| 9578 | goto out_restart; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9579 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9580 | default: |
| 9581 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9582 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9583 | case 0: |
| 9584 | break; |
| 9585 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9586 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9587 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9588 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9589 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9590 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9591 | return; |
| 9592 | out_restart: |
| 9593 | task->tk_status = 0; |
| 9594 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9595 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9596 | } |
| 9597 | |
| 9598 | static void nfs4_layoutreturn_release(void *calldata) |
| 9599 | { |
| 9600 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9601 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9602 | |
| 9603 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9604 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9605 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9606 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9607 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9608 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9609 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9610 | nfs_iput_and_deactive(lrp->inode); |
Trond Myklebust | 44ea8df | 2020-04-02 15:37:02 -0400 | [diff] [blame] | 9611 | put_cred(lrp->cred); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9612 | kfree(calldata); |
| 9613 | dprintk("<-- %s\n", __func__); |
| 9614 | } |
| 9615 | |
| 9616 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9617 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9618 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9619 | .rpc_release = nfs4_layoutreturn_release, |
| 9620 | }; |
| 9621 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9622 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9623 | { |
| 9624 | struct rpc_task *task; |
| 9625 | struct rpc_message msg = { |
| 9626 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9627 | .rpc_argp = &lrp->args, |
| 9628 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9629 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9630 | }; |
| 9631 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9632 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9633 | .rpc_message = &msg, |
| 9634 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9635 | .callback_data = lrp, |
| 9636 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9637 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9638 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9639 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9640 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9641 | &task_setup_data.rpc_client, &msg); |
| 9642 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9643 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d973bd0 | 2021-06-01 11:35:56 -0400 | [diff] [blame] | 9644 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9645 | if (!sync) { |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9646 | if (!lrp->inode) { |
| 9647 | nfs4_layoutreturn_release(lrp); |
| 9648 | return -EAGAIN; |
| 9649 | } |
| 9650 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9651 | } |
Trond Myklebust | d973bd0 | 2021-06-01 11:35:56 -0400 | [diff] [blame] | 9652 | if (!lrp->inode) |
| 9653 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, |
| 9654 | 1); |
| 9655 | else |
| 9656 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, |
| 9657 | 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9658 | task = rpc_run_task(&task_setup_data); |
| 9659 | if (IS_ERR(task)) |
| 9660 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9661 | if (sync) |
| 9662 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9663 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9664 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9665 | rpc_put_task(task); |
| 9666 | return status; |
| 9667 | } |
| 9668 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9669 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9670 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9671 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9672 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9673 | { |
| 9674 | struct nfs4_getdeviceinfo_args args = { |
| 9675 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9676 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9677 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9678 | }; |
| 9679 | struct nfs4_getdeviceinfo_res res = { |
| 9680 | .pdev = pdev, |
| 9681 | }; |
| 9682 | struct rpc_message msg = { |
| 9683 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9684 | .rpc_argp = &args, |
| 9685 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9686 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9687 | }; |
| 9688 | int status; |
| 9689 | |
| 9690 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9691 | 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] | 9692 | if (res.notification & ~args.notify_types) |
| 9693 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9694 | if (res.notification != args.notify_types) |
| 9695 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9696 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9697 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9698 | |
| 9699 | return status; |
| 9700 | } |
| 9701 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9702 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9703 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9704 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9705 | { |
| 9706 | struct nfs4_exception exception = { }; |
| 9707 | int err; |
| 9708 | |
| 9709 | do { |
| 9710 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9711 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9712 | &exception); |
| 9713 | } while (exception.retry); |
| 9714 | return err; |
| 9715 | } |
| 9716 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9717 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9718 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9719 | { |
| 9720 | struct nfs4_layoutcommit_data *data = calldata; |
| 9721 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9722 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9723 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9724 | &data->args.seq_args, |
| 9725 | &data->res.seq_res, |
| 9726 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9727 | } |
| 9728 | |
| 9729 | static void |
| 9730 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9731 | { |
| 9732 | struct nfs4_layoutcommit_data *data = calldata; |
| 9733 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9734 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9735 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9736 | return; |
| 9737 | |
| 9738 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9739 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9740 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9741 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9742 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9743 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9744 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9745 | break; |
| 9746 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9747 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9748 | rpc_restart_call_prepare(task); |
| 9749 | return; |
| 9750 | } |
| 9751 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9752 | } |
| 9753 | |
| 9754 | static void nfs4_layoutcommit_release(void *calldata) |
| 9755 | { |
| 9756 | struct nfs4_layoutcommit_data *data = calldata; |
| 9757 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9758 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9759 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9760 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9761 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9762 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9763 | kfree(data); |
| 9764 | } |
| 9765 | |
| 9766 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9767 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9768 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9769 | .rpc_release = nfs4_layoutcommit_release, |
| 9770 | }; |
| 9771 | |
| 9772 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9773 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9774 | { |
| 9775 | struct rpc_message msg = { |
| 9776 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9777 | .rpc_argp = &data->args, |
| 9778 | .rpc_resp = &data->res, |
| 9779 | .rpc_cred = data->cred, |
| 9780 | }; |
| 9781 | struct rpc_task_setup task_setup_data = { |
| 9782 | .task = &data->task, |
| 9783 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9784 | .rpc_message = &msg, |
| 9785 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9786 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9787 | }; |
| 9788 | struct rpc_task *task; |
| 9789 | int status = 0; |
| 9790 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9791 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9792 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9793 | data->args.lastbytewritten, |
| 9794 | data->args.inode->i_ino); |
| 9795 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9796 | if (!sync) { |
| 9797 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9798 | if (data->inode == NULL) { |
| 9799 | nfs4_layoutcommit_release(data); |
| 9800 | return -EAGAIN; |
| 9801 | } |
| 9802 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9803 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9804 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9805 | task = rpc_run_task(&task_setup_data); |
| 9806 | if (IS_ERR(task)) |
| 9807 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9808 | if (sync) |
| 9809 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9810 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9811 | dprintk("%s: status %d\n", __func__, status); |
| 9812 | rpc_put_task(task); |
| 9813 | return status; |
| 9814 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9815 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9816 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9817 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9818 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9819 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9820 | static int |
| 9821 | _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] | 9822 | struct nfs_fsinfo *info, |
| 9823 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9824 | { |
| 9825 | struct nfs41_secinfo_no_name_args args = { |
| 9826 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9827 | }; |
| 9828 | struct nfs4_secinfo_res res = { |
| 9829 | .flavors = flavors, |
| 9830 | }; |
| 9831 | struct rpc_message msg = { |
| 9832 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9833 | .rpc_argp = &args, |
| 9834 | .rpc_resp = &res, |
| 9835 | }; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9836 | struct nfs4_call_sync_data data = { |
| 9837 | .seq_server = server, |
| 9838 | .seq_args = &args.seq_args, |
| 9839 | .seq_res = &res.seq_res, |
| 9840 | }; |
| 9841 | struct rpc_task_setup task_setup = { |
| 9842 | .rpc_client = server->client, |
| 9843 | .rpc_message = &msg, |
| 9844 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9845 | .callback_data = &data, |
| 9846 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9847 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9848 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9849 | int status; |
| 9850 | |
| 9851 | if (use_integrity) { |
Colin Ian King | 48bb6ec | 2020-06-10 00:22:57 +0100 | [diff] [blame] | 9852 | task_setup.rpc_client = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9853 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9854 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9855 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9856 | } |
| 9857 | |
| 9858 | dprintk("--> %s\n", __func__); |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9859 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9860 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9861 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9862 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9863 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9864 | |
| 9865 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9866 | } |
| 9867 | |
| 9868 | static int |
| 9869 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9870 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9871 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9872 | struct nfs4_exception exception = { |
| 9873 | .interruptible = true, |
| 9874 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9875 | int err; |
| 9876 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9877 | /* first try using integrity protection */ |
| 9878 | err = -NFS4ERR_WRONGSEC; |
| 9879 | |
| 9880 | /* try to use integrity protection with machine cred */ |
| 9881 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9882 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9883 | flavors, true); |
| 9884 | |
| 9885 | /* |
| 9886 | * if unable to use integrity protection, or SECINFO with |
| 9887 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9888 | * disallowed by spec, but exists in deployed servers) use |
| 9889 | * the current filesystem's rpc_client and the user cred. |
| 9890 | */ |
| 9891 | if (err == -NFS4ERR_WRONGSEC) |
| 9892 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9893 | flavors, false); |
| 9894 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9895 | switch (err) { |
| 9896 | case 0: |
| 9897 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9898 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9899 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9900 | default: |
| 9901 | err = nfs4_handle_exception(server, err, &exception); |
| 9902 | } |
| 9903 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9904 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9905 | return err; |
| 9906 | } |
| 9907 | |
| 9908 | static int |
| 9909 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9910 | struct nfs_fsinfo *info) |
| 9911 | { |
| 9912 | int err; |
| 9913 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9914 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9915 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9916 | struct nfs4_secinfo4 *secinfo; |
| 9917 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9918 | |
| 9919 | page = alloc_page(GFP_KERNEL); |
| 9920 | if (!page) { |
| 9921 | err = -ENOMEM; |
| 9922 | goto out; |
| 9923 | } |
| 9924 | |
| 9925 | flavors = page_address(page); |
| 9926 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9927 | |
| 9928 | /* |
| 9929 | * Fall back on "guess and check" method if |
| 9930 | * the server doesn't support SECINFO_NO_NAME |
| 9931 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9932 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9933 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9934 | goto out_freepage; |
| 9935 | } |
| 9936 | if (err) |
| 9937 | goto out_freepage; |
| 9938 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9939 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9940 | secinfo = &flavors->flavors[i]; |
| 9941 | |
| 9942 | switch (secinfo->flavor) { |
| 9943 | case RPC_AUTH_NULL: |
| 9944 | case RPC_AUTH_UNIX: |
| 9945 | case RPC_AUTH_GSS: |
| 9946 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9947 | &secinfo->flavor_info); |
| 9948 | break; |
| 9949 | default: |
| 9950 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9951 | break; |
| 9952 | } |
| 9953 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9954 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9955 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9956 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9957 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9958 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9959 | info, flavor); |
| 9960 | if (!err) |
| 9961 | break; |
| 9962 | } |
| 9963 | } |
| 9964 | |
| 9965 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9966 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9967 | |
| 9968 | out_freepage: |
| 9969 | put_page(page); |
| 9970 | if (err == -EACCES) |
| 9971 | return -EPERM; |
| 9972 | out: |
| 9973 | return err; |
| 9974 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9975 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9976 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9977 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9978 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9979 | { |
| 9980 | int status; |
| 9981 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9982 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9983 | }; |
| 9984 | struct nfs41_test_stateid_res res; |
| 9985 | struct rpc_message msg = { |
| 9986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9987 | .rpc_argp = &args, |
| 9988 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9989 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9990 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9991 | struct rpc_clnt *rpc_client = server->client; |
| 9992 | |
| 9993 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9994 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9995 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9996 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9997 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9998 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9999 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10000 | if (status != NFS_OK) { |
| 10001 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 10002 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10003 | } |
| 10004 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 10005 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10006 | } |
| 10007 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10008 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 10009 | int err, struct nfs4_exception *exception) |
| 10010 | { |
| 10011 | exception->retry = 0; |
| 10012 | switch(err) { |
| 10013 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 10014 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10015 | nfs4_handle_exception(server, err, exception); |
| 10016 | break; |
| 10017 | case -NFS4ERR_BADSESSION: |
| 10018 | case -NFS4ERR_BADSLOT: |
| 10019 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 10020 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 10021 | case -NFS4ERR_DEADSESSION: |
| 10022 | nfs4_do_handle_exception(server, err, exception); |
| 10023 | } |
| 10024 | } |
| 10025 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10026 | /** |
| 10027 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 10028 | * |
| 10029 | * @server: server / transport on which to perform the operation |
| 10030 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10031 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10032 | * |
| 10033 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 10034 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 10035 | * failed or the state ID is not currently valid. |
| 10036 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10037 | static int nfs41_test_stateid(struct nfs_server *server, |
| 10038 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10039 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10040 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 10041 | struct nfs4_exception exception = { |
| 10042 | .interruptible = true, |
| 10043 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10044 | int err; |
| 10045 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10046 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10047 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10048 | } while (exception.retry); |
| 10049 | return err; |
| 10050 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10051 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10052 | struct nfs_free_stateid_data { |
| 10053 | struct nfs_server *server; |
| 10054 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10055 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10056 | }; |
| 10057 | |
| 10058 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 10059 | { |
| 10060 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 10061 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10062 | &data->args.seq_args, |
| 10063 | &data->res.seq_res, |
| 10064 | task); |
| 10065 | } |
| 10066 | |
| 10067 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 10068 | { |
| 10069 | struct nfs_free_stateid_data *data = calldata; |
| 10070 | |
| 10071 | nfs41_sequence_done(task, &data->res.seq_res); |
| 10072 | |
| 10073 | switch (task->tk_status) { |
| 10074 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 10075 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10076 | rpc_restart_call_prepare(task); |
| 10077 | } |
| 10078 | } |
| 10079 | |
| 10080 | static void nfs41_free_stateid_release(void *calldata) |
| 10081 | { |
| 10082 | kfree(calldata); |
| 10083 | } |
| 10084 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10085 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10086 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 10087 | .rpc_call_done = nfs41_free_stateid_done, |
| 10088 | .rpc_release = nfs41_free_stateid_release, |
| 10089 | }; |
| 10090 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10091 | /** |
| 10092 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 10093 | * |
| 10094 | * @server: server / transport on which to perform the operation |
| 10095 | * @stateid: state ID to release |
| 10096 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 10097 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10098 | * |
| 10099 | * Note: this function is always asynchronous. |
| 10100 | */ |
| 10101 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10102 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10103 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10104 | bool privileged) |
| 10105 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10106 | struct rpc_message msg = { |
| 10107 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10108 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10109 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10110 | struct rpc_task_setup task_setup = { |
| 10111 | .rpc_client = server->client, |
| 10112 | .rpc_message = &msg, |
| 10113 | .callback_ops = &nfs41_free_stateid_ops, |
| 10114 | .flags = RPC_TASK_ASYNC, |
| 10115 | }; |
| 10116 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10117 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10118 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10119 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 10120 | &task_setup.rpc_client, &msg); |
| 10121 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10122 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10123 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 10124 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10125 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10126 | data->server = server; |
| 10127 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 10128 | |
| 10129 | task_setup.callback_data = data; |
| 10130 | |
| 10131 | msg.rpc_argp = &data->args; |
| 10132 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10133 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, privileged); |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10134 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10135 | if (IS_ERR(task)) |
| 10136 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10137 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10138 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10139 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10140 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 10141 | static void |
| 10142 | 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] | 10143 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10144 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10145 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10146 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10147 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10148 | } |
| 10149 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10150 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 10151 | const nfs4_stateid *s2) |
| 10152 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 10153 | if (s1->type != s2->type) |
| 10154 | return false; |
| 10155 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10156 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10157 | return false; |
| 10158 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10159 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10160 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10161 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 10162 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10163 | } |
| 10164 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 10165 | #endif /* CONFIG_NFS_V4_1 */ |
| 10166 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10167 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 10168 | const nfs4_stateid *s2) |
| 10169 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10170 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10171 | } |
| 10172 | |
| 10173 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10174 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10175 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10176 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10177 | .recover_open = nfs4_open_reclaim, |
| 10178 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10179 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10180 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10181 | }; |
| 10182 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10183 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10184 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10185 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 10186 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 10187 | .recover_open = nfs4_open_reclaim, |
| 10188 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10189 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 10190 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10191 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10192 | }; |
| 10193 | #endif /* CONFIG_NFS_V4_1 */ |
| 10194 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10195 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10196 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10197 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 10198 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10199 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10200 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10201 | }; |
| 10202 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10203 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10204 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10205 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 10206 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 10207 | .recover_open = nfs41_open_expired, |
| 10208 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10209 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10210 | }; |
| 10211 | #endif /* CONFIG_NFS_V4_1 */ |
| 10212 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10213 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10214 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10215 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10216 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10217 | }; |
| 10218 | |
| 10219 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10220 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10221 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10222 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10223 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10224 | }; |
| 10225 | #endif |
| 10226 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10227 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10228 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10229 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10230 | }; |
| 10231 | |
| 10232 | #if defined(CONFIG_NFS_V4_1) |
| 10233 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10234 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10235 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10236 | }; |
| 10237 | #endif /* CONFIG_NFS_V4_1 */ |
| 10238 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10239 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 10240 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10241 | .init_caps = NFS_CAP_READDIRPLUS |
| 10242 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10243 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10244 | .init_client = nfs40_init_client, |
| 10245 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10246 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10247 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10248 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10249 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10250 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10251 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10252 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 10253 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 10254 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10255 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10256 | }; |
| 10257 | |
| 10258 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10259 | static struct nfs_seqid * |
| 10260 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 10261 | { |
| 10262 | return NULL; |
| 10263 | } |
| 10264 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10265 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 10266 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10267 | .init_caps = NFS_CAP_READDIRPLUS |
| 10268 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 10269 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 10270 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10271 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 10272 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10273 | .init_client = nfs41_init_client, |
| 10274 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10275 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10276 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10277 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10278 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10279 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10280 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10281 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10282 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10283 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10284 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10285 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10286 | }; |
| 10287 | #endif |
| 10288 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10289 | #if defined(CONFIG_NFS_V4_2) |
| 10290 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 10291 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10292 | .init_caps = NFS_CAP_READDIRPLUS |
| 10293 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10294 | | NFS_CAP_POSIX_LOCK |
| 10295 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 10296 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10297 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 10298 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 10299 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 10300 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 10301 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 10302 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 10303 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 10304 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 10305 | | NFS_CAP_CLONE |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 10306 | | NFS_CAP_LAYOUTERROR |
| 10307 | | NFS_CAP_READ_PLUS, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10308 | .init_client = nfs41_init_client, |
| 10309 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10310 | .match_stateid = nfs41_match_stateid, |
| 10311 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10312 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10313 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10314 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10315 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10316 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10317 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10318 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10319 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 10320 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10321 | }; |
| 10322 | #endif |
| 10323 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10324 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 10325 | [0] = &nfs_v4_0_minor_ops, |
| 10326 | #if defined(CONFIG_NFS_V4_1) |
| 10327 | [1] = &nfs_v4_1_minor_ops, |
| 10328 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10329 | #if defined(CONFIG_NFS_V4_2) |
| 10330 | [2] = &nfs_v4_2_minor_ops, |
| 10331 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10332 | }; |
| 10333 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 10334 | 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] | 10335 | { |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10336 | ssize_t error, error2, error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10337 | |
| 10338 | error = generic_listxattr(dentry, list, size); |
| 10339 | if (error < 0) |
| 10340 | return error; |
| 10341 | if (list) { |
| 10342 | list += error; |
| 10343 | size -= error; |
| 10344 | } |
| 10345 | |
| 10346 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10347 | if (error2 < 0) |
| 10348 | return error2; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10349 | |
| 10350 | if (list) { |
| 10351 | list += error2; |
| 10352 | size -= error2; |
| 10353 | } |
| 10354 | |
| 10355 | error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); |
| 10356 | if (error3 < 0) |
| 10357 | return error3; |
| 10358 | |
| 10359 | return error + error2 + error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10360 | } |
| 10361 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10362 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10363 | .create = nfs_create, |
| 10364 | .lookup = nfs_lookup, |
| 10365 | .atomic_open = nfs_atomic_open, |
| 10366 | .link = nfs_link, |
| 10367 | .unlink = nfs_unlink, |
| 10368 | .symlink = nfs_symlink, |
| 10369 | .mkdir = nfs_mkdir, |
| 10370 | .rmdir = nfs_rmdir, |
| 10371 | .mknod = nfs_mknod, |
| 10372 | .rename = nfs_rename, |
| 10373 | .permission = nfs_permission, |
| 10374 | .getattr = nfs_getattr, |
| 10375 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10376 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10377 | }; |
| 10378 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10379 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10380 | .permission = nfs_permission, |
| 10381 | .getattr = nfs_getattr, |
| 10382 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10383 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10384 | }; |
| 10385 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10386 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10387 | .version = 4, /* protocol version */ |
| 10388 | .dentry_ops = &nfs4_dentry_operations, |
| 10389 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10390 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10391 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10392 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10393 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10394 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10395 | .getattr = nfs4_proc_getattr, |
| 10396 | .setattr = nfs4_proc_setattr, |
| 10397 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10398 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10399 | .access = nfs4_proc_access, |
| 10400 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10401 | .create = nfs4_proc_create, |
| 10402 | .remove = nfs4_proc_remove, |
| 10403 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10404 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10405 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10406 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10407 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10408 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10409 | .link = nfs4_proc_link, |
| 10410 | .symlink = nfs4_proc_symlink, |
| 10411 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10412 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10413 | .readdir = nfs4_proc_readdir, |
| 10414 | .mknod = nfs4_proc_mknod, |
| 10415 | .statfs = nfs4_proc_statfs, |
| 10416 | .fsinfo = nfs4_proc_fsinfo, |
| 10417 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10418 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10419 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10420 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10421 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10422 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10423 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10424 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10425 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10426 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10427 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10428 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10429 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10430 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10431 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10432 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10433 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10434 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10435 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10436 | .create_server = nfs4_create_server, |
| 10437 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10438 | }; |
| 10439 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10440 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10441 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10442 | .list = nfs4_xattr_list_nfs4_acl, |
| 10443 | .get = nfs4_xattr_get_nfs4_acl, |
| 10444 | .set = nfs4_xattr_set_nfs4_acl, |
| 10445 | }; |
| 10446 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10447 | #ifdef CONFIG_NFS_V4_2 |
| 10448 | static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { |
| 10449 | .prefix = XATTR_USER_PREFIX, |
| 10450 | .get = nfs4_xattr_get_nfs4_user, |
| 10451 | .set = nfs4_xattr_set_nfs4_user, |
| 10452 | }; |
| 10453 | #endif |
| 10454 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10455 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10456 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10457 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10458 | &nfs4_xattr_nfs4_label_handler, |
| 10459 | #endif |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10460 | #ifdef CONFIG_NFS_V4_2 |
| 10461 | &nfs4_xattr_nfs4_user_handler, |
| 10462 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10463 | NULL |
| 10464 | }; |
| 10465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10466 | /* |
| 10467 | * Local variables: |
| 10468 | * c-basic-offset: 8 |
| 10469 | * End: |
| 10470 | */ |