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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 75 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 76 | #define NFS4_BITMASK_SZ 3 |
| 77 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 78 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 80 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 81 | /* file attributes which can be mapped to nfs attributes */ |
| 82 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 83 | | ATTR_UID \ |
| 84 | | ATTR_GID \ |
| 85 | | ATTR_SIZE \ |
| 86 | | ATTR_ATIME \ |
| 87 | | ATTR_MTIME \ |
| 88 | | ATTR_CTIME \ |
| 89 | | ATTR_ATIME_SET \ |
| 90 | | ATTR_MTIME_SET) |
| 91 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 92 | struct nfs4_opendata; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 93 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | 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] | 95 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame^] | 96 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 97 | struct nfs_fattr *fattr, struct inode *inode); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 98 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 99 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 100 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 101 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 102 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 103 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 104 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 105 | struct nfs4_slot *slot, |
| 106 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 107 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 108 | const struct cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 109 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 110 | const struct cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 111 | #endif |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 112 | static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], |
| 113 | const __u32 *src, struct inode *inode, |
| 114 | struct nfs_server *server, |
| 115 | struct nfs4_label *label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 116 | |
| 117 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 118 | static inline struct nfs4_label * |
| 119 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 120 | struct iattr *sattr, struct nfs4_label *label) |
| 121 | { |
| 122 | int err; |
| 123 | |
| 124 | if (label == NULL) |
| 125 | return NULL; |
| 126 | |
| 127 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 128 | return NULL; |
| 129 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 130 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 131 | &dentry->d_name, (void **)&label->label, &label->len); |
| 132 | if (err == 0) |
| 133 | return label; |
| 134 | |
| 135 | return NULL; |
| 136 | } |
| 137 | static inline void |
| 138 | nfs4_label_release_security(struct nfs4_label *label) |
| 139 | { |
| 140 | if (label) |
| 141 | security_release_secctx(label->label, label->len); |
| 142 | } |
| 143 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 144 | { |
| 145 | if (label) |
| 146 | return server->attr_bitmask; |
| 147 | |
| 148 | return server->attr_bitmask_nl; |
| 149 | } |
| 150 | #else |
| 151 | static inline struct nfs4_label * |
| 152 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 153 | struct iattr *sattr, struct nfs4_label *l) |
| 154 | { return NULL; } |
| 155 | static inline void |
| 156 | nfs4_label_release_security(struct nfs4_label *label) |
| 157 | { return; } |
| 158 | static inline u32 * |
| 159 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 160 | { return server->attr_bitmask; } |
| 161 | #endif |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 164 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 166 | if (err >= -1000) |
| 167 | return err; |
| 168 | switch (err) { |
| 169 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 170 | case -NFS4ERR_LAYOUTTRYLATER: |
| 171 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 172 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 173 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 174 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 175 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 176 | case -NFS4ERR_BADOWNER: |
| 177 | case -NFS4ERR_BADNAME: |
| 178 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 179 | case -NFS4ERR_SHARE_DENIED: |
| 180 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 181 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 182 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 183 | case -NFS4ERR_FILE_OPEN: |
| 184 | return -EBUSY; |
Trond Myklebust | 9fff59e | 2020-11-02 20:11:32 -0500 | [diff] [blame] | 185 | case -NFS4ERR_NOT_SAME: |
| 186 | return -ENOTSYNC; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 187 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 189 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 190 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 192 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /* |
| 196 | * This is our standard bitmap for GETATTR requests. |
| 197 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 198 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | FATTR4_WORD0_TYPE |
| 200 | | FATTR4_WORD0_CHANGE |
| 201 | | FATTR4_WORD0_SIZE |
| 202 | | FATTR4_WORD0_FSID |
| 203 | | FATTR4_WORD0_FILEID, |
| 204 | FATTR4_WORD1_MODE |
| 205 | | FATTR4_WORD1_NUMLINKS |
| 206 | | FATTR4_WORD1_OWNER |
| 207 | | FATTR4_WORD1_OWNER_GROUP |
| 208 | | FATTR4_WORD1_RAWDEV |
| 209 | | FATTR4_WORD1_SPACE_USED |
| 210 | | FATTR4_WORD1_TIME_ACCESS |
| 211 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 212 | | FATTR4_WORD1_TIME_MODIFY |
| 213 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 214 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 215 | FATTR4_WORD2_SECURITY_LABEL |
| 216 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 219 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 220 | FATTR4_WORD0_TYPE |
| 221 | | FATTR4_WORD0_CHANGE |
| 222 | | FATTR4_WORD0_SIZE |
| 223 | | FATTR4_WORD0_FSID |
| 224 | | FATTR4_WORD0_FILEID, |
| 225 | FATTR4_WORD1_MODE |
| 226 | | FATTR4_WORD1_NUMLINKS |
| 227 | | FATTR4_WORD1_OWNER |
| 228 | | FATTR4_WORD1_OWNER_GROUP |
| 229 | | FATTR4_WORD1_RAWDEV |
| 230 | | FATTR4_WORD1_SPACE_USED |
| 231 | | FATTR4_WORD1_TIME_ACCESS |
| 232 | | FATTR4_WORD1_TIME_METADATA |
| 233 | | FATTR4_WORD1_TIME_MODIFY, |
| 234 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 235 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 236 | | FATTR4_WORD2_SECURITY_LABEL |
| 237 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 238 | }; |
| 239 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 240 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 241 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 242 | | FATTR4_WORD0_FILEID, |
| 243 | }; |
| 244 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 245 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | FATTR4_WORD0_FILES_AVAIL |
| 247 | | FATTR4_WORD0_FILES_FREE |
| 248 | | FATTR4_WORD0_FILES_TOTAL, |
| 249 | FATTR4_WORD1_SPACE_AVAIL |
| 250 | | FATTR4_WORD1_SPACE_FREE |
| 251 | | FATTR4_WORD1_SPACE_TOTAL |
| 252 | }; |
| 253 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 254 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | FATTR4_WORD0_MAXLINK |
| 256 | | FATTR4_WORD0_MAXNAME, |
| 257 | 0 |
| 258 | }; |
| 259 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 260 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | | FATTR4_WORD0_MAXREAD |
| 262 | | FATTR4_WORD0_MAXWRITE |
| 263 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 264 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 265 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 266 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 267 | | FATTR4_WORD2_CLONE_BLKSIZE |
Trond Myklebust | 7f08a33 | 2021-03-26 09:50:19 -0400 | [diff] [blame] | 268 | | FATTR4_WORD2_CHANGE_ATTR_TYPE |
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, |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 289 | struct inode *inode, unsigned long flags) |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 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 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 297 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity) | flags; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 298 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 299 | /* Remove the attributes over which we have full control */ |
| 300 | dst[1] &= ~FATTR4_WORD1_RAWDEV; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 301 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 302 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 303 | |
| 304 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 305 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 306 | |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 307 | if (!(cache_validity & NFS_INO_INVALID_MODE)) |
| 308 | dst[1] &= ~FATTR4_WORD1_MODE; |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 309 | if (!(cache_validity & NFS_INO_INVALID_OTHER)) |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 310 | dst[1] &= ~(FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 313 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | struct nfs4_readdir_arg *readdir) |
| 315 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 316 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 317 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 320 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | readdir->cookie = 0; |
| 326 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 327 | if (cookie == 2) |
| 328 | return; |
| 329 | |
| 330 | /* |
| 331 | * NFSv4 servers do not return entries for '.' and '..' |
| 332 | * Therefore, we fake these entries here. We let '.' |
| 333 | * have cookie 0 and '..' have cookie 1. Note that |
| 334 | * when talking to the server, we always send cookie 0 |
| 335 | * instead of 1 or 2. |
| 336 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 337 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | if (cookie == 0) { |
| 340 | *p++ = xdr_one; /* next */ |
| 341 | *p++ = xdr_zero; /* cookie, first word */ |
| 342 | *p++ = xdr_one; /* cookie, second word */ |
| 343 | *p++ = xdr_one; /* entry len */ |
| 344 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 345 | p++; |
| 346 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 347 | *p++ = htonl(attrs); /* bitmap */ |
| 348 | *p++ = htonl(12); /* attribute buffer length */ |
| 349 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 350 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | *p++ = xdr_one; /* next */ |
| 354 | *p++ = xdr_zero; /* cookie, first word */ |
| 355 | *p++ = xdr_two; /* cookie, second word */ |
| 356 | *p++ = xdr_two; /* entry len */ |
| 357 | memcpy(p, "..\0\0", 4); /* entry */ |
| 358 | p++; |
| 359 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 360 | *p++ = htonl(attrs); /* bitmap */ |
| 361 | *p++ = htonl(12); /* attribute buffer length */ |
| 362 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 363 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | readdir->pgbase = (char *)p - (char *)start; |
| 366 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 367 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 370 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 371 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 372 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 373 | { |
| 374 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 375 | |
| 376 | ops->test_and_free_expired(server, stateid, cred); |
| 377 | } |
| 378 | |
| 379 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 380 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 381 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 382 | { |
| 383 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 384 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 385 | } |
| 386 | |
| 387 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 388 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 389 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 390 | { |
| 391 | nfs4_stateid tmp; |
| 392 | |
| 393 | nfs4_stateid_copy(&tmp, stateid); |
| 394 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 395 | } |
| 396 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 397 | static long nfs4_update_delay(long *timeout) |
| 398 | { |
| 399 | long ret; |
| 400 | if (!timeout) |
| 401 | return NFS4_POLL_RETRY_MAX; |
| 402 | if (*timeout <= 0) |
| 403 | *timeout = NFS4_POLL_RETRY_MIN; |
| 404 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 405 | *timeout = NFS4_POLL_RETRY_MAX; |
| 406 | ret = *timeout; |
| 407 | *timeout <<= 1; |
| 408 | return ret; |
| 409 | } |
| 410 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 411 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 412 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 413 | might_sleep(); |
| 414 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 415 | freezable_schedule_timeout_killable_unsafe( |
| 416 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 417 | if (!__fatal_signal_pending(current)) |
| 418 | return 0; |
| 419 | return -EINTR; |
| 420 | } |
| 421 | |
| 422 | static int nfs4_delay_interruptible(long *timeout) |
| 423 | { |
| 424 | might_sleep(); |
| 425 | |
He Zhe | 59679d9 | 2020-07-06 17:52:24 +0800 | [diff] [blame] | 426 | freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 427 | if (!signal_pending(current)) |
| 428 | return 0; |
| 429 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 430 | } |
| 431 | |
| 432 | static int nfs4_delay(long *timeout, bool interruptible) |
| 433 | { |
| 434 | if (interruptible) |
| 435 | return nfs4_delay_interruptible(timeout); |
| 436 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 437 | } |
| 438 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 439 | static const nfs4_stateid * |
| 440 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 441 | { |
| 442 | if (!stateid) |
| 443 | return NULL; |
| 444 | switch (stateid->type) { |
| 445 | case NFS4_OPEN_STATEID_TYPE: |
| 446 | case NFS4_LOCK_STATEID_TYPE: |
| 447 | case NFS4_DELEGATION_STATEID_TYPE: |
| 448 | return stateid; |
| 449 | default: |
| 450 | break; |
| 451 | } |
| 452 | return NULL; |
| 453 | } |
| 454 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 455 | /* This is the error handling routine for processes that are allowed |
| 456 | * to sleep. |
| 457 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 458 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 459 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 460 | { |
| 461 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 462 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 463 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 464 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 465 | int ret = errorcode; |
| 466 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 467 | exception->delay = 0; |
| 468 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 469 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 470 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 471 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 472 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 473 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 474 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 475 | switch(errorcode) { |
| 476 | case 0: |
| 477 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 478 | case -NFS4ERR_BADHANDLE: |
| 479 | case -ESTALE: |
| 480 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 481 | pnfs_destroy_layout(NFS_I(inode)); |
| 482 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 483 | case -NFS4ERR_DELEG_REVOKED: |
| 484 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 485 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 486 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame] | 487 | case -NFS4ERR_PARTNER_NO_AUTH: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 488 | if (inode != NULL && stateid != NULL) { |
| 489 | nfs_inode_find_state_and_recover(inode, |
| 490 | stateid); |
| 491 | goto wait_on_recovery; |
| 492 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 493 | fallthrough; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 494 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 495 | if (inode) { |
| 496 | int err; |
| 497 | |
| 498 | err = nfs_async_inode_return_delegation(inode, |
| 499 | stateid); |
| 500 | if (err == 0) |
| 501 | goto wait_on_recovery; |
| 502 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 503 | exception->retry = 1; |
| 504 | break; |
| 505 | } |
| 506 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 507 | if (state == NULL) |
| 508 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 509 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 510 | if (ret < 0) |
| 511 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 512 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 513 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 514 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 515 | nfs4_schedule_lease_recovery(clp); |
| 516 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 517 | case -NFS4ERR_MOVED: |
| 518 | ret = nfs4_schedule_migration_recovery(server); |
| 519 | if (ret < 0) |
| 520 | break; |
| 521 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 522 | case -NFS4ERR_LEASE_MOVED: |
| 523 | nfs4_schedule_lease_moved_recovery(clp); |
| 524 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 525 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 526 | case -NFS4ERR_BADSESSION: |
| 527 | case -NFS4ERR_BADSLOT: |
| 528 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 529 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 530 | case -NFS4ERR_DEADSESSION: |
| 531 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 532 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 533 | /* Handled in nfs41_sequence_process() */ |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 534 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 535 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 536 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 537 | if (exception->timeout > HZ) { |
| 538 | /* We have retried a decent amount, time to |
| 539 | * fail |
| 540 | */ |
| 541 | ret = -EBUSY; |
| 542 | break; |
| 543 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 544 | fallthrough; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 545 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 546 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 547 | fallthrough; |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 548 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 549 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 550 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 551 | exception->delay = 1; |
| 552 | return 0; |
| 553 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 554 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 555 | case -NFS4ERR_OLD_STATEID: |
| 556 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 557 | break; |
| 558 | case -NFS4ERR_BADOWNER: |
| 559 | /* The following works around a Linux server bug! */ |
| 560 | case -NFS4ERR_BADNAME: |
| 561 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 562 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 563 | exception->retry = 1; |
| 564 | printk(KERN_WARNING "NFS: v4 server %s " |
| 565 | "does not accept raw " |
| 566 | "uid/gids. " |
| 567 | "Reenabling the idmapper.\n", |
| 568 | server->nfs_client->cl_hostname); |
| 569 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 570 | } |
| 571 | /* We failed to handle the error */ |
| 572 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 573 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 574 | exception->recovering = 1; |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | /* This is the error handling routine for processes that are allowed |
| 579 | * to sleep. |
| 580 | */ |
| 581 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 582 | { |
| 583 | struct nfs_client *clp = server->nfs_client; |
| 584 | int ret; |
| 585 | |
| 586 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 587 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 588 | ret = nfs4_delay(&exception->timeout, |
| 589 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 590 | goto out_retry; |
| 591 | } |
| 592 | if (exception->recovering) { |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 593 | if (exception->task_is_privileged) |
| 594 | return -EDEADLOCK; |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 595 | ret = nfs4_wait_clnt_recover(clp); |
| 596 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 597 | return -EIO; |
| 598 | goto out_retry; |
| 599 | } |
| 600 | return ret; |
| 601 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 602 | if (ret == 0) |
| 603 | exception->retry = 1; |
| 604 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 605 | } |
| 606 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 607 | static int |
| 608 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 609 | int errorcode, struct nfs4_exception *exception) |
| 610 | { |
| 611 | struct nfs_client *clp = server->nfs_client; |
| 612 | int ret; |
| 613 | |
| 614 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 615 | if (exception->delay) { |
| 616 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 617 | goto out_retry; |
| 618 | } |
| 619 | if (exception->recovering) { |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 620 | if (exception->task_is_privileged) |
| 621 | return -EDEADLOCK; |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 622 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 623 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 624 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 625 | goto out_retry; |
| 626 | } |
| 627 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 628 | ret = -EIO; |
| 629 | return ret; |
| 630 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 631 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 632 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 633 | /* |
| 634 | * For NFS4ERR_MOVED, the client transport will need to |
| 635 | * be recomputed after migration recovery has completed. |
| 636 | */ |
| 637 | if (errorcode == -NFS4ERR_MOVED) |
| 638 | rpc_task_release_transport(task); |
| 639 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 640 | return ret; |
| 641 | } |
| 642 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 643 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 644 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 645 | struct nfs4_state *state, long *timeout) |
| 646 | { |
| 647 | struct nfs4_exception exception = { |
| 648 | .state = state, |
| 649 | }; |
| 650 | |
| 651 | if (task->tk_status >= 0) |
| 652 | return 0; |
| 653 | if (timeout) |
| 654 | exception.timeout = *timeout; |
| 655 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 656 | task->tk_status, |
| 657 | &exception); |
| 658 | if (exception.delay && timeout) |
| 659 | *timeout = exception.timeout; |
| 660 | if (exception.retry) |
| 661 | return -EAGAIN; |
| 662 | return 0; |
| 663 | } |
| 664 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 665 | /* |
| 666 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 667 | * or 'false' otherwise. |
| 668 | */ |
| 669 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 670 | { |
| 671 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 672 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 673 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 674 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 675 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | spin_lock(&clp->cl_lock); |
| 678 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 679 | clp->cl_last_renewal = timestamp; |
| 680 | spin_unlock(&clp->cl_lock); |
| 681 | } |
| 682 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 683 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 684 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 685 | struct nfs_client *clp = server->nfs_client; |
| 686 | |
| 687 | if (!nfs4_has_session(clp)) |
| 688 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 689 | } |
| 690 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 691 | struct nfs4_call_sync_data { |
| 692 | const struct nfs_server *seq_server; |
| 693 | struct nfs4_sequence_args *seq_args; |
| 694 | struct nfs4_sequence_res *seq_res; |
| 695 | }; |
| 696 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 697 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 698 | struct nfs4_sequence_res *res, int cache_reply, |
| 699 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 700 | { |
| 701 | args->sa_slot = NULL; |
| 702 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 703 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 704 | |
| 705 | res->sr_slot = NULL; |
| 706 | } |
| 707 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 708 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 709 | { |
| 710 | struct nfs4_slot *slot = res->sr_slot; |
| 711 | struct nfs4_slot_table *tbl; |
| 712 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 713 | tbl = slot->table; |
| 714 | spin_lock(&tbl->slot_tbl_lock); |
| 715 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 716 | nfs4_free_slot(tbl, slot); |
| 717 | spin_unlock(&tbl->slot_tbl_lock); |
| 718 | |
| 719 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static int nfs40_sequence_done(struct rpc_task *task, |
| 723 | struct nfs4_sequence_res *res) |
| 724 | { |
| 725 | if (res->sr_slot != NULL) |
| 726 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 727 | return 1; |
| 728 | } |
| 729 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 730 | #if defined(CONFIG_NFS_V4_1) |
| 731 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 732 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 733 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 734 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 735 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 736 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 737 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 738 | if (!slot) |
| 739 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 740 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 741 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 742 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 743 | /* Bump the slot sequence number */ |
| 744 | if (slot->seq_done) |
| 745 | slot->seq_nr++; |
| 746 | slot->seq_done = 0; |
| 747 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 748 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 749 | /* Be nice to the server: try to ensure that the last transmitted |
| 750 | * value for highest_user_slotid <= target_highest_slotid |
| 751 | */ |
| 752 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 753 | send_new_highest_used_slotid = true; |
| 754 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 755 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 756 | send_new_highest_used_slotid = false; |
| 757 | goto out_unlock; |
| 758 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 759 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 760 | |
| 761 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 762 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 763 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 764 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 765 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 766 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 767 | if (waitqueue_active(&tbl->slot_waitq)) |
| 768 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 769 | } |
| 770 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 771 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 772 | { |
| 773 | nfs41_release_slot(res->sr_slot); |
| 774 | res->sr_slot = NULL; |
| 775 | } |
| 776 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 777 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 778 | u32 seqnr) |
| 779 | { |
| 780 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 781 | slot->seq_nr_highest_sent = seqnr; |
| 782 | } |
| 783 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 784 | u32 seqnr) |
| 785 | { |
| 786 | slot->seq_nr_highest_sent = seqnr; |
| 787 | slot->seq_nr_last_acked = seqnr; |
| 788 | } |
| 789 | |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 790 | static void nfs4_probe_sequence(struct nfs_client *client, const struct cred *cred, |
| 791 | struct nfs4_slot *slot) |
| 792 | { |
| 793 | struct rpc_task *task = _nfs41_proc_sequence(client, cred, slot, true); |
| 794 | if (!IS_ERR(task)) |
| 795 | rpc_put_task_async(task); |
| 796 | } |
| 797 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 798 | static int nfs41_sequence_process(struct rpc_task *task, |
| 799 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 800 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 801 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 802 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 803 | struct nfs_client *clp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 804 | int status; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 805 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 806 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 807 | if (slot == NULL) |
| 808 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 809 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 810 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 811 | goto out; |
| 812 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 813 | session = slot->table->session; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 814 | clp = session->clp; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 815 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 816 | trace_nfs4_sequence_done(session, res); |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 817 | |
| 818 | status = res->sr_status; |
| 819 | if (task->tk_status == -NFS4ERR_DEADSESSION) |
| 820 | status = -NFS4ERR_DEADSESSION; |
| 821 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 822 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 823 | switch (status) { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 824 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 825 | /* Mark this sequence number as having been acked */ |
| 826 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 827 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 828 | slot->seq_done = 1; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 829 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 830 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 831 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 832 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 833 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 834 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 835 | case 1: |
| 836 | /* |
| 837 | * sr_status remains 1 if an RPC level error occurred. |
| 838 | * The server may or may not have processed the sequence |
| 839 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 840 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 841 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 842 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 843 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 844 | case -NFS4ERR_DELAY: |
| 845 | /* The server detected a resend of the RPC call and |
| 846 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 847 | * of RFC5661. |
| 848 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 849 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 850 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 851 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 852 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 853 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 854 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 855 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 856 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 857 | /* |
| 858 | * The server thinks we tried to replay a request. |
| 859 | * Retry the call after bumping the sequence ID. |
| 860 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 861 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 862 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 863 | case -NFS4ERR_BADSLOT: |
| 864 | /* |
| 865 | * The slot id we used was probably retired. Try again |
| 866 | * using a different slot id. |
| 867 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 868 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 869 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 870 | goto retry_nowait; |
| 871 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 872 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 873 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 874 | * Were one or more calls using this slot interrupted? |
| 875 | * If the server never received the request, then our |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 876 | * transmitted slot sequence number may be too high. However, |
| 877 | * if the server did receive the request then it might |
| 878 | * accidentally give us a reply with a mismatched operation. |
| 879 | * We can sort this out by sending a lone sequence operation |
| 880 | * to the server on the same slot. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 881 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 882 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 883 | slot->seq_nr--; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 884 | if (task->tk_msg.rpc_proc != &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE]) { |
| 885 | nfs4_probe_sequence(clp, task->tk_msg.rpc_cred, slot); |
| 886 | res->sr_slot = NULL; |
| 887 | } |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 888 | goto retry_nowait; |
| 889 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 890 | /* |
| 891 | * RFC5661: |
| 892 | * A retry might be sent while the original request is |
| 893 | * still in progress on the replier. The replier SHOULD |
| 894 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 895 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 896 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 897 | * |
| 898 | * Restart the search after a delay. |
| 899 | */ |
| 900 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 901 | goto out_retry; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 902 | case -NFS4ERR_BADSESSION: |
| 903 | case -NFS4ERR_DEADSESSION: |
| 904 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 905 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 906 | default: |
| 907 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 908 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 909 | } |
| 910 | out: |
| 911 | /* The session may be reset by one of the error handlers. */ |
| 912 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 913 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 914 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 915 | session_recover: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 916 | nfs4_schedule_session_recovery(session, status); |
| 917 | dprintk("%s ERROR: %d Reset session\n", __func__, status); |
| 918 | nfs41_sequence_free_slot(res); |
| 919 | goto out; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 920 | retry_new_seq: |
| 921 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 922 | retry_nowait: |
| 923 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 924 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 925 | task->tk_status = 0; |
| 926 | ret = 0; |
| 927 | } |
| 928 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 929 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 930 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 931 | goto out; |
| 932 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 933 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 934 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 935 | |
| 936 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 937 | { |
| 938 | if (!nfs41_sequence_process(task, res)) |
| 939 | return 0; |
| 940 | if (res->sr_slot != NULL) |
| 941 | nfs41_sequence_free_slot(res); |
| 942 | return 1; |
| 943 | |
| 944 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 945 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 946 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 947 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 948 | { |
| 949 | if (res->sr_slot == NULL) |
| 950 | return 1; |
| 951 | if (res->sr_slot->table->session != NULL) |
| 952 | return nfs41_sequence_process(task, res); |
| 953 | return nfs40_sequence_done(task, res); |
| 954 | } |
| 955 | |
| 956 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 957 | { |
| 958 | if (res->sr_slot != NULL) { |
| 959 | if (res->sr_slot->table->session != NULL) |
| 960 | nfs41_sequence_free_slot(res); |
| 961 | else |
| 962 | nfs40_sequence_free_slot(res); |
| 963 | } |
| 964 | } |
| 965 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 966 | 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] | 967 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 968 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 969 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 970 | if (!res->sr_slot->table->session) |
| 971 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 972 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 973 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 974 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 975 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 976 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 977 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 978 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 979 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 980 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 981 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 982 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 983 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 984 | } |
| 985 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 986 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 987 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 988 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 989 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 990 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 991 | } |
| 992 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 993 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 994 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 995 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 996 | }; |
| 997 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 998 | #else /* !CONFIG_NFS_V4_1 */ |
| 999 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1000 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 1001 | { |
| 1002 | return nfs40_sequence_done(task, res); |
| 1003 | } |
| 1004 | |
| 1005 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1006 | { |
| 1007 | if (res->sr_slot != NULL) |
| 1008 | nfs40_sequence_free_slot(res); |
| 1009 | } |
| 1010 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1011 | int nfs4_sequence_done(struct rpc_task *task, |
| 1012 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1013 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1014 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1015 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1016 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1017 | |
| 1018 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1019 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1020 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 1021 | { |
| 1022 | res->sr_timestamp = jiffies; |
| 1023 | res->sr_status_flags = 0; |
| 1024 | res->sr_status = 1; |
| 1025 | } |
| 1026 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1027 | static |
| 1028 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 1029 | struct nfs4_sequence_res *res, |
| 1030 | struct nfs4_slot *slot) |
| 1031 | { |
| 1032 | if (!slot) |
| 1033 | return; |
| 1034 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 1035 | args->sa_slot = slot; |
| 1036 | |
| 1037 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1041 | struct nfs4_sequence_args *args, |
| 1042 | struct nfs4_sequence_res *res, |
| 1043 | struct rpc_task *task) |
| 1044 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1045 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1046 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1047 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1048 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1049 | /* slot already allocated? */ |
| 1050 | if (res->sr_slot != NULL) |
| 1051 | goto out_start; |
| 1052 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1053 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1054 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1055 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1056 | spin_lock(&tbl->slot_tbl_lock); |
| 1057 | /* The state manager will wait until the slot table is empty */ |
| 1058 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1059 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1060 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1061 | slot = nfs4_alloc_slot(tbl); |
| 1062 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1063 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1064 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1065 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1066 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1067 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1068 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1069 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1070 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1071 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1072 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1073 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1074 | rpc_call_start(task); |
| 1075 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1076 | out_sleep_timeout: |
| 1077 | /* Try again in 1/4 second */ |
| 1078 | if (args->sa_privileged) |
| 1079 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1080 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1081 | else |
| 1082 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1083 | NULL, jiffies + (HZ >> 2)); |
| 1084 | spin_unlock(&tbl->slot_tbl_lock); |
| 1085 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1086 | out_sleep: |
| 1087 | if (args->sa_privileged) |
| 1088 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1089 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1090 | else |
| 1091 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1092 | spin_unlock(&tbl->slot_tbl_lock); |
| 1093 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1094 | } |
| 1095 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1096 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1097 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1098 | { |
| 1099 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1100 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1101 | data->seq_args, data->seq_res, task); |
| 1102 | } |
| 1103 | |
| 1104 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1105 | { |
| 1106 | struct nfs4_call_sync_data *data = calldata; |
| 1107 | nfs4_sequence_done(task, data->seq_res); |
| 1108 | } |
| 1109 | |
| 1110 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1111 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1112 | .rpc_call_done = nfs40_call_sync_done, |
| 1113 | }; |
| 1114 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1115 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1116 | { |
| 1117 | int ret; |
| 1118 | struct rpc_task *task; |
| 1119 | |
| 1120 | task = rpc_run_task(task_setup); |
| 1121 | if (IS_ERR(task)) |
| 1122 | return PTR_ERR(task); |
| 1123 | |
| 1124 | ret = task->tk_status; |
| 1125 | rpc_put_task(task); |
| 1126 | return ret; |
| 1127 | } |
| 1128 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1129 | static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
| 1130 | struct nfs_server *server, |
| 1131 | struct rpc_message *msg, |
| 1132 | struct nfs4_sequence_args *args, |
| 1133 | struct nfs4_sequence_res *res, |
| 1134 | unsigned short task_flags) |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1135 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1136 | struct nfs_client *clp = server->nfs_client; |
| 1137 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1138 | .seq_server = server, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1139 | .seq_args = args, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1140 | .seq_res = res, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1141 | }; |
| 1142 | struct rpc_task_setup task_setup = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1143 | .rpc_client = clnt, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1144 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1145 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1146 | .callback_data = &data, |
| 1147 | .flags = task_flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1148 | }; |
| 1149 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1150 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1153 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 1154 | struct nfs_server *server, |
| 1155 | struct rpc_message *msg, |
| 1156 | struct nfs4_sequence_args *args, |
| 1157 | struct nfs4_sequence_res *res) |
| 1158 | { |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 1159 | unsigned short task_flags = 0; |
| 1160 | |
| 1161 | if (server->nfs_client->cl_minorversion) |
| 1162 | task_flags = RPC_TASK_MOVEABLE; |
| 1163 | return nfs4_do_call_sync(clnt, server, msg, args, res, task_flags); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1167 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1168 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1169 | struct rpc_message *msg, |
| 1170 | struct nfs4_sequence_args *args, |
| 1171 | struct nfs4_sequence_res *res, |
| 1172 | int cache_reply) |
| 1173 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1174 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1175 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1178 | static void |
| 1179 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1180 | { |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 1181 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 1182 | NFS_INO_INVALID_CTIME | |
| 1183 | NFS_INO_INVALID_NLINK); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1184 | inc_nlink(inode); |
| 1185 | } |
| 1186 | |
| 1187 | static void |
Trond Myklebust | 1301e42 | 2021-04-01 14:57:56 -0400 | [diff] [blame] | 1188 | nfs4_inc_nlink(struct inode *inode) |
| 1189 | { |
| 1190 | spin_lock(&inode->i_lock); |
| 1191 | nfs4_inc_nlink_locked(inode); |
| 1192 | spin_unlock(&inode->i_lock); |
| 1193 | } |
| 1194 | |
| 1195 | static void |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1196 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1197 | { |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 1198 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 1199 | NFS_INO_INVALID_CTIME | |
| 1200 | NFS_INO_INVALID_NLINK); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1201 | drop_nlink(inode); |
| 1202 | } |
| 1203 | |
| 1204 | static void |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1205 | nfs4_update_changeattr_locked(struct inode *inode, |
| 1206 | struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1207 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1209 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1210 | u64 change_attr = inode_peek_iversion_raw(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 1212 | cache_validity |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME; |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1213 | if (S_ISDIR(inode->i_mode)) |
| 1214 | cache_validity |= NFS_INO_INVALID_DATA; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1215 | |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1216 | switch (NFS_SERVER(inode)->change_attr_type) { |
| 1217 | case NFS4_CHANGE_TYPE_IS_UNDEFINED: |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1218 | if (cinfo->after == change_attr) |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1219 | goto out; |
| 1220 | break; |
| 1221 | default: |
| 1222 | if ((s64)(change_attr - cinfo->after) >= 0) |
| 1223 | goto out; |
| 1224 | } |
| 1225 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1226 | inode_set_iversion_raw(inode, cinfo->after); |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1227 | if (!cinfo->atomic || cinfo->before != change_attr) { |
| 1228 | if (S_ISDIR(inode->i_mode)) |
| 1229 | nfs_force_lookup_revalidate(inode); |
| 1230 | |
| 1231 | if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) |
| 1232 | cache_validity |= |
| 1233 | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL | |
| 1234 | NFS_INO_INVALID_SIZE | NFS_INO_INVALID_OTHER | |
| 1235 | NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_NLINK | |
| 1236 | NFS_INO_INVALID_MODE | NFS_INO_INVALID_XATTR | |
| 1237 | NFS_INO_REVAL_PAGECACHE; |
| 1238 | nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); |
| 1239 | } |
| 1240 | nfsi->attrtimeo_timestamp = jiffies; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1241 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1242 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1243 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1244 | out: |
| 1245 | nfs_set_cache_invalid(inode, cache_validity); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1246 | } |
| 1247 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1248 | void |
| 1249 | nfs4_update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1250 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1251 | { |
| 1252 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1253 | nfs4_update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | spin_unlock(&dir->i_lock); |
| 1255 | } |
| 1256 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1257 | struct nfs4_open_createattrs { |
| 1258 | struct nfs4_label *label; |
| 1259 | struct iattr *sattr; |
| 1260 | const __u32 verf[2]; |
| 1261 | }; |
| 1262 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1263 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1264 | int err, struct nfs4_exception *exception) |
| 1265 | { |
| 1266 | if (err != -EINVAL) |
| 1267 | return false; |
| 1268 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1269 | return false; |
| 1270 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1271 | exception->retry = 1; |
| 1272 | return true; |
| 1273 | } |
| 1274 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1275 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1276 | { |
| 1277 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1278 | } |
| 1279 | |
| 1280 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1281 | { |
| 1282 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1283 | |
| 1284 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1285 | } |
| 1286 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1287 | static u32 |
| 1288 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1289 | fmode_t fmode, int openflags) |
| 1290 | { |
| 1291 | u32 res = 0; |
| 1292 | |
| 1293 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1294 | case FMODE_READ: |
| 1295 | res = NFS4_SHARE_ACCESS_READ; |
| 1296 | break; |
| 1297 | case FMODE_WRITE: |
| 1298 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1299 | break; |
| 1300 | case FMODE_READ|FMODE_WRITE: |
| 1301 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1302 | } |
| 1303 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1304 | goto out; |
| 1305 | /* Want no delegation if we're using O_DIRECT */ |
| 1306 | if (openflags & O_DIRECT) |
| 1307 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1308 | out: |
| 1309 | return res; |
| 1310 | } |
| 1311 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1312 | static enum open_claim_type4 |
| 1313 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1314 | enum open_claim_type4 claim) |
| 1315 | { |
| 1316 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1317 | return claim; |
| 1318 | switch (claim) { |
| 1319 | default: |
| 1320 | return claim; |
| 1321 | case NFS4_OPEN_CLAIM_FH: |
| 1322 | return NFS4_OPEN_CLAIM_NULL; |
| 1323 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1324 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1325 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1326 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1327 | } |
| 1328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | |
| 1330 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1331 | { |
| 1332 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1333 | p->o_res.seqid = p->o_arg.seqid; |
| 1334 | p->c_res.seqid = p->c_arg.seqid; |
| 1335 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1336 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1337 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1338 | 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] | 1339 | } |
| 1340 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1341 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1342 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1343 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1344 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1345 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1346 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1347 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1348 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1349 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1350 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1351 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1352 | struct nfs4_opendata *p; |
| 1353 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1354 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1355 | if (p == NULL) |
| 1356 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1357 | |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1358 | p->f_attr.label = nfs4_label_alloc(server, gfp_mask); |
| 1359 | if (IS_ERR(p->f_attr.label)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1360 | goto err_free_p; |
| 1361 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1362 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1363 | if (IS_ERR(p->a_label)) |
| 1364 | goto err_free_f; |
| 1365 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1366 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1367 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1368 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1369 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1370 | nfs_sb_active(dentry->d_sb); |
| 1371 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1372 | p->dir = parent; |
| 1373 | p->owner = sp; |
| 1374 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1375 | p->o_arg.open_flags = flags; |
| 1376 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1377 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1378 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1379 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1380 | if (flags & O_CREAT) { |
| 1381 | p->o_arg.umask = current_umask(); |
| 1382 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1383 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1384 | p->o_arg.u.attrs = &p->attrs; |
| 1385 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1386 | |
| 1387 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1388 | sizeof(p->o_arg.u.verifier.data)); |
| 1389 | } |
| 1390 | } |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 1391 | /* ask server to check for all possible rights as results |
| 1392 | * are cached */ |
| 1393 | switch (p->o_arg.claim) { |
| 1394 | default: |
| 1395 | break; |
| 1396 | case NFS4_OPEN_CLAIM_NULL: |
| 1397 | case NFS4_OPEN_CLAIM_FH: |
| 1398 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1399 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE | |
| 1400 | NFS4_ACCESS_EXECUTE; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1401 | #ifdef CONFIG_NFS_V4_2 |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 1402 | if (!(server->caps & NFS_CAP_XATTR)) |
| 1403 | break; |
| 1404 | p->o_arg.access |= NFS4_ACCESS_XAREAD | NFS4_ACCESS_XAWRITE | |
| 1405 | NFS4_ACCESS_XALIST; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1406 | #endif |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1407 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1408 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1409 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1410 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1411 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1412 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1413 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1414 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1415 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1416 | case NFS4_OPEN_CLAIM_NULL: |
| 1417 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1418 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1419 | p->o_arg.fh = NFS_FH(dir); |
| 1420 | break; |
| 1421 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1422 | case NFS4_OPEN_CLAIM_FH: |
| 1423 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1424 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1425 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1426 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1427 | p->c_arg.fh = &p->o_res.fh; |
| 1428 | p->c_arg.stateid = &p->o_res.stateid; |
| 1429 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1430 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1431 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1432 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1433 | |
| 1434 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1435 | nfs4_label_free(p->a_label); |
| 1436 | err_free_f: |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1437 | nfs4_label_free(p->f_attr.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1438 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1439 | kfree(p); |
| 1440 | err: |
| 1441 | dput(parent); |
| 1442 | return NULL; |
| 1443 | } |
| 1444 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1445 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1446 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1447 | struct nfs4_opendata *p = container_of(kref, |
| 1448 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1449 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1450 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1451 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1452 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1453 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1454 | if (p->state != NULL) |
| 1455 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1456 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1457 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1458 | nfs4_label_free(p->a_label); |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1459 | nfs4_label_free(p->f_attr.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1460 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1461 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1462 | dput(p->dentry); |
| 1463 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1464 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1465 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1466 | kfree(p); |
| 1467 | } |
| 1468 | |
| 1469 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1470 | { |
| 1471 | if (p != NULL) |
| 1472 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1473 | } |
| 1474 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1475 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1476 | fmode_t fmode) |
| 1477 | { |
| 1478 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1479 | case FMODE_READ|FMODE_WRITE: |
| 1480 | return state->n_rdwr != 0; |
| 1481 | case FMODE_WRITE: |
| 1482 | return state->n_wronly != 0; |
| 1483 | case FMODE_READ: |
| 1484 | return state->n_rdonly != 0; |
| 1485 | } |
| 1486 | WARN_ON_ONCE(1); |
| 1487 | return false; |
| 1488 | } |
| 1489 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1490 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1491 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1492 | { |
| 1493 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1494 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1495 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1496 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1497 | switch (claim) { |
| 1498 | case NFS4_OPEN_CLAIM_NULL: |
| 1499 | case NFS4_OPEN_CLAIM_FH: |
| 1500 | goto out; |
| 1501 | default: |
| 1502 | break; |
| 1503 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1504 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1505 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1506 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1507 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1508 | break; |
| 1509 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1510 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1511 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1512 | break; |
| 1513 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1514 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1515 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1516 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1517 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1518 | return ret; |
| 1519 | } |
| 1520 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1521 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1522 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1523 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1524 | if (delegation == NULL) |
| 1525 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1526 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1527 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1528 | switch (claim) { |
| 1529 | case NFS4_OPEN_CLAIM_NULL: |
| 1530 | case NFS4_OPEN_CLAIM_FH: |
| 1531 | break; |
| 1532 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1533 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1534 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1535 | fallthrough; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1536 | default: |
| 1537 | return 0; |
| 1538 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1539 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1540 | return 1; |
| 1541 | } |
| 1542 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1543 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1544 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1545 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1546 | case FMODE_WRITE: |
| 1547 | state->n_wronly++; |
| 1548 | break; |
| 1549 | case FMODE_READ: |
| 1550 | state->n_rdonly++; |
| 1551 | break; |
| 1552 | case FMODE_READ|FMODE_WRITE: |
| 1553 | state->n_rdwr++; |
| 1554 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1555 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1558 | #ifdef CONFIG_NFS_V4_1 |
| 1559 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1560 | { |
| 1561 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1562 | return true; |
| 1563 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1564 | return true; |
| 1565 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1566 | return true; |
| 1567 | return false; |
| 1568 | } |
| 1569 | #endif /* CONFIG_NFS_V4_1 */ |
| 1570 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1571 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1572 | { |
| 1573 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1574 | wake_up_all(&state->waitq); |
| 1575 | } |
| 1576 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1577 | 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] | 1578 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1579 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1580 | bool need_recover = false; |
| 1581 | |
| 1582 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1583 | need_recover = true; |
| 1584 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1585 | need_recover = true; |
| 1586 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1587 | need_recover = true; |
| 1588 | if (need_recover) |
| 1589 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1590 | } |
| 1591 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1592 | /* |
| 1593 | * Check for whether or not the caller may update the open stateid |
| 1594 | * to the value passed in by stateid. |
| 1595 | * |
| 1596 | * Note: This function relies heavily on the server implementing |
| 1597 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1598 | * correctly. |
| 1599 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1600 | * are then incremented on every state transition. |
| 1601 | */ |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1602 | static bool nfs_stateid_is_sequential(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1603 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1604 | { |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1605 | if (test_bit(NFS_OPEN_STATE, &state->flags)) { |
| 1606 | /* The common case - we're updating to a new sequence number */ |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1607 | if (nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1608 | if (nfs4_stateid_is_next(&state->open_stateid, stateid)) |
| 1609 | return true; |
| 1610 | return false; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1611 | } |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1612 | /* The server returned a new stateid */ |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1613 | } |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1614 | /* This is the first OPEN in this generation */ |
| 1615 | if (stateid->seqid == cpu_to_be32(1)) |
| 1616 | return true; |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1617 | return false; |
| 1618 | } |
| 1619 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1620 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1621 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1622 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1623 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1624 | if (state->n_wronly) |
| 1625 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1626 | if (state->n_rdonly) |
| 1627 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1628 | if (state->n_rdwr) |
| 1629 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1630 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1631 | } |
| 1632 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1633 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1634 | nfs4_stateid *stateid, fmode_t fmode) |
| 1635 | { |
| 1636 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1637 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1638 | case FMODE_WRITE: |
| 1639 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1640 | break; |
| 1641 | case FMODE_READ: |
| 1642 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1643 | break; |
| 1644 | case 0: |
| 1645 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1646 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1647 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1648 | } |
| 1649 | if (stateid == NULL) |
| 1650 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1651 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1652 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1653 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1654 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1655 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1656 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1657 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1658 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1659 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1660 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1661 | out: |
| 1662 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1663 | } |
| 1664 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1665 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1666 | nfs4_stateid *arg_stateid, |
| 1667 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1668 | { |
| 1669 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1670 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1671 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1672 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1673 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1674 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1675 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1676 | } |
| 1677 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1678 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1679 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1680 | __must_hold(&state->owner->so_lock) |
| 1681 | __must_hold(&state->seqlock) |
| 1682 | __must_hold(RCU) |
| 1683 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1684 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1685 | DEFINE_WAIT(wait); |
| 1686 | int status = 0; |
| 1687 | for (;;) { |
| 1688 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1689 | if (nfs_stateid_is_sequential(state, stateid)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1690 | break; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1691 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1692 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1693 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1694 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1695 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1696 | break; |
| 1697 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1698 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1699 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1700 | /* |
| 1701 | * Ensure we process the state changes in the same order |
| 1702 | * in which the server processed them by delaying the |
| 1703 | * update of the stateid until we are in sequence. |
| 1704 | */ |
| 1705 | write_sequnlock(&state->seqlock); |
| 1706 | spin_unlock(&state->owner->so_lock); |
| 1707 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1708 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1709 | |
zhouchuangao | bb00238 | 2021-05-09 19:34:37 -0700 | [diff] [blame] | 1710 | if (!fatal_signal_pending(current)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1711 | if (schedule_timeout(5*HZ) == 0) |
| 1712 | status = -EAGAIN; |
| 1713 | else |
| 1714 | status = 0; |
| 1715 | } else |
| 1716 | status = -EINTR; |
| 1717 | finish_wait(&state->waitq, &wait); |
| 1718 | rcu_read_lock(); |
| 1719 | spin_lock(&state->owner->so_lock); |
| 1720 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1721 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1722 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1723 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1724 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1725 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1726 | nfs_test_and_clear_all_open_stateid(state); |
| 1727 | } |
| 1728 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1729 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1730 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1731 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1732 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1733 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1734 | } |
| 1735 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1736 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1737 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1738 | fmode_t fmode, |
| 1739 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1741 | /* |
| 1742 | * Protect the call to nfs4_state_set_mode_locked and |
| 1743 | * serialise the stateid update |
| 1744 | */ |
| 1745 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1746 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1747 | switch (fmode) { |
| 1748 | case FMODE_READ: |
| 1749 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1750 | break; |
| 1751 | case FMODE_WRITE: |
| 1752 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1753 | break; |
| 1754 | case FMODE_READ|FMODE_WRITE: |
| 1755 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1756 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1757 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1758 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1759 | } |
| 1760 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1761 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1762 | { |
| 1763 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1764 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1765 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1766 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1767 | } |
| 1768 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1769 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1770 | const nfs4_stateid *deleg_stateid, |
| 1771 | fmode_t fmode) |
| 1772 | { |
| 1773 | /* |
| 1774 | * Protect the call to nfs4_state_set_mode_locked and |
| 1775 | * serialise the stateid update |
| 1776 | */ |
| 1777 | write_seqlock(&state->seqlock); |
| 1778 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1779 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1780 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1783 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1784 | { |
| 1785 | write_seqlock(&state->seqlock); |
| 1786 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1787 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1788 | write_sequnlock(&state->seqlock); |
| 1789 | } |
| 1790 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1791 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1792 | const nfs4_stateid *open_stateid, |
| 1793 | const nfs4_stateid *delegation, |
| 1794 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1795 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1796 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1797 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1798 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1799 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1800 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1801 | int ret = 0; |
| 1802 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1803 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1804 | |
| 1805 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1806 | spin_lock(&state->owner->so_lock); |
| 1807 | if (open_stateid != NULL) { |
| 1808 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1809 | ret = 1; |
| 1810 | } |
| 1811 | |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1812 | deleg_cur = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1813 | if (deleg_cur == NULL) |
| 1814 | goto no_delegation; |
| 1815 | |
| 1816 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1817 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1818 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1819 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1820 | goto no_delegation_unlock; |
| 1821 | |
| 1822 | if (delegation == NULL) |
| 1823 | delegation = &deleg_cur->stateid; |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1824 | else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1825 | goto no_delegation_unlock; |
| 1826 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1827 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1828 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1829 | ret = 1; |
| 1830 | no_delegation_unlock: |
| 1831 | spin_unlock(&deleg_cur->lock); |
| 1832 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1833 | if (ret) |
| 1834 | update_open_stateflags(state, fmode); |
| 1835 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1836 | rcu_read_unlock(); |
| 1837 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1838 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1839 | nfs4_schedule_state_manager(clp); |
| 1840 | if (freeme.type != 0) |
| 1841 | nfs4_test_and_free_stateid(server, &freeme, |
| 1842 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1843 | |
| 1844 | return ret; |
| 1845 | } |
| 1846 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1847 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1848 | const nfs4_stateid *stateid) |
| 1849 | { |
| 1850 | struct nfs4_state *state = lsp->ls_state; |
| 1851 | bool ret = false; |
| 1852 | |
| 1853 | spin_lock(&state->state_lock); |
| 1854 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1855 | goto out_noupdate; |
| 1856 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1857 | goto out_noupdate; |
| 1858 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1859 | ret = true; |
| 1860 | out_noupdate: |
| 1861 | spin_unlock(&state->state_lock); |
| 1862 | return ret; |
| 1863 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1864 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1865 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1866 | { |
| 1867 | struct nfs_delegation *delegation; |
| 1868 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1869 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1870 | rcu_read_lock(); |
Trond Myklebust | 40e6aa1 | 2019-10-27 13:38:45 -0400 | [diff] [blame] | 1871 | delegation = nfs4_get_valid_delegation(inode); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1872 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1873 | rcu_read_unlock(); |
| 1874 | return; |
| 1875 | } |
| 1876 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1877 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1878 | } |
| 1879 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1880 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1881 | { |
| 1882 | struct nfs4_state *state = opendata->state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1883 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1884 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1885 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1886 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1887 | nfs4_stateid stateid; |
| 1888 | int ret = -EAGAIN; |
| 1889 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1890 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1891 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1892 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1893 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1894 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1895 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1896 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1897 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1898 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 1899 | delegation = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1900 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1901 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1902 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1903 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1904 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1905 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1906 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1907 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1908 | if (!opendata->is_recover) { |
| 1909 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1910 | if (ret != 0) |
| 1911 | goto out; |
| 1912 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1913 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1914 | |
| 1915 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1916 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1917 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1918 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1919 | out: |
| 1920 | return ERR_PTR(ret); |
| 1921 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1922 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1923 | return state; |
| 1924 | } |
| 1925 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1926 | static void |
| 1927 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1928 | { |
| 1929 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1930 | struct nfs_delegation *delegation; |
| 1931 | int delegation_flags = 0; |
| 1932 | |
| 1933 | rcu_read_lock(); |
| 1934 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1935 | if (delegation) |
| 1936 | delegation_flags = delegation->flags; |
| 1937 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1938 | switch (data->o_arg.claim) { |
| 1939 | default: |
| 1940 | break; |
| 1941 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1942 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1943 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1944 | "returning a delegation for " |
| 1945 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1946 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1947 | return; |
| 1948 | } |
| 1949 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1950 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1951 | data->owner->so_cred, |
| 1952 | data->o_res.delegation_type, |
| 1953 | &data->o_res.delegation, |
| 1954 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1955 | else |
| 1956 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1957 | data->owner->so_cred, |
| 1958 | data->o_res.delegation_type, |
| 1959 | &data->o_res.delegation, |
| 1960 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1961 | |
| 1962 | if (data->o_res.do_recall) |
| 1963 | nfs_async_inode_return_delegation(state->inode, |
| 1964 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /* |
| 1968 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1969 | * and update the nfs4_state. |
| 1970 | */ |
| 1971 | static struct nfs4_state * |
| 1972 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1973 | { |
| 1974 | struct inode *inode = data->state->inode; |
| 1975 | struct nfs4_state *state = data->state; |
| 1976 | int ret; |
| 1977 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1978 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1979 | if (data->rpc_status) |
| 1980 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1981 | /* cached opens have already been processed */ |
| 1982 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1983 | } |
| 1984 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1985 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1986 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1987 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1988 | |
| 1989 | if (data->o_res.delegation_type != 0) |
| 1990 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1991 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1992 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1993 | NULL, data->o_arg.fmode)) |
| 1994 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1995 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1996 | |
| 1997 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1998 | } |
| 1999 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 2000 | static struct inode * |
| 2001 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 2002 | { |
| 2003 | struct inode *inode; |
| 2004 | |
| 2005 | switch (data->o_arg.claim) { |
| 2006 | case NFS4_OPEN_CLAIM_NULL: |
| 2007 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 2008 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 2009 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 2010 | return ERR_PTR(-EAGAIN); |
| 2011 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 2012 | &data->f_attr, data->f_attr.label); |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 2013 | break; |
| 2014 | default: |
| 2015 | inode = d_inode(data->dentry); |
| 2016 | ihold(inode); |
| 2017 | nfs_refresh_inode(inode, &data->f_attr); |
| 2018 | } |
| 2019 | return inode; |
| 2020 | } |
| 2021 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2022 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2023 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 2024 | { |
| 2025 | struct nfs4_state *state; |
| 2026 | struct inode *inode; |
| 2027 | |
| 2028 | inode = nfs4_opendata_get_inode(data); |
| 2029 | if (IS_ERR(inode)) |
| 2030 | return ERR_CAST(inode); |
| 2031 | if (data->state != NULL && data->state->inode == inode) { |
| 2032 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2033 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2034 | } else |
| 2035 | state = nfs4_get_open_state(inode, data->owner); |
| 2036 | iput(inode); |
| 2037 | if (state == NULL) |
| 2038 | state = ERR_PTR(-ENOMEM); |
| 2039 | return state; |
| 2040 | } |
| 2041 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2042 | static struct nfs4_state * |
| 2043 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2044 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2045 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2046 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2047 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2048 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2049 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2050 | goto out; |
| 2051 | } |
| 2052 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2053 | state = nfs4_opendata_find_nfs4_state(data); |
| 2054 | if (IS_ERR(state)) |
| 2055 | goto out; |
| 2056 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2057 | if (data->o_res.delegation_type != 0) |
| 2058 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 2059 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 2060 | NULL, data->o_arg.fmode)) { |
| 2061 | nfs4_put_open_state(state); |
| 2062 | state = ERR_PTR(-EAGAIN); |
| 2063 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2064 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 2065 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2066 | return state; |
| 2067 | } |
| 2068 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2069 | static struct nfs4_state * |
| 2070 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2071 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2072 | struct nfs4_state *ret; |
| 2073 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2074 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2075 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2076 | else |
| 2077 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2078 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2079 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2080 | } |
| 2081 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2082 | static struct nfs_open_context * |
| 2083 | 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] | 2084 | { |
| 2085 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2086 | struct nfs_open_context *ctx; |
| 2087 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2088 | rcu_read_lock(); |
| 2089 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2090 | if (ctx->state != state) |
| 2091 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2092 | if ((ctx->mode & mode) != mode) |
| 2093 | continue; |
| 2094 | if (!get_nfs_open_context(ctx)) |
| 2095 | continue; |
| 2096 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2097 | return ctx; |
| 2098 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2099 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2100 | return ERR_PTR(-ENOENT); |
| 2101 | } |
| 2102 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2103 | static struct nfs_open_context * |
| 2104 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2105 | { |
| 2106 | struct nfs_open_context *ctx; |
| 2107 | |
| 2108 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2109 | if (!IS_ERR(ctx)) |
| 2110 | return ctx; |
| 2111 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2112 | if (!IS_ERR(ctx)) |
| 2113 | return ctx; |
| 2114 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2115 | } |
| 2116 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2117 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2118 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2119 | { |
| 2120 | struct nfs4_opendata *opendata; |
| 2121 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2122 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2123 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2124 | if (opendata == NULL) |
| 2125 | return ERR_PTR(-ENOMEM); |
| 2126 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2127 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2128 | return opendata; |
| 2129 | } |
| 2130 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2131 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2132 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2133 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2134 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2135 | int ret; |
| 2136 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2137 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2138 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2139 | opendata->o_arg.open_flags = 0; |
| 2140 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2141 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2142 | NFS_SB(opendata->dentry->d_sb), |
| 2143 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2144 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2145 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2146 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2147 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2148 | if (ret != 0) |
| 2149 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2150 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2151 | if (IS_ERR(newstate)) |
| 2152 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2153 | if (newstate != opendata->state) |
| 2154 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2155 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2156 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2160 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2161 | int ret; |
| 2162 | |
| 2163 | /* memory barrier prior to reading state->n_* */ |
| 2164 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2165 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2166 | if (ret != 0) |
| 2167 | return ret; |
| 2168 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2169 | if (ret != 0) |
| 2170 | return ret; |
| 2171 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2172 | if (ret != 0) |
| 2173 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2174 | /* |
| 2175 | * We may have performed cached opens for all three recoveries. |
| 2176 | * Check if we need to update the current stateid. |
| 2177 | */ |
| 2178 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2179 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2180 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2181 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2182 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2183 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2184 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2185 | return 0; |
| 2186 | } |
| 2187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | /* |
| 2189 | * OPEN_RECLAIM: |
| 2190 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2192 | 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] | 2193 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2194 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2195 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2196 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | int status; |
| 2198 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2199 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2200 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2201 | if (IS_ERR(opendata)) |
| 2202 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2203 | rcu_read_lock(); |
| 2204 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2205 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2206 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2207 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2208 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2209 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2210 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | return status; |
| 2212 | } |
| 2213 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2214 | 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] | 2215 | { |
| 2216 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2217 | struct nfs4_exception exception = { }; |
| 2218 | int err; |
| 2219 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2220 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2221 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2222 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2223 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2224 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2225 | break; |
| 2226 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | } while (exception.retry); |
| 2228 | return err; |
| 2229 | } |
| 2230 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2231 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2232 | { |
| 2233 | struct nfs_open_context *ctx; |
| 2234 | int ret; |
| 2235 | |
| 2236 | ctx = nfs4_state_find_open_context(state); |
| 2237 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2238 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2239 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2240 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2241 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2242 | put_nfs_open_context(ctx); |
| 2243 | return ret; |
| 2244 | } |
| 2245 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2246 | 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] | 2247 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2248 | switch (err) { |
| 2249 | default: |
| 2250 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2251 | "%d.\n", __func__, err); |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame] | 2252 | fallthrough; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2253 | case 0: |
| 2254 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2255 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2256 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2257 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2258 | break; |
| 2259 | case -NFS4ERR_BADSESSION: |
| 2260 | case -NFS4ERR_BADSLOT: |
| 2261 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2262 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2263 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2264 | return -EAGAIN; |
| 2265 | case -NFS4ERR_STALE_CLIENTID: |
| 2266 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2267 | /* Don't recall a delegation if it was lost */ |
| 2268 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2269 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2270 | case -NFS4ERR_MOVED: |
| 2271 | nfs4_schedule_migration_recovery(server); |
| 2272 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2273 | case -NFS4ERR_LEASE_MOVED: |
| 2274 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2275 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2276 | case -NFS4ERR_DELEG_REVOKED: |
| 2277 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2278 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2279 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2280 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2281 | nfs_inode_find_state_and_recover(state->inode, |
| 2282 | stateid); |
| 2283 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2284 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2285 | case -NFS4ERR_DELAY: |
| 2286 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2287 | ssleep(1); |
| 2288 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2289 | case -ENOMEM: |
| 2290 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2291 | if (fl) { |
| 2292 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2293 | if (lsp) |
| 2294 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2295 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2296 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | return err; |
| 2299 | } |
| 2300 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2301 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2302 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2303 | { |
| 2304 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2305 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2306 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2307 | |
| 2308 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2309 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2310 | if (IS_ERR(opendata)) |
| 2311 | return PTR_ERR(opendata); |
| 2312 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2313 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2314 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2315 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2316 | goto out; |
| 2317 | } |
| 2318 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2319 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2320 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2321 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2322 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2323 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2324 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2325 | if (err) |
| 2326 | goto out; |
| 2327 | } |
| 2328 | nfs_state_clear_delegation(state); |
| 2329 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2330 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2331 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2332 | } |
| 2333 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2334 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2335 | { |
| 2336 | struct nfs4_opendata *data = calldata; |
| 2337 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2338 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2339 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2340 | } |
| 2341 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2342 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2343 | { |
| 2344 | struct nfs4_opendata *data = calldata; |
| 2345 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2346 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2347 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2348 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2349 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2350 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2351 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2352 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2353 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2354 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | static void nfs4_open_confirm_release(void *calldata) |
| 2358 | { |
| 2359 | struct nfs4_opendata *data = calldata; |
| 2360 | struct nfs4_state *state = NULL; |
| 2361 | |
| 2362 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2363 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2364 | goto out_free; |
| 2365 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2366 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2367 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2368 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2369 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2370 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2371 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2372 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2376 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2377 | .rpc_call_done = nfs4_open_confirm_done, |
| 2378 | .rpc_release = nfs4_open_confirm_release, |
| 2379 | }; |
| 2380 | |
| 2381 | /* |
| 2382 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2383 | */ |
| 2384 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2385 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2386 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2387 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2388 | struct rpc_message msg = { |
| 2389 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2390 | .rpc_argp = &data->c_arg, |
| 2391 | .rpc_resp = &data->c_res, |
| 2392 | .rpc_cred = data->owner->so_cred, |
| 2393 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2394 | struct rpc_task_setup task_setup_data = { |
| 2395 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2396 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2397 | .callback_ops = &nfs4_open_confirm_ops, |
| 2398 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2399 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2400 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2401 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | int status; |
| 2403 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2404 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2405 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2406 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2407 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2408 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2409 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2410 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2411 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2412 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2413 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2414 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2415 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2416 | smp_wmb(); |
| 2417 | } else |
| 2418 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2419 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | return status; |
| 2421 | } |
| 2422 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2423 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2425 | struct nfs4_opendata *data = calldata; |
| 2426 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2427 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2428 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2429 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2430 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2431 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2432 | /* |
| 2433 | * Check if we still need to send an OPEN call, or if we can use |
| 2434 | * a delegation instead. |
| 2435 | */ |
| 2436 | if (data->state != NULL) { |
| 2437 | struct nfs_delegation *delegation; |
| 2438 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2439 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2440 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2441 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2442 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 2443 | delegation = nfs4_get_valid_delegation(data->state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2444 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2445 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2446 | rcu_read_unlock(); |
| 2447 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2448 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2449 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2450 | switch (claim) { |
| 2451 | default: |
| 2452 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2453 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2454 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2455 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2456 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2457 | fallthrough; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2458 | case NFS4_OPEN_CLAIM_FH: |
| 2459 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2460 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2461 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2462 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2463 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2464 | &data->o_res.seq_res, |
| 2465 | task) != 0) |
| 2466 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2467 | |
| 2468 | /* Set the create mode (note dependency on the session type) */ |
| 2469 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2470 | if (data->o_arg.open_flags & O_EXCL) { |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 2471 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2472 | if (clp->cl_mvops->minor_version == 0) { |
| 2473 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2474 | /* don't put an ACCESS op in OPEN compound if O_EXCL, |
| 2475 | * because ACCESS will return permission denied for |
| 2476 | * all bits until close */ |
| 2477 | data->o_res.access_request = data->o_arg.access = 0; |
| 2478 | } else if (nfs4_has_persistent_session(clp)) |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2479 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2480 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2481 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2482 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2483 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2484 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2485 | out_no_action: |
| 2486 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2487 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2488 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2489 | } |
| 2490 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2491 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2492 | { |
| 2493 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2495 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2496 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2497 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2498 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2499 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2500 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2501 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2502 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2503 | case S_IFREG: |
| 2504 | break; |
| 2505 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2506 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2507 | break; |
| 2508 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2509 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2510 | break; |
| 2511 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2512 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2513 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2514 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2515 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2516 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2517 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2518 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2519 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2520 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2521 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2522 | static void nfs4_open_release(void *calldata) |
| 2523 | { |
| 2524 | struct nfs4_opendata *data = calldata; |
| 2525 | struct nfs4_state *state = NULL; |
| 2526 | |
| 2527 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2528 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2529 | goto out_free; |
| 2530 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2531 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2532 | goto out_free; |
| 2533 | /* In case we need an open_confirm, no cleanup! */ |
| 2534 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2535 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2536 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2537 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2538 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2539 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2540 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2544 | .rpc_call_prepare = nfs4_open_prepare, |
| 2545 | .rpc_call_done = nfs4_open_done, |
| 2546 | .rpc_release = nfs4_open_release, |
| 2547 | }; |
| 2548 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2549 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2550 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2551 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2552 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2553 | struct nfs_server *server = NFS_SERVER(dir); |
| 2554 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2555 | struct nfs_openres *o_res = &data->o_res; |
| 2556 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2557 | struct rpc_message msg = { |
| 2558 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2559 | .rpc_argp = o_arg, |
| 2560 | .rpc_resp = o_res, |
| 2561 | .rpc_cred = data->owner->so_cred, |
| 2562 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2563 | struct rpc_task_setup task_setup_data = { |
| 2564 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2565 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2566 | .callback_ops = &nfs4_open_ops, |
| 2567 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2568 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2569 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2570 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2571 | int status; |
| 2572 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 2573 | if (server->nfs_client->cl_minorversion) |
| 2574 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
| 2575 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2576 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2577 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2578 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2579 | data->cancelled = false; |
| 2580 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2581 | if (!ctx) { |
| 2582 | 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] | 2583 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2584 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2585 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2586 | 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] | 2587 | pnfs_lgopen_prepare(data, ctx); |
| 2588 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2589 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2590 | if (IS_ERR(task)) |
| 2591 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2592 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2593 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2594 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2595 | smp_wmb(); |
| 2596 | } else |
| 2597 | status = data->rpc_status; |
| 2598 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2599 | |
| 2600 | return status; |
| 2601 | } |
| 2602 | |
| 2603 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2604 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2605 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2606 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2607 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2608 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2609 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2610 | if (status != 0 || !data->rpc_done) |
| 2611 | return status; |
| 2612 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2613 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2614 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2615 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2616 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2617 | |
| 2618 | return status; |
| 2619 | } |
| 2620 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2621 | /* |
| 2622 | * Additional permission checks in order to distinguish between an |
| 2623 | * open for read, and an open for execute. This works around the |
| 2624 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2625 | * the same. |
| 2626 | * Note that in the non-execute case, we want to turn off permission |
| 2627 | * checking if we just created a new file (POSIX open() semantics). |
| 2628 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2629 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2630 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2631 | struct nfs4_state *state, fmode_t fmode, |
| 2632 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2633 | { |
| 2634 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2635 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2636 | |
| 2637 | /* access call failed or for some reason the server doesn't |
| 2638 | * support any access modes -- defer access call until later */ |
| 2639 | if (opendata->o_res.access_supported == 0) |
| 2640 | return 0; |
| 2641 | |
| 2642 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2643 | /* |
| 2644 | * Use openflags to check for exec, because fmode won't |
| 2645 | * always have FMODE_EXEC set when file open for exec. |
| 2646 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2647 | if (openflags & __FMODE_EXEC) { |
| 2648 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2649 | if (S_ISDIR(state->inode->i_mode)) |
| 2650 | mask = NFS4_ACCESS_LOOKUP; |
| 2651 | else |
| 2652 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2653 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2654 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2655 | |
| 2656 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2657 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2658 | nfs_access_add_cache(state->inode, &cache); |
| 2659 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2660 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2661 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2662 | return 0; |
| 2663 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2664 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2665 | } |
| 2666 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2667 | /* |
| 2668 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2669 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2670 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2671 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2672 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2673 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2674 | struct nfs_server *server = NFS_SERVER(dir); |
| 2675 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2676 | struct nfs_openres *o_res = &data->o_res; |
| 2677 | int status; |
| 2678 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2679 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2680 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2681 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2682 | if (status != 0) { |
| 2683 | if (status == -NFS4ERR_BADNAME && |
| 2684 | !(o_arg->open_flags & O_CREAT)) |
| 2685 | return -ENOENT; |
| 2686 | return status; |
| 2687 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2688 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2689 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2690 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2691 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2692 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2693 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2694 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2695 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2696 | if (data->file_created || |
| 2697 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 2698 | nfs4_update_changeattr(dir, &o_res->cinfo, |
| 2699 | o_res->f_attr->time_start, |
| 2700 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2701 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2702 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2703 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2705 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2707 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2709 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2710 | nfs4_sequence_free_slot(&o_res->seq_res); |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame^] | 2711 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2712 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2713 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | /* |
| 2717 | * OPEN_EXPIRED: |
| 2718 | * reclaim state on the server after a network partition. |
| 2719 | * Assumes caller holds the appropriate lock |
| 2720 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2721 | 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] | 2722 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2723 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2724 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2726 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2727 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2728 | if (IS_ERR(opendata)) |
| 2729 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2730 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2731 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2732 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2733 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2734 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2737 | 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] | 2738 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2739 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2740 | struct nfs4_exception exception = { }; |
| 2741 | int err; |
| 2742 | |
| 2743 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2744 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2745 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2746 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2747 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2748 | switch (err) { |
| 2749 | default: |
| 2750 | goto out; |
| 2751 | case -NFS4ERR_GRACE: |
| 2752 | case -NFS4ERR_DELAY: |
| 2753 | nfs4_handle_exception(server, err, &exception); |
| 2754 | err = 0; |
| 2755 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2756 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2757 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2758 | return err; |
| 2759 | } |
| 2760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2762 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2764 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2766 | ctx = nfs4_state_find_open_context(state); |
| 2767 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2768 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2769 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2770 | put_nfs_open_context(ctx); |
| 2771 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | } |
| 2773 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2774 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2775 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2776 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2777 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2778 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2782 | { |
| 2783 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2784 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2788 | { |
| 2789 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2790 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2791 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2792 | return nfs4_open_expired(sp, state); |
| 2793 | } |
| 2794 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2795 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2796 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2797 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2798 | { |
| 2799 | return -NFS4ERR_BAD_STATEID; |
| 2800 | } |
| 2801 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2802 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2803 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2804 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2805 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2806 | { |
| 2807 | int status; |
| 2808 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2809 | switch (stateid->type) { |
| 2810 | default: |
| 2811 | break; |
| 2812 | case NFS4_INVALID_STATEID_TYPE: |
| 2813 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2814 | return -NFS4ERR_BAD_STATEID; |
| 2815 | case NFS4_REVOKED_STATEID_TYPE: |
| 2816 | goto out_free; |
| 2817 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2818 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2819 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2820 | switch (status) { |
| 2821 | case -NFS4ERR_EXPIRED: |
| 2822 | case -NFS4ERR_ADMIN_REVOKED: |
| 2823 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2824 | break; |
| 2825 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2826 | return status; |
| 2827 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2828 | out_free: |
| 2829 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2830 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2831 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2834 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2835 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2836 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2837 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2838 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2839 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2840 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2841 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2842 | /* Get the delegation credential for use by test/free_stateid */ |
| 2843 | rcu_read_lock(); |
| 2844 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2845 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2846 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2847 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2848 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2849 | } |
| 2850 | |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2851 | spin_lock(&delegation->lock); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2852 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2853 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2854 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2855 | &delegation->flags)) { |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2856 | spin_unlock(&delegation->lock); |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2857 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2858 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2859 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2860 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2861 | if (delegation->cred) |
| 2862 | cred = get_cred(delegation->cred); |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2863 | spin_unlock(&delegation->lock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2864 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2865 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2866 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2867 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2868 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2869 | else |
| 2870 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2871 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2872 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2873 | return ret; |
| 2874 | } |
| 2875 | |
| 2876 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2877 | { |
| 2878 | nfs4_stateid tmp; |
| 2879 | |
| 2880 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2881 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2882 | &tmp, NULL) && |
| 2883 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2884 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2885 | else |
| 2886 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2890 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2891 | * |
| 2892 | * @state: NFSv4 state for an inode |
| 2893 | * |
| 2894 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2895 | * Otherwise a negative NFS4ERR value is returned. |
| 2896 | */ |
| 2897 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2898 | { |
| 2899 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2900 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2901 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2902 | |
| 2903 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2904 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2905 | |
| 2906 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2907 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2908 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2909 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2910 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2911 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2912 | spin_unlock(&state->state_lock); |
| 2913 | |
| 2914 | nfs4_put_lock_state(prev); |
| 2915 | prev = lsp; |
| 2916 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2917 | status = nfs41_test_and_free_expired_stateid(server, |
| 2918 | &lsp->ls_stateid, |
| 2919 | cred); |
| 2920 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2921 | if (status == -NFS4ERR_EXPIRED || |
| 2922 | status == -NFS4ERR_BAD_STATEID) { |
| 2923 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2924 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2925 | if (!recover_lost_locks) |
| 2926 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2927 | } else if (status != NFS_OK) { |
| 2928 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2929 | nfs4_put_lock_state(prev); |
| 2930 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2931 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2932 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2933 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2934 | } |
| 2935 | spin_unlock(&state->state_lock); |
| 2936 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2937 | out: |
| 2938 | return ret; |
| 2939 | } |
| 2940 | |
| 2941 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2942 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2943 | * |
| 2944 | * @state: NFSv4 state for an inode |
| 2945 | * |
| 2946 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2947 | * Otherwise a negative NFS4ERR value is returned. |
| 2948 | */ |
| 2949 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2950 | { |
| 2951 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2952 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2953 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2954 | int status; |
| 2955 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2956 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2957 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2958 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2959 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2960 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2961 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2962 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2963 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2964 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2965 | if (nfs_open_stateid_recover_openmode(state)) |
| 2966 | return -NFS4ERR_OPENMODE; |
| 2967 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2971 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2972 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2973 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2974 | status = nfs41_check_delegation_stateid(state); |
| 2975 | if (status != NFS_OK) |
| 2976 | return status; |
| 2977 | nfs41_delegation_recover_stateid(state); |
| 2978 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2979 | status = nfs41_check_expired_locks(state); |
| 2980 | if (status != NFS_OK) |
| 2981 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2982 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2983 | if (status != NFS_OK) |
| 2984 | status = nfs4_open_expired(sp, state); |
| 2985 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2986 | } |
| 2987 | #endif |
| 2988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2990 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2991 | * fields corresponding to attributes that were used to store the verifier. |
| 2992 | * Make sure we clobber those fields in the later setattr call |
| 2993 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2994 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2995 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2996 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2997 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2998 | __u32 attrset[3]; |
| 2999 | unsigned ret; |
| 3000 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3001 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3002 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 3003 | attrset[i] = opendata->o_res.attrset[i]; |
| 3004 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 3005 | attrset[i] &= ~bitmask[i]; |
| 3006 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3007 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3008 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 3009 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3010 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3011 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 3012 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 3013 | ret |= ATTR_ATIME_SET; |
| 3014 | else |
| 3015 | ret |= ATTR_ATIME; |
| 3016 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3017 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3018 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 3019 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 3020 | ret |= ATTR_MTIME_SET; |
| 3021 | else |
| 3022 | ret |= ATTR_MTIME; |
| 3023 | } |
| 3024 | |
| 3025 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3026 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3027 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3028 | } |
| 3029 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3030 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3031 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3032 | { |
| 3033 | struct nfs4_state_owner *sp = opendata->owner; |
| 3034 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3035 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3036 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3037 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3038 | struct inode *dir = d_inode(opendata->dir); |
| 3039 | unsigned long dir_verifier; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3040 | unsigned int seq; |
| 3041 | int ret; |
| 3042 | |
| 3043 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3044 | dir_verifier = nfs_save_change_attribute(dir); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3045 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 3046 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 3047 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3048 | goto out; |
| 3049 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 3050 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3051 | ret = PTR_ERR(state); |
| 3052 | if (IS_ERR(state)) |
| 3053 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 3054 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3055 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 3056 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 3057 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 3058 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3059 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3060 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3061 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3062 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3063 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3064 | alias = d_exact_alias(dentry, state->inode); |
| 3065 | if (!alias) |
| 3066 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 3067 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 3068 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3069 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3070 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3071 | } |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | switch(opendata->o_arg.claim) { |
| 3075 | default: |
| 3076 | break; |
| 3077 | case NFS4_OPEN_CLAIM_NULL: |
| 3078 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 3079 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 3080 | if (!opendata->rpc_done) |
| 3081 | break; |
| 3082 | if (opendata->o_res.delegation_type != 0) |
| 3083 | dir_verifier = nfs_save_change_attribute(dir); |
| 3084 | nfs_set_verifier(dentry, dir_verifier); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3085 | } |
| 3086 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 3087 | /* Parse layoutget results before we check for access */ |
| 3088 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 3089 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3090 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 3091 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3092 | if (ret != 0) |
| 3093 | goto out; |
| 3094 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3095 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3096 | nfs_inode_attach_open_context(ctx); |
| 3097 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3098 | nfs4_schedule_stateid_recovery(server, state); |
| 3099 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3100 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3101 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3102 | if (!opendata->cancelled) |
| 3103 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3104 | return ret; |
| 3105 | } |
| 3106 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3107 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3108 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3110 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3111 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3112 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3113 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3114 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | { |
| 3116 | struct nfs4_state_owner *sp; |
| 3117 | struct nfs4_state *state = NULL; |
| 3118 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3119 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3120 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3121 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3122 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3123 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3124 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3125 | struct iattr *sattr = c->sattr; |
| 3126 | struct nfs4_label *label = c->label; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3127 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | |
| 3129 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3131 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3132 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3134 | goto out_err; |
| 3135 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3136 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3137 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3138 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3139 | if (d_really_is_positive(dentry)) |
| 3140 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3141 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3142 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3143 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3144 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3145 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3146 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3147 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3149 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3150 | if (!opendata->f_attr.mdsthreshold) { |
| 3151 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3152 | if (!opendata->f_attr.mdsthreshold) |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3153 | goto err_opendata_put; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3154 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3155 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3156 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3157 | if (d_really_is_positive(dentry)) |
| 3158 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3159 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3160 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3161 | if (status != 0) |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3162 | goto err_opendata_put; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3163 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3164 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3165 | 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] | 3166 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3167 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3168 | /* |
| 3169 | * send create attributes which was not set by open |
| 3170 | * with an extra setattr. |
| 3171 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3172 | if (attrs || label) { |
| 3173 | unsigned ia_old = sattr->ia_valid; |
| 3174 | |
| 3175 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3176 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3177 | status = nfs4_do_setattr(state->inode, cred, |
| 3178 | opendata->o_res.f_attr, sattr, |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3179 | ctx, label, opendata->o_res.f_attr->label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3180 | if (status == 0) { |
| 3181 | nfs_setattr_update_inode(state->inode, sattr, |
| 3182 | opendata->o_res.f_attr); |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3183 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, |
| 3184 | opendata->o_res.f_attr->label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3185 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3186 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3187 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3188 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3189 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3190 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3191 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3192 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3193 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3194 | opendata->f_attr.mdsthreshold = NULL; |
| 3195 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3196 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3197 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3200 | err_opendata_put: |
| 3201 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3202 | err_put_state_owner: |
| 3203 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | return status; |
| 3206 | } |
| 3207 | |
| 3208 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3209 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3210 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3211 | int flags, |
| 3212 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3213 | struct nfs4_label *label, |
| 3214 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3216 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3217 | struct nfs4_exception exception = { |
| 3218 | .interruptible = true, |
| 3219 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3221 | struct nfs4_open_createattrs c = { |
| 3222 | .label = label, |
| 3223 | .sattr = sattr, |
| 3224 | .verf = { |
| 3225 | [0] = (__u32)jiffies, |
| 3226 | [1] = (__u32)current->pid, |
| 3227 | }, |
| 3228 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | int status; |
| 3230 | |
| 3231 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3232 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3233 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3234 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | if (status == 0) |
| 3236 | break; |
| 3237 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3238 | * book-keeping w.r.t. state-changing operations |
| 3239 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3240 | * It is actually a sign of a bug on the client or on the server. |
| 3241 | * |
| 3242 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3243 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | * have unhashed the old state_owner for us, and that we can |
| 3245 | * therefore safely retry using a new one. We should still warn |
| 3246 | * the user though... |
| 3247 | */ |
| 3248 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3249 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3250 | " returned a bad sequence-id error!\n", |
| 3251 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | exception.retry = 1; |
| 3253 | continue; |
| 3254 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3255 | /* |
| 3256 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3257 | * state before it received the OPEN_CONFIRM. |
| 3258 | * Recover by retrying the request as per the discussion |
| 3259 | * on Page 181 of RFC3530. |
| 3260 | */ |
| 3261 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3262 | exception.retry = 1; |
| 3263 | continue; |
| 3264 | } |
Robert Milkowski | 924491f | 2020-01-28 08:37:47 +0000 | [diff] [blame] | 3265 | if (status == -NFS4ERR_EXPIRED) { |
| 3266 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 3267 | exception.retry = 1; |
| 3268 | continue; |
| 3269 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3270 | if (status == -EAGAIN) { |
| 3271 | /* We must have found a delegation */ |
| 3272 | exception.retry = 1; |
| 3273 | continue; |
| 3274 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3275 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3276 | continue; |
| 3277 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | status, &exception)); |
| 3279 | } while (exception.retry); |
| 3280 | return res; |
| 3281 | } |
| 3282 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3283 | static int _nfs4_do_setattr(struct inode *inode, |
| 3284 | struct nfs_setattrargs *arg, |
| 3285 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3286 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3287 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3288 | { |
| 3289 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3290 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3291 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3292 | .rpc_argp = arg, |
| 3293 | .rpc_resp = res, |
| 3294 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3295 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3296 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3297 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3298 | bool truncate; |
| 3299 | int status; |
| 3300 | |
| 3301 | nfs_fattr_init(res->fattr); |
| 3302 | |
| 3303 | /* Servers should only apply open mode checks for file size changes */ |
| 3304 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3305 | if (!truncate) { |
| 3306 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3307 | goto zero_stateid; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3308 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3309 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3310 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3311 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3312 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3313 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3314 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3315 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3316 | l_ctx = nfs_get_lock_context(ctx); |
| 3317 | if (IS_ERR(l_ctx)) |
| 3318 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3319 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3320 | &arg->stateid, &delegation_cred); |
| 3321 | nfs_put_lock_context(l_ctx); |
| 3322 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3323 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3324 | else if (status == -EAGAIN) |
| 3325 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3326 | } else { |
| 3327 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3328 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3329 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3330 | if (delegation_cred) |
| 3331 | msg.rpc_cred = delegation_cred; |
| 3332 | |
| 3333 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3334 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3335 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3336 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3337 | renew_lease(server, timestamp); |
| 3338 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3339 | return status; |
| 3340 | } |
| 3341 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3342 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3343 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3344 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3345 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3347 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3348 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3349 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3350 | struct nfs_setattrargs arg = { |
| 3351 | .fh = NFS_FH(inode), |
| 3352 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3354 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3355 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3356 | }; |
| 3357 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3359 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3361 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3362 | struct nfs4_exception exception = { |
| 3363 | .state = state, |
| 3364 | .inode = inode, |
| 3365 | .stateid = &arg.stateid, |
| 3366 | }; |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3367 | unsigned long adjust_flags = NFS_INO_INVALID_CHANGE; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3368 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 3370 | if (sattr->ia_valid & (ATTR_MODE | ATTR_KILL_SUID | ATTR_KILL_SGID)) |
| 3371 | adjust_flags |= NFS_INO_INVALID_MODE; |
| 3372 | if (sattr->ia_valid & (ATTR_UID | ATTR_GID)) |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3373 | adjust_flags |= NFS_INO_INVALID_OTHER; |
| 3374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | do { |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3376 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, olabel), |
| 3377 | inode, adjust_flags); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3378 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3379 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3380 | switch (err) { |
| 3381 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3382 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3383 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3384 | "applying open mode checks to " |
| 3385 | "a SETATTR that is not " |
| 3386 | "changing file size.\n", |
| 3387 | server->nfs_client->cl_hostname); |
| 3388 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3389 | if (state && !(state->state & FMODE_WRITE)) { |
| 3390 | err = -EBADF; |
| 3391 | if (sattr->ia_valid & ATTR_OPEN) |
| 3392 | err = -EACCES; |
| 3393 | goto out; |
| 3394 | } |
| 3395 | } |
| 3396 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3398 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | return err; |
| 3400 | } |
| 3401 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3402 | static bool |
| 3403 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3404 | { |
| 3405 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3406 | return false; |
| 3407 | |
| 3408 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3409 | } |
| 3410 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3411 | /* |
| 3412 | * Update the seqid of an open stateid |
| 3413 | */ |
| 3414 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3415 | struct nfs4_state *state) |
| 3416 | { |
| 3417 | __be32 seqid_open; |
| 3418 | u32 dst_seqid; |
| 3419 | int seq; |
| 3420 | |
| 3421 | for (;;) { |
| 3422 | if (!nfs4_valid_open_stateid(state)) |
| 3423 | break; |
| 3424 | seq = read_seqbegin(&state->seqlock); |
| 3425 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3426 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3427 | if (read_seqretry(&state->seqlock, seq)) |
| 3428 | continue; |
| 3429 | break; |
| 3430 | } |
| 3431 | seqid_open = state->open_stateid.seqid; |
| 3432 | if (read_seqretry(&state->seqlock, seq)) |
| 3433 | continue; |
| 3434 | |
| 3435 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3436 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3437 | dst->seqid = seqid_open; |
| 3438 | break; |
| 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | /* |
| 3443 | * Update the seqid of an open stateid after receiving |
| 3444 | * NFS4ERR_OLD_STATEID |
| 3445 | */ |
| 3446 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3447 | struct nfs4_state *state) |
| 3448 | { |
| 3449 | __be32 seqid_open; |
| 3450 | u32 dst_seqid; |
| 3451 | bool ret; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3452 | int seq, status = -EAGAIN; |
| 3453 | DEFINE_WAIT(wait); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3454 | |
| 3455 | for (;;) { |
| 3456 | ret = false; |
| 3457 | if (!nfs4_valid_open_stateid(state)) |
| 3458 | break; |
| 3459 | seq = read_seqbegin(&state->seqlock); |
| 3460 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3461 | if (read_seqretry(&state->seqlock, seq)) |
| 3462 | continue; |
| 3463 | break; |
| 3464 | } |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3465 | |
| 3466 | write_seqlock(&state->seqlock); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3467 | seqid_open = state->open_stateid.seqid; |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3468 | |
| 3469 | dst_seqid = be32_to_cpu(dst->seqid); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3470 | |
| 3471 | /* Did another OPEN bump the state's seqid? try again: */ |
| 3472 | if ((s32)(be32_to_cpu(seqid_open) - dst_seqid) > 0) { |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3473 | dst->seqid = seqid_open; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3474 | write_sequnlock(&state->seqlock); |
| 3475 | ret = true; |
| 3476 | break; |
| 3477 | } |
| 3478 | |
| 3479 | /* server says we're behind but we haven't seen the update yet */ |
| 3480 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 3481 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 3482 | write_sequnlock(&state->seqlock); |
| 3483 | trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); |
| 3484 | |
zhouchuangao | bb00238 | 2021-05-09 19:34:37 -0700 | [diff] [blame] | 3485 | if (fatal_signal_pending(current)) |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3486 | status = -EINTR; |
| 3487 | else |
| 3488 | if (schedule_timeout(5*HZ) != 0) |
| 3489 | status = 0; |
| 3490 | |
| 3491 | finish_wait(&state->waitq, &wait); |
| 3492 | |
| 3493 | if (!status) |
| 3494 | continue; |
| 3495 | if (status == -EINTR) |
| 3496 | break; |
| 3497 | |
| 3498 | /* we slept the whole 5 seconds, we must have lost a seqid */ |
| 3499 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3500 | ret = true; |
| 3501 | break; |
| 3502 | } |
| 3503 | |
| 3504 | return ret; |
| 3505 | } |
| 3506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | struct nfs4_closedata { |
| 3508 | struct inode *inode; |
| 3509 | struct nfs4_state *state; |
| 3510 | struct nfs_closeargs arg; |
| 3511 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3512 | struct { |
| 3513 | struct nfs4_layoutreturn_args arg; |
| 3514 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3515 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3516 | u32 roc_barrier; |
| 3517 | bool roc; |
| 3518 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3519 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3520 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | }; |
| 3522 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3523 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3524 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3525 | struct nfs4_closedata *calldata = data; |
| 3526 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3527 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3528 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3529 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3530 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3531 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3532 | nfs4_put_open_state(calldata->state); |
| 3533 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3534 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3535 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3536 | kfree(calldata); |
| 3537 | } |
| 3538 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3539 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3541 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3544 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3545 | struct nfs4_exception exception = { |
| 3546 | .state = state, |
| 3547 | .inode = calldata->inode, |
| 3548 | .stateid = &calldata->arg.stateid, |
| 3549 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3551 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3552 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3553 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3554 | |
| 3555 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 3556 | if (pnfs_roc_done(task, &calldata->arg.lr_args, &calldata->res.lr_res, |
| 3557 | &calldata->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3558 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3559 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3560 | /* 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] | 3561 | * the state_owner. we keep this around to process errors |
| 3562 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | switch (task->tk_status) { |
| 3564 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3565 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3566 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3567 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3568 | case -NFS4ERR_ACCESS: |
| 3569 | if (calldata->arg.bitmask != NULL) { |
| 3570 | calldata->arg.bitmask = NULL; |
| 3571 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3572 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3573 | |
| 3574 | } |
| 3575 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3576 | case -NFS4ERR_OLD_STATEID: |
| 3577 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3578 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3579 | state)) |
| 3580 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3581 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3582 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3584 | case -NFS4ERR_EXPIRED: |
| 3585 | nfs4_free_revoked_stateid(server, |
| 3586 | &calldata->arg.stateid, |
| 3587 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3588 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3589 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3590 | if (calldata->arg.fmode == 0) |
| 3591 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3592 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3594 | task->tk_status = nfs4_async_handle_exception(task, |
| 3595 | server, task->tk_status, &exception); |
| 3596 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3597 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3599 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3600 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3601 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3602 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3603 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3604 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 3605 | dprintk("%s: ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3606 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3607 | out_restart: |
| 3608 | task->tk_status = 0; |
| 3609 | rpc_restart_call_prepare(task); |
| 3610 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | } |
| 3612 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3613 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3615 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3616 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3617 | struct inode *inode = calldata->inode; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3618 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3619 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3620 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3621 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3622 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3623 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3624 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3625 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3626 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3627 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3628 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3629 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3630 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3631 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3632 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3633 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3634 | if (state->n_rdonly == 0) |
| 3635 | call_close |= is_rdonly; |
| 3636 | else if (is_rdonly) |
| 3637 | calldata->arg.fmode |= FMODE_READ; |
| 3638 | if (state->n_wronly == 0) |
| 3639 | call_close |= is_wronly; |
| 3640 | else if (is_wronly) |
| 3641 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3642 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3643 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3644 | } else if (is_rdwr) |
| 3645 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3646 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3647 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3648 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3649 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3650 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3651 | |
| 3652 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3653 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3654 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3655 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3656 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3657 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3658 | nfs_release_seqid(calldata->arg.seqid); |
| 3659 | goto out_wait; |
| 3660 | } |
| 3661 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3662 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3663 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3664 | calldata->arg.lr_args = NULL; |
| 3665 | calldata->res.lr_res = NULL; |
| 3666 | } |
| 3667 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3668 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3669 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3670 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3671 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3672 | /* Close-to-open cache consistency revalidation */ |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3673 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3674 | nfs4_bitmask_set(calldata->arg.bitmask_store, |
| 3675 | server->cache_consistency_bitmask, |
| 3676 | inode, server, NULL); |
| 3677 | calldata->arg.bitmask = calldata->arg.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3678 | } else |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3679 | calldata->arg.bitmask = NULL; |
| 3680 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3681 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3682 | calldata->arg.share_access = |
| 3683 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3684 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3685 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3686 | if (calldata->res.fattr == NULL) |
| 3687 | calldata->arg.bitmask = NULL; |
| 3688 | else if (calldata->arg.bitmask == NULL) |
| 3689 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3690 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3691 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3692 | &calldata->arg.seq_args, |
| 3693 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3694 | task) != 0) |
| 3695 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3696 | return; |
| 3697 | out_no_action: |
| 3698 | task->tk_action = NULL; |
| 3699 | out_wait: |
| 3700 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3703 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3704 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3705 | .rpc_call_done = nfs4_close_done, |
| 3706 | .rpc_release = nfs4_free_closedata, |
| 3707 | }; |
| 3708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | /* |
| 3710 | * It is possible for data to be read/written from a mem-mapped file |
| 3711 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3712 | * This means that we can't safely call nfsv4 close on a file until |
| 3713 | * the inode is cleared. This in turn means that we are not good |
| 3714 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3715 | * share state even when we are done with one of the three share |
| 3716 | * stateid's in the inode. |
| 3717 | * |
| 3718 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3719 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3720 | 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] | 3721 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3722 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3723 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3725 | struct nfs4_state_owner *sp = state->owner; |
| 3726 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3727 | struct rpc_message msg = { |
| 3728 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3729 | .rpc_cred = state->owner->so_cred, |
| 3730 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3731 | struct rpc_task_setup task_setup_data = { |
| 3732 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3733 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3734 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3735 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 3736 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3737 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3738 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 3740 | if (server->nfs_client->cl_minorversion) |
| 3741 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
| 3742 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3743 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3744 | &task_setup_data.rpc_client, &msg); |
| 3745 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3746 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3748 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3749 | 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] | 3750 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3752 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3753 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3754 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3756 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3757 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3758 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3759 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3760 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3761 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3762 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3763 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3764 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3765 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3766 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3767 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3768 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3769 | if (calldata->lr.roc) { |
| 3770 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3771 | calldata->res.lr_res = &calldata->lr.res; |
| 3772 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3773 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3774 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3775 | msg.rpc_argp = &calldata->arg; |
| 3776 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3777 | task_setup_data.callback_data = calldata; |
| 3778 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3779 | if (IS_ERR(task)) |
| 3780 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3781 | status = 0; |
| 3782 | if (wait) |
| 3783 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3784 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3785 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3786 | out_free_calldata: |
| 3787 | kfree(calldata); |
| 3788 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3789 | nfs4_put_open_state(state); |
| 3790 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3791 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3794 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3795 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3796 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3799 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3800 | |
| 3801 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3803 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3804 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3805 | |
| 3806 | nfs4_label_release_security(label); |
| 3807 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3808 | if (IS_ERR(state)) |
| 3809 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3810 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3813 | 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] | 3814 | { |
| 3815 | if (ctx->state == NULL) |
| 3816 | return; |
| 3817 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3818 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3819 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3820 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3823 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3824 | #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] | 3825 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3828 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3829 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3830 | struct nfs4_server_caps_arg args = { |
| 3831 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3832 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3833 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | struct nfs4_server_caps_res res = {}; |
| 3835 | struct rpc_message msg = { |
| 3836 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3837 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | .rpc_resp = &res, |
| 3839 | }; |
| 3840 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3841 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3843 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3844 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3845 | FATTR4_WORD0_LINK_SUPPORT | |
| 3846 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3847 | FATTR4_WORD0_ACLSUPPORT; |
| 3848 | if (minorversion) |
| 3849 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3850 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3851 | 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] | 3852 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3853 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3854 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3855 | case 0: |
| 3856 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3857 | res.attr_bitmask[2] = 0; |
| 3858 | break; |
| 3859 | case 1: |
| 3860 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3861 | break; |
| 3862 | case 2: |
| 3863 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | ce62b11 | 2018-03-05 15:01:18 -0500 | [diff] [blame] | 3866 | server->caps &= ~(NFS_CAP_ACLS | NFS_CAP_HARDLINKS | |
| 3867 | NFS_CAP_SYMLINKS| NFS_CAP_SECURITY_LABEL); |
| 3868 | server->fattr_valid = NFS_ATTR_FATTR_V4; |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3869 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3870 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | server->caps |= NFS_CAP_ACLS; |
| 3872 | if (res.has_links != 0) |
| 3873 | server->caps |= NFS_CAP_HARDLINKS; |
| 3874 | if (res.has_symlinks != 0) |
| 3875 | server->caps |= NFS_CAP_SYMLINKS; |
Scott Mayhew | 0b4f132 | 2021-06-02 13:13:11 -0400 | [diff] [blame] | 3876 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3877 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3878 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3879 | #endif |
Trond Myklebust | ce62b11 | 2018-03-05 15:01:18 -0500 | [diff] [blame] | 3880 | if (!(res.attr_bitmask[0] & FATTR4_WORD0_FILEID)) |
| 3881 | server->fattr_valid &= ~NFS_ATTR_FATTR_FILEID; |
| 3882 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_MODE)) |
| 3883 | server->fattr_valid &= ~NFS_ATTR_FATTR_MODE; |
| 3884 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)) |
| 3885 | server->fattr_valid &= ~NFS_ATTR_FATTR_NLINK; |
| 3886 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_OWNER)) |
| 3887 | server->fattr_valid &= ~(NFS_ATTR_FATTR_OWNER | |
| 3888 | NFS_ATTR_FATTR_OWNER_NAME); |
| 3889 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)) |
| 3890 | server->fattr_valid &= ~(NFS_ATTR_FATTR_GROUP | |
| 3891 | NFS_ATTR_FATTR_GROUP_NAME); |
| 3892 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_SPACE_USED)) |
| 3893 | server->fattr_valid &= ~NFS_ATTR_FATTR_SPACE_USED; |
| 3894 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)) |
| 3895 | server->fattr_valid &= ~NFS_ATTR_FATTR_ATIME; |
| 3896 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)) |
| 3897 | server->fattr_valid &= ~NFS_ATTR_FATTR_CTIME; |
| 3898 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)) |
| 3899 | server->fattr_valid &= ~NFS_ATTR_FATTR_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3900 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3901 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3902 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3903 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3904 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3905 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3906 | 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] | 3907 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3908 | |
| 3909 | /* Avoid a regression due to buggy server */ |
| 3910 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3911 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3912 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3913 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3916 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | return status; |
| 3920 | } |
| 3921 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3922 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3924 | struct nfs4_exception exception = { |
| 3925 | .interruptible = true, |
| 3926 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | int err; |
Anna Schumaker | 01dde76 | 2021-10-14 13:55:04 -0400 | [diff] [blame] | 3928 | |
| 3929 | nfs4_server_set_init_caps(server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | do { |
| 3931 | err = nfs4_handle_exception(server, |
| 3932 | _nfs4_server_capabilities(server, fhandle), |
| 3933 | &exception); |
| 3934 | } while (exception.retry); |
| 3935 | return err; |
| 3936 | } |
| 3937 | |
| 3938 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3939 | struct nfs_fsinfo *info) |
| 3940 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3941 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3943 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | }; |
| 3945 | struct nfs4_lookup_res res = { |
| 3946 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3947 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | .fh = fhandle, |
| 3949 | }; |
| 3950 | struct rpc_message msg = { |
| 3951 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3952 | .rpc_argp = &args, |
| 3953 | .rpc_resp = &res, |
| 3954 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3955 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3956 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3957 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3958 | /* |
| 3959 | * Process the label in the upcoming getfattr |
| 3960 | */ |
| 3961 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3962 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3963 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3964 | 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] | 3965 | } |
| 3966 | |
| 3967 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3968 | struct nfs_fsinfo *info) |
| 3969 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3970 | struct nfs4_exception exception = { |
| 3971 | .interruptible = true, |
| 3972 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | int err; |
| 3974 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3975 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3976 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3977 | switch (err) { |
| 3978 | case 0: |
| 3979 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3980 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3981 | default: |
| 3982 | err = nfs4_handle_exception(server, err, &exception); |
| 3983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3985 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | return err; |
| 3987 | } |
| 3988 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3989 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3990 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3991 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3992 | struct rpc_auth_create_args auth_args = { |
| 3993 | .pseudoflavor = flavor, |
| 3994 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3995 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3996 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3997 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3998 | if (IS_ERR(auth)) |
| 3999 | return -EACCES; |
| 4000 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4001 | } |
| 4002 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4003 | /* |
| 4004 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 4005 | * |
| 4006 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 4007 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 4008 | * |
| 4009 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 4010 | * negative errno value. |
| 4011 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4012 | 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] | 4013 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4015 | /* Per 3530bis 15.33.5 */ |
| 4016 | static const rpc_authflavor_t flav_array[] = { |
| 4017 | RPC_AUTH_GSS_KRB5P, |
| 4018 | RPC_AUTH_GSS_KRB5I, |
| 4019 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 4020 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4021 | RPC_AUTH_NULL, |
| 4022 | }; |
| 4023 | int status = -EPERM; |
| 4024 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 4026 | if (server->auth_info.flavor_len > 0) { |
| 4027 | /* try each flavor specified by user */ |
| 4028 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 4029 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4030 | server->auth_info.flavors[i]); |
| 4031 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4032 | continue; |
| 4033 | break; |
| 4034 | } |
| 4035 | } else { |
| 4036 | /* no flavors specified by user, try default list */ |
| 4037 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 4038 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4039 | flav_array[i]); |
| 4040 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4041 | continue; |
| 4042 | break; |
| 4043 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4044 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4045 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4046 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 4047 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4048 | * to access the mount. It could also mean that we tried to mount |
| 4049 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 4050 | * existing mount programs don't handle -EACCES very well so it should |
| 4051 | * be mapped to -EPERM instead. |
| 4052 | */ |
| 4053 | if (status == -EACCES) |
| 4054 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4055 | return status; |
| 4056 | } |
| 4057 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4058 | /** |
| 4059 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 4060 | * @server: initialized nfs_server handle |
| 4061 | * @fhandle: we fill in the pseudo-fs root file handle |
| 4062 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4063 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4064 | * |
| 4065 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4066 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 4067 | 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] | 4068 | struct nfs_fsinfo *info, |
| 4069 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4070 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4071 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4072 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4073 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4074 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4075 | |
| 4076 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 4077 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 4078 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | if (status == 0) |
| 4081 | status = nfs4_server_capabilities(server, fhandle); |
| 4082 | if (status == 0) |
| 4083 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4084 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 4085 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4088 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 4089 | struct nfs_fsinfo *info) |
| 4090 | { |
| 4091 | int error; |
| 4092 | struct nfs_fattr *fattr = info->fattr; |
| 4093 | |
| 4094 | error = nfs4_server_capabilities(server, mntfh); |
| 4095 | if (error < 0) { |
| 4096 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 4097 | return error; |
| 4098 | } |
| 4099 | |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame^] | 4100 | error = nfs4_proc_getattr(server, mntfh, fattr, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4101 | if (error < 0) { |
| 4102 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4103 | goto out; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4107 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4108 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4109 | |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4110 | out: |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4111 | return error; |
| 4112 | } |
| 4113 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4114 | /* |
| 4115 | * Get locations and (maybe) other attributes of a referral. |
| 4116 | * Note that we'll actually follow the referral later when |
| 4117 | * we detect fsid mismatch in inode revalidation |
| 4118 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4119 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4120 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4121 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4122 | { |
| 4123 | int status = -ENOMEM; |
| 4124 | struct page *page = NULL; |
| 4125 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4126 | |
| 4127 | page = alloc_page(GFP_KERNEL); |
| 4128 | if (page == NULL) |
| 4129 | goto out; |
| 4130 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4131 | if (locations == NULL) |
| 4132 | goto out; |
| 4133 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4134 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4135 | if (status != 0) |
| 4136 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4137 | |
| 4138 | /* |
| 4139 | * If the fsid didn't change, this is a migration event, not a |
| 4140 | * referral. Cause us to drop into the exception handler, which |
| 4141 | * will kick off migration recovery. |
| 4142 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4143 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4144 | dprintk("%s: server did not return a different fsid for" |
| 4145 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4146 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4147 | goto out; |
| 4148 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4149 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4150 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4151 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4152 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4153 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4154 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4155 | out: |
| 4156 | if (page) |
| 4157 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4158 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4159 | return status; |
| 4160 | } |
| 4161 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4162 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame^] | 4163 | struct nfs_fattr *fattr, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4165 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | struct nfs4_getattr_arg args = { |
| 4167 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4168 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | }; |
| 4170 | struct nfs4_getattr_res res = { |
| 4171 | .fattr = fattr, |
| 4172 | .server = server, |
| 4173 | }; |
| 4174 | struct rpc_message msg = { |
| 4175 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4176 | .rpc_argp = &args, |
| 4177 | .rpc_resp = &res, |
| 4178 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4179 | unsigned short task_flags = 0; |
| 4180 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 4181 | if (nfs4_has_session(server->nfs_client)) |
| 4182 | task_flags = RPC_TASK_MOVEABLE; |
| 4183 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4184 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4185 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4186 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4187 | |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame^] | 4188 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label), inode, 0); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4189 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4190 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4191 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4192 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | } |
| 4194 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4195 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame^] | 4196 | struct nfs_fattr *fattr, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4198 | struct nfs4_exception exception = { |
| 4199 | .interruptible = true, |
| 4200 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | int err; |
| 4202 | do { |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame^] | 4203 | err = _nfs4_proc_getattr(server, fhandle, fattr, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4204 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4205 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | &exception); |
| 4207 | } while (exception.retry); |
| 4208 | return err; |
| 4209 | } |
| 4210 | |
| 4211 | /* |
| 4212 | * The file is not closed if it is opened due to the a request to change |
| 4213 | * the size of the file. The open call will not be needed once the |
| 4214 | * VFS layer lookup-intents are implemented. |
| 4215 | * |
| 4216 | * Close is called when the inode is destroyed. |
| 4217 | * If we haven't opened the file for O_WRONLY, we |
| 4218 | * need to in the size_change case to obtain a stateid. |
| 4219 | * |
| 4220 | * Got race? |
| 4221 | * Because OPEN is always done by name in nfsv4, it is |
| 4222 | * possible that we opened a different file by the same |
| 4223 | * name. We can recognize this race condition, but we |
| 4224 | * can't do anything about it besides returning an error. |
| 4225 | * |
| 4226 | * This will be fixed with VFS changes (lookup-intent). |
| 4227 | */ |
| 4228 | static int |
| 4229 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4230 | struct iattr *sattr) |
| 4231 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4232 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4233 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4234 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4235 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | int status; |
| 4237 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4238 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4239 | sattr->ia_valid & ATTR_SIZE && |
| 4240 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4241 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4242 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4243 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4245 | /* Deal with open(O_TRUNC) */ |
| 4246 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4247 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4248 | |
| 4249 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4250 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4251 | return 0; |
| 4252 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4253 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4254 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4255 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4256 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4257 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4258 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4259 | } |
| 4260 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4261 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4262 | if (IS_ERR(label)) |
| 4263 | return PTR_ERR(label); |
| 4264 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4265 | /* Return any delegations if we're going to change ACLs */ |
| 4266 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4267 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4268 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4269 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4270 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4271 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4272 | nfs_setsecurity(inode, fattr, label); |
| 4273 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4274 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | return status; |
| 4276 | } |
| 4277 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4278 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4279 | struct dentry *dentry, struct nfs_fh *fhandle, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4280 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4281 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4282 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4283 | int status; |
| 4284 | struct nfs4_lookup_arg args = { |
| 4285 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4286 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4287 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4288 | }; |
| 4289 | struct nfs4_lookup_res res = { |
| 4290 | .server = server, |
| 4291 | .fattr = fattr, |
| 4292 | .fh = fhandle, |
| 4293 | }; |
| 4294 | struct rpc_message msg = { |
| 4295 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4296 | .rpc_argp = &args, |
| 4297 | .rpc_resp = &res, |
| 4298 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4299 | unsigned short task_flags = 0; |
| 4300 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 4301 | if (server->nfs_client->cl_minorversion) |
| 4302 | task_flags = RPC_TASK_MOVEABLE; |
| 4303 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4304 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4305 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4306 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4307 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4308 | args.bitmask = nfs4_bitmask(server, fattr->label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4309 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4310 | nfs_fattr_init(fattr); |
| 4311 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4312 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4313 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4314 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4315 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | dprintk("NFS reply lookup: %d\n", status); |
| 4317 | return status; |
| 4318 | } |
| 4319 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4320 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4321 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4322 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4323 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4324 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4325 | fattr->nlink = 2; |
| 4326 | } |
| 4327 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4328 | 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] | 4329 | struct dentry *dentry, struct nfs_fh *fhandle, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4330 | struct nfs_fattr *fattr) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4331 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4332 | struct nfs4_exception exception = { |
| 4333 | .interruptible = true, |
| 4334 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4335 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4336 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4337 | int err; |
| 4338 | do { |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4339 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4340 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4341 | switch (err) { |
| 4342 | case -NFS4ERR_BADNAME: |
| 4343 | err = -ENOENT; |
| 4344 | goto out; |
| 4345 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4346 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4347 | if (err == -NFS4ERR_MOVED) |
| 4348 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4349 | goto out; |
| 4350 | case -NFS4ERR_WRONGSEC: |
| 4351 | err = -EPERM; |
| 4352 | if (client != *clnt) |
| 4353 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4354 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4355 | if (IS_ERR(client)) |
| 4356 | return PTR_ERR(client); |
| 4357 | |
| 4358 | exception.retry = 1; |
| 4359 | break; |
| 4360 | default: |
| 4361 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4362 | } |
| 4363 | } while (exception.retry); |
| 4364 | |
| 4365 | out: |
| 4366 | if (err == 0) |
| 4367 | *clnt = client; |
| 4368 | else if (client != *clnt) |
| 4369 | rpc_shutdown_client(client); |
| 4370 | |
| 4371 | return err; |
| 4372 | } |
| 4373 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4374 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4375 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4377 | int status; |
| 4378 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4379 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4380 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4381 | if (client != NFS_CLIENT(dir)) { |
| 4382 | rpc_shutdown_client(client); |
| 4383 | nfs_fixup_secinfo_attributes(fattr); |
| 4384 | } |
| 4385 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | } |
| 4387 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4388 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4389 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4390 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4391 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4392 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4393 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4394 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4395 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4396 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4397 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4398 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4399 | } |
| 4400 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4401 | static int _nfs4_proc_lookupp(struct inode *inode, |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4402 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4403 | { |
| 4404 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4405 | struct nfs_server *server = NFS_SERVER(inode); |
| 4406 | int status; |
| 4407 | struct nfs4_lookupp_arg args = { |
| 4408 | .bitmask = server->attr_bitmask, |
| 4409 | .fh = NFS_FH(inode), |
| 4410 | }; |
| 4411 | struct nfs4_lookupp_res res = { |
| 4412 | .server = server, |
| 4413 | .fattr = fattr, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4414 | .fh = fhandle, |
| 4415 | }; |
| 4416 | struct rpc_message msg = { |
| 4417 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4418 | .rpc_argp = &args, |
| 4419 | .rpc_resp = &res, |
| 4420 | }; |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4421 | unsigned short task_flags = 0; |
| 4422 | |
| 4423 | if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL) |
| 4424 | task_flags |= RPC_TASK_TIMEOUT; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4425 | |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4426 | args.bitmask = nfs4_bitmask(server, fattr->label); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4427 | |
| 4428 | nfs_fattr_init(fattr); |
| 4429 | |
| 4430 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4431 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4432 | &res.seq_res, task_flags); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4433 | dprintk("NFS reply lookupp: %d\n", status); |
| 4434 | return status; |
| 4435 | } |
| 4436 | |
| 4437 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4438 | struct nfs_fattr *fattr) |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4439 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4440 | struct nfs4_exception exception = { |
| 4441 | .interruptible = true, |
| 4442 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4443 | int err; |
| 4444 | do { |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4445 | err = _nfs4_proc_lookupp(inode, fhandle, fattr); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4446 | trace_nfs4_lookupp(inode, err); |
| 4447 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4448 | &exception); |
| 4449 | } while (exception.retry); |
| 4450 | return err; |
| 4451 | } |
| 4452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4454 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4455 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | struct nfs4_accessargs args = { |
| 4457 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4458 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4460 | struct nfs4_accessres res = { |
| 4461 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4462 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | struct rpc_message msg = { |
| 4464 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4465 | .rpc_argp = &args, |
| 4466 | .rpc_resp = &res, |
| 4467 | .rpc_cred = entry->cred, |
| 4468 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4469 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4471 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4472 | res.fattr = nfs_alloc_fattr(); |
| 4473 | if (res.fattr == NULL) |
| 4474 | return -ENOMEM; |
| 4475 | args.bitmask = server->cache_consistency_bitmask; |
| 4476 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4477 | 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] | 4478 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4479 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4480 | if (res.fattr) |
| 4481 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4483 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | return status; |
| 4485 | } |
| 4486 | |
| 4487 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4488 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4489 | struct nfs4_exception exception = { |
| 4490 | .interruptible = true, |
| 4491 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | int err; |
| 4493 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4494 | err = _nfs4_proc_access(inode, entry); |
| 4495 | trace_nfs4_access(inode, err); |
| 4496 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | &exception); |
| 4498 | } while (exception.retry); |
| 4499 | return err; |
| 4500 | } |
| 4501 | |
| 4502 | /* |
| 4503 | * TODO: For the time being, we don't try to get any attributes |
| 4504 | * along with any of the zero-copy operations READ, READDIR, |
| 4505 | * READLINK, WRITE. |
| 4506 | * |
| 4507 | * In the case of the first three, we want to put the GETATTR |
| 4508 | * after the read-type operation -- this is because it is hard |
| 4509 | * to predict the length of a GETATTR response in v4, and thus |
| 4510 | * align the READ data correctly. This means that the GETATTR |
| 4511 | * may end up partially falling into the page cache, and we should |
| 4512 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4513 | * To do this efficiently, we need to know the total length |
| 4514 | * of data received, which doesn't seem to be available outside |
| 4515 | * of the RPC layer. |
| 4516 | * |
| 4517 | * In the case of WRITE, we also want to put the GETATTR after |
| 4518 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4519 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | * |
| 4521 | * Both of these changes to the XDR layer would in fact be quite |
| 4522 | * minor, but I decided to leave them for a subsequent patch. |
| 4523 | */ |
| 4524 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4525 | unsigned int pgbase, unsigned int pglen) |
| 4526 | { |
| 4527 | struct nfs4_readlink args = { |
| 4528 | .fh = NFS_FH(inode), |
| 4529 | .pgbase = pgbase, |
| 4530 | .pglen = pglen, |
| 4531 | .pages = &page, |
| 4532 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4533 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | struct rpc_message msg = { |
| 4535 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4536 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4537 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | }; |
| 4539 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4540 | 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] | 4541 | } |
| 4542 | |
| 4543 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4544 | unsigned int pgbase, unsigned int pglen) |
| 4545 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4546 | struct nfs4_exception exception = { |
| 4547 | .interruptible = true, |
| 4548 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | int err; |
| 4550 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4551 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4552 | trace_nfs4_readlink(inode, err); |
| 4553 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | &exception); |
| 4555 | } while (exception.retry); |
| 4556 | return err; |
| 4557 | } |
| 4558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4560 | * 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] | 4561 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | static int |
| 4563 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4564 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4566 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4567 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4568 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | int status = 0; |
| 4571 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4572 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4573 | if (IS_ERR(ctx)) |
| 4574 | return PTR_ERR(ctx); |
| 4575 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4576 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4577 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4578 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4579 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4580 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | if (IS_ERR(state)) { |
| 4582 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4583 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4586 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4587 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | return status; |
| 4589 | } |
| 4590 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4591 | static int |
| 4592 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4594 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4595 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4597 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4599 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4600 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4601 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4603 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4604 | .rpc_argp = &args, |
| 4605 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4607 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4608 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4609 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4610 | 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] | 4611 | if (status == 0) { |
| 4612 | spin_lock(&dir->i_lock); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4613 | /* Removing a directory decrements nlink in the parent */ |
| 4614 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4615 | nfs4_dec_nlink_locked(dir); |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 4616 | nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, |
| 4617 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4618 | spin_unlock(&dir->i_lock); |
| 4619 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | return status; |
| 4621 | } |
| 4622 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4623 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4624 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4625 | struct nfs4_exception exception = { |
| 4626 | .interruptible = true, |
| 4627 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4628 | struct inode *inode = d_inode(dentry); |
| 4629 | int err; |
| 4630 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4631 | if (inode) { |
| 4632 | if (inode->i_nlink == 1) |
| 4633 | nfs4_inode_return_delegation(inode); |
| 4634 | else |
| 4635 | nfs4_inode_make_writeable(inode); |
| 4636 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4637 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4638 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4639 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4640 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4641 | &exception); |
| 4642 | } while (exception.retry); |
| 4643 | return err; |
| 4644 | } |
| 4645 | |
| 4646 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4648 | struct nfs4_exception exception = { |
| 4649 | .interruptible = true, |
| 4650 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4654 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4655 | trace_nfs4_remove(dir, name, err); |
| 4656 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | &exception); |
| 4658 | } while (exception.retry); |
| 4659 | return err; |
| 4660 | } |
| 4661 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4662 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4663 | struct dentry *dentry, |
| 4664 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4666 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4667 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4669 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4671 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4672 | |
| 4673 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4674 | |
| 4675 | if (inode) |
| 4676 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | } |
| 4678 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4679 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4680 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4681 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4682 | &data->args.seq_args, |
| 4683 | &data->res.seq_res, |
| 4684 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | } |
| 4686 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4687 | 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] | 4688 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4689 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4690 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4691 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4692 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4693 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4694 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4695 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4696 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4697 | if (task->tk_status == 0) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4698 | nfs4_update_changeattr(dir, &res->cinfo, |
| 4699 | res->dir_attr->time_start, |
| 4700 | NFS_INO_INVALID_DATA); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4701 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4702 | } |
| 4703 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4704 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4705 | struct dentry *old_dentry, |
| 4706 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4707 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4708 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4709 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4710 | struct inode *old_inode = d_inode(old_dentry); |
| 4711 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4712 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4713 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4714 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4715 | if (new_inode) |
| 4716 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4717 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4718 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4719 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4720 | } |
| 4721 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4722 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4723 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4724 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4725 | &data->args.seq_args, |
| 4726 | &data->res.seq_res, |
| 4727 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4731 | struct inode *new_dir) |
| 4732 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4733 | struct nfs_renamedata *data = task->tk_calldata; |
| 4734 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4735 | |
| 4736 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4737 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4738 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4739 | return 0; |
| 4740 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4741 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4742 | if (new_dir != old_dir) { |
| 4743 | /* Note: If we moved a directory, nlink will change */ |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4744 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4745 | res->old_fattr->time_start, |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 4746 | NFS_INO_INVALID_NLINK | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4747 | NFS_INO_INVALID_DATA); |
| 4748 | nfs4_update_changeattr(new_dir, &res->new_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4749 | res->new_fattr->time_start, |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 4750 | NFS_INO_INVALID_NLINK | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4751 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4752 | } else |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4753 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4754 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4755 | NFS_INO_INVALID_DATA); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4756 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4757 | return 1; |
| 4758 | } |
| 4759 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4760 | 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] | 4761 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4762 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4763 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | struct nfs4_link_arg arg = { |
| 4765 | .fh = NFS_FH(inode), |
| 4766 | .dir_fh = NFS_FH(dir), |
| 4767 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4768 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4770 | struct nfs4_link_res res = { |
| 4771 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4772 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | struct rpc_message msg = { |
| 4774 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4775 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4776 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4778 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | |
Anna Schumaker | aa7ca3b | 2021-10-22 13:11:03 -0400 | [diff] [blame] | 4780 | res.fattr = nfs_alloc_fattr_with_label(server); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4781 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4782 | goto out; |
| 4783 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4784 | nfs4_inode_make_writeable(inode); |
Anna Schumaker | aa7ca3b | 2021-10-22 13:11:03 -0400 | [diff] [blame] | 4785 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, res.fattr->label), inode, |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 4786 | NFS_INO_INVALID_CHANGE); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4787 | 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] | 4788 | if (!status) { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4789 | nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, |
| 4790 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 1301e42 | 2021-04-01 14:57:56 -0400 | [diff] [blame] | 4791 | nfs4_inc_nlink(inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4792 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4793 | if (!status) |
Anna Schumaker | aa7ca3b | 2021-10-22 13:11:03 -0400 | [diff] [blame] | 4794 | nfs_setsecurity(inode, res.fattr, res.fattr->label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4795 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4796 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4797 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4798 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | return status; |
| 4800 | } |
| 4801 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4802 | 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] | 4803 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4804 | struct nfs4_exception exception = { |
| 4805 | .interruptible = true, |
| 4806 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | int err; |
| 4808 | do { |
| 4809 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4810 | _nfs4_proc_link(inode, dir, name), |
| 4811 | &exception); |
| 4812 | } while (exception.retry); |
| 4813 | return err; |
| 4814 | } |
| 4815 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4816 | struct nfs4_createdata { |
| 4817 | struct rpc_message msg; |
| 4818 | struct nfs4_create_arg arg; |
| 4819 | struct nfs4_create_res res; |
| 4820 | struct nfs_fh fh; |
| 4821 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4822 | }; |
| 4823 | |
| 4824 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4825 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4826 | { |
| 4827 | struct nfs4_createdata *data; |
| 4828 | |
| 4829 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4830 | if (data != NULL) { |
| 4831 | struct nfs_server *server = NFS_SERVER(dir); |
| 4832 | |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4833 | data->fattr.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4834 | if (IS_ERR(data->fattr.label)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4835 | goto out_free; |
| 4836 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4837 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4838 | data->msg.rpc_argp = &data->arg; |
| 4839 | data->msg.rpc_resp = &data->res; |
| 4840 | data->arg.dir_fh = NFS_FH(dir); |
| 4841 | data->arg.server = server; |
| 4842 | data->arg.name = name; |
| 4843 | data->arg.attrs = sattr; |
| 4844 | data->arg.ftype = ftype; |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4845 | data->arg.bitmask = nfs4_bitmask(server, data->fattr.label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4846 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4847 | data->res.server = server; |
| 4848 | data->res.fh = &data->fh; |
| 4849 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4850 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4851 | } |
| 4852 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4853 | out_free: |
| 4854 | kfree(data); |
| 4855 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4859 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4860 | 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] | 4861 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4862 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4863 | spin_lock(&dir->i_lock); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4864 | /* Creating a directory bumps nlink in the parent */ |
| 4865 | if (data->arg.ftype == NF4DIR) |
| 4866 | nfs4_inc_nlink_locked(dir); |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 4867 | nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, |
| 4868 | data->res.fattr->time_start, |
| 4869 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4870 | spin_unlock(&dir->i_lock); |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4871 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.fattr->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4872 | } |
| 4873 | return status; |
| 4874 | } |
| 4875 | |
| 4876 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4877 | { |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4878 | nfs4_label_free(data->fattr.label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4879 | kfree(data); |
| 4880 | } |
| 4881 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4882 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4883 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4884 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4886 | struct nfs4_createdata *data; |
| 4887 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4889 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4890 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4891 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4892 | status = -ENOMEM; |
| 4893 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4894 | if (data == NULL) |
| 4895 | goto out; |
| 4896 | |
| 4897 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4898 | data->arg.u.symlink.pages = &page; |
| 4899 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4900 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4902 | status = nfs4_do_create(dir, dentry, data); |
| 4903 | |
| 4904 | nfs4_free_createdata(data); |
| 4905 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | return status; |
| 4907 | } |
| 4908 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4909 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4910 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4912 | struct nfs4_exception exception = { |
| 4913 | .interruptible = true, |
| 4914 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4915 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4917 | |
| 4918 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4921 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4922 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4923 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | &exception); |
| 4925 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4926 | |
| 4927 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | return err; |
| 4929 | } |
| 4930 | |
| 4931 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4932 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4934 | struct nfs4_createdata *data; |
| 4935 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4937 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4938 | if (data == NULL) |
| 4939 | goto out; |
| 4940 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4941 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4942 | status = nfs4_do_create(dir, dentry, data); |
| 4943 | |
| 4944 | nfs4_free_createdata(data); |
| 4945 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | return status; |
| 4947 | } |
| 4948 | |
| 4949 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4950 | struct iattr *sattr) |
| 4951 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4952 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4953 | struct nfs4_exception exception = { |
| 4954 | .interruptible = true, |
| 4955 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4956 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4958 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4959 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4960 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4961 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4962 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4964 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4965 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4966 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | &exception); |
| 4968 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4969 | nfs4_label_release_security(label); |
| 4970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | return err; |
| 4972 | } |
| 4973 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4974 | static int _nfs4_proc_readdir(struct nfs_readdir_arg *nr_arg, |
| 4975 | struct nfs_readdir_res *nr_res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4976 | { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4977 | struct inode *dir = d_inode(nr_arg->dentry); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4978 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | struct nfs4_readdir_arg args = { |
| 4980 | .fh = NFS_FH(dir), |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4981 | .pages = nr_arg->pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | .pgbase = 0, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4983 | .count = nr_arg->page_len, |
| 4984 | .plus = nr_arg->plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | }; |
| 4986 | struct nfs4_readdir_res res; |
| 4987 | struct rpc_message msg = { |
| 4988 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4989 | .rpc_argp = &args, |
| 4990 | .rpc_resp = &res, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4991 | .rpc_cred = nr_arg->cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | }; |
| 4993 | int status; |
| 4994 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4995 | dprintk("%s: dentry = %pd2, cookie = %llu\n", __func__, |
| 4996 | nr_arg->dentry, (unsigned long long)nr_arg->cookie); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4997 | if (!(server->caps & NFS_CAP_SECURITY_LABEL)) |
| 4998 | args.bitmask = server->attr_bitmask_nl; |
| 4999 | else |
| 5000 | args.bitmask = server->attr_bitmask; |
| 5001 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5002 | nfs4_setup_readdir(nr_arg->cookie, nr_arg->verf, nr_arg->dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | res.pgbase = args.pgbase; |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 5004 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 5005 | &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 5006 | if (status >= 0) { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5007 | memcpy(nr_res->verf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 5008 | status += args.pgbase; |
| 5009 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 5010 | |
| 5011 | nfs_invalidate_atime(dir); |
| 5012 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5013 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | return status; |
| 5015 | } |
| 5016 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5017 | static int nfs4_proc_readdir(struct nfs_readdir_arg *arg, |
| 5018 | struct nfs_readdir_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5020 | struct nfs4_exception exception = { |
| 5021 | .interruptible = true, |
| 5022 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | int err; |
| 5024 | do { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5025 | err = _nfs4_proc_readdir(arg, res); |
| 5026 | trace_nfs4_readdir(d_inode(arg->dentry), err); |
| 5027 | err = nfs4_handle_exception(NFS_SERVER(d_inode(arg->dentry)), |
| 5028 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | } while (exception.retry); |
| 5030 | return err; |
| 5031 | } |
| 5032 | |
| 5033 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5034 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5036 | struct nfs4_createdata *data; |
| 5037 | int mode = sattr->ia_mode; |
| 5038 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5040 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 5041 | if (data == NULL) |
| 5042 | goto out; |
| 5043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5044 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5045 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5046 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5047 | data->arg.ftype = NF4BLK; |
| 5048 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5049 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5050 | } |
| 5051 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5052 | data->arg.ftype = NF4CHR; |
| 5053 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5054 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5055 | } else if (!S_ISSOCK(mode)) { |
| 5056 | status = -EINVAL; |
| 5057 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5059 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5060 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5061 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5062 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5063 | nfs4_free_createdata(data); |
| 5064 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | return status; |
| 5066 | } |
| 5067 | |
| 5068 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 5069 | struct iattr *sattr, dev_t rdev) |
| 5070 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5071 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5072 | struct nfs4_exception exception = { |
| 5073 | .interruptible = true, |
| 5074 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5075 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5076 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 5077 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5078 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5079 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5080 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 5081 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5083 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 5084 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 5085 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | &exception); |
| 5087 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5088 | |
| 5089 | nfs4_label_release_security(label); |
| 5090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5091 | return err; |
| 5092 | } |
| 5093 | |
| 5094 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5095 | struct nfs_fsstat *fsstat) |
| 5096 | { |
| 5097 | struct nfs4_statfs_arg args = { |
| 5098 | .fh = fhandle, |
| 5099 | .bitmask = server->attr_bitmask, |
| 5100 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5101 | struct nfs4_statfs_res res = { |
| 5102 | .fsstat = fsstat, |
| 5103 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5104 | struct rpc_message msg = { |
| 5105 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5106 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5107 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | }; |
| 5109 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5110 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5111 | 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] | 5112 | } |
| 5113 | |
| 5114 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5115 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5116 | struct nfs4_exception exception = { |
| 5117 | .interruptible = true, |
| 5118 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | int err; |
| 5120 | do { |
| 5121 | err = nfs4_handle_exception(server, |
| 5122 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5123 | &exception); |
| 5124 | } while (exception.retry); |
| 5125 | return err; |
| 5126 | } |
| 5127 | |
| 5128 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5129 | struct nfs_fsinfo *fsinfo) |
| 5130 | { |
| 5131 | struct nfs4_fsinfo_arg args = { |
| 5132 | .fh = fhandle, |
| 5133 | .bitmask = server->attr_bitmask, |
| 5134 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5135 | struct nfs4_fsinfo_res res = { |
| 5136 | .fsinfo = fsinfo, |
| 5137 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | struct rpc_message msg = { |
| 5139 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5140 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5141 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 | }; |
| 5143 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5144 | 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] | 5145 | } |
| 5146 | |
| 5147 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5148 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5149 | struct nfs4_exception exception = { |
| 5150 | .interruptible = true, |
| 5151 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | int err; |
| 5153 | |
| 5154 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5155 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5156 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5157 | if (err == 0) { |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 5158 | nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5159 | break; |
| 5160 | } |
| 5161 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | } while (exception.retry); |
| 5163 | return err; |
| 5164 | } |
| 5165 | |
| 5166 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5167 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5168 | int error; |
| 5169 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5170 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5171 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5172 | if (error == 0) { |
| 5173 | /* block layout checks this! */ |
| 5174 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5175 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5176 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5177 | |
| 5178 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5182 | struct nfs_pathconf *pathconf) |
| 5183 | { |
| 5184 | struct nfs4_pathconf_arg args = { |
| 5185 | .fh = fhandle, |
| 5186 | .bitmask = server->attr_bitmask, |
| 5187 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5188 | struct nfs4_pathconf_res res = { |
| 5189 | .pathconf = pathconf, |
| 5190 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 | struct rpc_message msg = { |
| 5192 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5193 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5194 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5195 | }; |
| 5196 | |
| 5197 | /* None of the pathconf attributes are mandatory to implement */ |
| 5198 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5199 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5200 | return 0; |
| 5201 | } |
| 5202 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5203 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5204 | 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] | 5205 | } |
| 5206 | |
| 5207 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5208 | struct nfs_pathconf *pathconf) |
| 5209 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5210 | struct nfs4_exception exception = { |
| 5211 | .interruptible = true, |
| 5212 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | int err; |
| 5214 | |
| 5215 | do { |
| 5216 | err = nfs4_handle_exception(server, |
| 5217 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5218 | &exception); |
| 5219 | } while (exception.retry); |
| 5220 | return err; |
| 5221 | } |
| 5222 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5223 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5224 | const struct nfs_open_context *ctx, |
| 5225 | const struct nfs_lock_context *l_ctx, |
| 5226 | fmode_t fmode) |
| 5227 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5228 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5229 | } |
| 5230 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5231 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5232 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5233 | const struct nfs_open_context *ctx, |
| 5234 | const struct nfs_lock_context *l_ctx, |
| 5235 | fmode_t fmode) |
| 5236 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5237 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5238 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5239 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5240 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5241 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5242 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | static bool nfs4_error_stateid_expired(int err) |
| 5246 | { |
| 5247 | switch (err) { |
| 5248 | case -NFS4ERR_DELEG_REVOKED: |
| 5249 | case -NFS4ERR_ADMIN_REVOKED: |
| 5250 | case -NFS4ERR_BAD_STATEID: |
| 5251 | case -NFS4ERR_STALE_STATEID: |
| 5252 | case -NFS4ERR_OLD_STATEID: |
| 5253 | case -NFS4ERR_OPENMODE: |
| 5254 | case -NFS4ERR_EXPIRED: |
| 5255 | return true; |
| 5256 | } |
| 5257 | return false; |
| 5258 | } |
| 5259 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5260 | 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] | 5261 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5262 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5264 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5265 | if (task->tk_status < 0) { |
| 5266 | struct nfs4_exception exception = { |
| 5267 | .inode = hdr->inode, |
| 5268 | .state = hdr->args.context->state, |
| 5269 | .stateid = &hdr->args.stateid, |
| 5270 | }; |
| 5271 | task->tk_status = nfs4_async_handle_exception(task, |
| 5272 | server, task->tk_status, &exception); |
| 5273 | if (exception.retry) { |
| 5274 | rpc_restart_call_prepare(task); |
| 5275 | return -EAGAIN; |
| 5276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5280 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5281 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5282 | } |
| 5283 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5284 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5285 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5286 | { |
| 5287 | |
| 5288 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5289 | nfs4_stateid_is_current(&args->stateid, |
| 5290 | args->context, |
| 5291 | args->lock_context, |
| 5292 | FMODE_READ)) |
| 5293 | return false; |
| 5294 | rpc_restart_call_prepare(task); |
| 5295 | return true; |
| 5296 | } |
| 5297 | |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5298 | static bool nfs4_read_plus_not_supported(struct rpc_task *task, |
| 5299 | struct nfs_pgio_header *hdr) |
| 5300 | { |
| 5301 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
| 5302 | struct rpc_message *msg = &task->tk_msg; |
| 5303 | |
| 5304 | if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS] && |
| 5305 | server->caps & NFS_CAP_READ_PLUS && task->tk_status == -ENOTSUPP) { |
| 5306 | server->caps &= ~NFS_CAP_READ_PLUS; |
| 5307 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5308 | rpc_restart_call_prepare(task); |
| 5309 | return true; |
| 5310 | } |
| 5311 | return false; |
| 5312 | } |
| 5313 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5314 | 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] | 5315 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5316 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5317 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5318 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5319 | return -EAGAIN; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5320 | if (nfs4_read_plus_not_supported(task, hdr)) |
| 5321 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5322 | if (task->tk_status > 0) |
| 5323 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5324 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5325 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5326 | } |
| 5327 | |
Anna Schumaker | 21e3140 | 2020-12-03 15:18:39 -0500 | [diff] [blame] | 5328 | #if defined CONFIG_NFS_V4_2 && defined CONFIG_NFS_V4_2_READ_PLUS |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5329 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5330 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5331 | { |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5332 | /* Note: We don't use READ_PLUS with pNFS yet */ |
| 5333 | if (nfs_server_capable(hdr->inode, NFS_CAP_READ_PLUS) && !hdr->ds_clp) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5334 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS]; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5335 | } |
| 5336 | #else |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5337 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5338 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5339 | { |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5340 | } |
| 5341 | #endif /* CONFIG_NFS_V4_2 */ |
| 5342 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5343 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5344 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5346 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5347 | if (!hdr->pgio_done_cb) |
| 5348 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5349 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5350 | nfs42_read_plus_support(hdr, msg); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5351 | 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] | 5352 | } |
| 5353 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5354 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5355 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5356 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5357 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5358 | &hdr->args.seq_args, |
| 5359 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5360 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5361 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5362 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5363 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5364 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5365 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5366 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5367 | return -EIO; |
| 5368 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5371 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5372 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5374 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5375 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5376 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5377 | if (task->tk_status < 0) { |
| 5378 | struct nfs4_exception exception = { |
| 5379 | .inode = hdr->inode, |
| 5380 | .state = hdr->args.context->state, |
| 5381 | .stateid = &hdr->args.stateid, |
| 5382 | }; |
| 5383 | task->tk_status = nfs4_async_handle_exception(task, |
| 5384 | NFS_SERVER(inode), task->tk_status, |
| 5385 | &exception); |
| 5386 | if (exception.retry) { |
| 5387 | rpc_restart_call_prepare(task); |
| 5388 | return -EAGAIN; |
| 5389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5391 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5392 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5393 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5394 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5395 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5396 | } |
| 5397 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5398 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5399 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5400 | { |
| 5401 | |
| 5402 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5403 | nfs4_stateid_is_current(&args->stateid, |
| 5404 | args->context, |
| 5405 | args->lock_context, |
| 5406 | FMODE_WRITE)) |
| 5407 | return false; |
| 5408 | rpc_restart_call_prepare(task); |
| 5409 | return true; |
| 5410 | } |
| 5411 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5412 | 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] | 5413 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5414 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5415 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5416 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5417 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5418 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5419 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5420 | } |
| 5421 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5422 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5423 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5424 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5425 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5426 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5427 | return false; |
| 5428 | /* Otherwise, request attributes if and only if we don't hold |
| 5429 | * a delegation |
| 5430 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5431 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5432 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5433 | |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5434 | static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src, |
| 5435 | struct inode *inode, struct nfs_server *server, |
| 5436 | struct nfs4_label *label) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5437 | { |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5438 | unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5439 | unsigned int i; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5440 | |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5441 | memcpy(bitmask, src, sizeof(*bitmask) * NFS4_BITMASK_SZ); |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5442 | |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5443 | if (cache_validity & NFS_INO_INVALID_CHANGE) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5444 | bitmask[0] |= FATTR4_WORD0_CHANGE; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5445 | if (cache_validity & NFS_INO_INVALID_ATIME) |
| 5446 | bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 5447 | if (cache_validity & NFS_INO_INVALID_MODE) |
| 5448 | bitmask[1] |= FATTR4_WORD1_MODE; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5449 | if (cache_validity & NFS_INO_INVALID_OTHER) |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 5450 | bitmask[1] |= FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP; |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 5451 | if (cache_validity & NFS_INO_INVALID_NLINK) |
| 5452 | bitmask[1] |= FATTR4_WORD1_NUMLINKS; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5453 | if (label && label->len && cache_validity & NFS_INO_INVALID_LABEL) |
| 5454 | bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5455 | if (cache_validity & NFS_INO_INVALID_CTIME) |
| 5456 | bitmask[1] |= FATTR4_WORD1_TIME_METADATA; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5457 | if (cache_validity & NFS_INO_INVALID_MTIME) |
| 5458 | bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5459 | if (cache_validity & NFS_INO_INVALID_BLOCKS) |
| 5460 | bitmask[1] |= FATTR4_WORD1_SPACE_USED; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5461 | |
Trond Myklebust | cc7f2da | 2021-04-11 14:31:24 -0400 | [diff] [blame] | 5462 | if (cache_validity & NFS_INO_INVALID_SIZE) |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5463 | bitmask[0] |= FATTR4_WORD0_SIZE; |
| 5464 | |
| 5465 | for (i = 0; i < NFS4_BITMASK_SZ; i++) |
| 5466 | bitmask[i] &= server->attr_bitmask[i]; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5467 | } |
| 5468 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5469 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5470 | struct rpc_message *msg, |
| 5471 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5472 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5473 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5474 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5475 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5476 | hdr->args.bitmask = NULL; |
| 5477 | hdr->res.fattr = NULL; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5478 | } else { |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5479 | nfs4_bitmask_set(hdr->args.bitmask_store, |
| 5480 | server->cache_consistency_bitmask, |
| 5481 | hdr->inode, server, NULL); |
| 5482 | hdr->args.bitmask = hdr->args.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5483 | } |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5484 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5485 | if (!hdr->pgio_done_cb) |
| 5486 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5487 | hdr->res.server = server; |
| 5488 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5490 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Olga Kornievskaia | cd1b659 | 2020-02-12 17:32:12 -0500 | [diff] [blame] | 5491 | 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] | 5492 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5495 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5496 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5497 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5498 | &data->args.seq_args, |
| 5499 | &data->res.seq_res, |
| 5500 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | } |
| 5502 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5503 | 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] | 5504 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5506 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5507 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5508 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5509 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5510 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5511 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5513 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5516 | 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] | 5517 | { |
| 5518 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5519 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5520 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5521 | } |
| 5522 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5523 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5524 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5526 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5527 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5528 | if (data->commit_done_cb == NULL) |
| 5529 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5530 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5531 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5532 | 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] | 5533 | 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] | 5534 | } |
| 5535 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5536 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5537 | struct nfs_commitres *res) |
| 5538 | { |
| 5539 | struct inode *dst_inode = file_inode(dst); |
| 5540 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5541 | struct rpc_message msg = { |
| 5542 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5543 | .rpc_argp = args, |
| 5544 | .rpc_resp = res, |
| 5545 | }; |
| 5546 | |
| 5547 | args->fh = NFS_FH(dst_inode); |
| 5548 | return nfs4_call_sync(server->client, server, &msg, |
| 5549 | &args->seq_args, &res->seq_res, 1); |
| 5550 | } |
| 5551 | |
| 5552 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5553 | { |
| 5554 | struct nfs_commitargs args = { |
| 5555 | .offset = offset, |
| 5556 | .count = count, |
| 5557 | }; |
| 5558 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5559 | struct nfs4_exception exception = { }; |
| 5560 | int status; |
| 5561 | |
| 5562 | do { |
| 5563 | status = _nfs4_proc_commit(dst, &args, res); |
| 5564 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5565 | } while (exception.retry); |
| 5566 | |
| 5567 | return status; |
| 5568 | } |
| 5569 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5570 | struct nfs4_renewdata { |
| 5571 | struct nfs_client *client; |
| 5572 | unsigned long timestamp; |
| 5573 | }; |
| 5574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | /* |
| 5576 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5577 | * standalone procedure for queueing an asynchronous RENEW. |
| 5578 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5579 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5580 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5581 | struct nfs4_renewdata *data = calldata; |
| 5582 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5583 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5584 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5585 | nfs4_schedule_state_renewal(clp); |
| 5586 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5587 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5588 | } |
| 5589 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5590 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5592 | struct nfs4_renewdata *data = calldata; |
| 5593 | struct nfs_client *clp = data->client; |
| 5594 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5595 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5596 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5597 | switch (task->tk_status) { |
| 5598 | case 0: |
| 5599 | break; |
| 5600 | case -NFS4ERR_LEASE_MOVED: |
| 5601 | nfs4_schedule_lease_moved_recovery(clp); |
| 5602 | break; |
| 5603 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5604 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5605 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5606 | return; |
| 5607 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5608 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5609 | return; |
| 5610 | } |
| 5611 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5613 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | } |
| 5615 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5616 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5617 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5618 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5619 | }; |
| 5620 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5621 | 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] | 5622 | { |
| 5623 | struct rpc_message msg = { |
| 5624 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5625 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5626 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5628 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5629 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5630 | if (renew_flags == 0) |
| 5631 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5632 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5633 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5634 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5635 | if (data == NULL) { |
| 5636 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5637 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5638 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5639 | data->client = clp; |
| 5640 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5641 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5642 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | } |
| 5644 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5645 | 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] | 5646 | { |
| 5647 | struct rpc_message msg = { |
| 5648 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5649 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5650 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | }; |
| 5652 | unsigned long now = jiffies; |
| 5653 | int status; |
| 5654 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5655 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | if (status < 0) |
| 5657 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5658 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | return 0; |
| 5660 | } |
| 5661 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5662 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5663 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5664 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5667 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5668 | * 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] | 5669 | * the stack. |
| 5670 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5671 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5672 | |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5673 | int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5674 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5675 | { |
| 5676 | struct page *newpage, **spages; |
| 5677 | int rc = 0; |
| 5678 | size_t len; |
| 5679 | spages = pages; |
| 5680 | |
| 5681 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5682 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5683 | newpage = alloc_page(GFP_KERNEL); |
| 5684 | |
| 5685 | if (newpage == NULL) |
| 5686 | goto unwind; |
| 5687 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5688 | buf += len; |
| 5689 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5690 | *pages++ = newpage; |
| 5691 | rc++; |
| 5692 | } while (buflen != 0); |
| 5693 | |
| 5694 | return rc; |
| 5695 | |
| 5696 | unwind: |
| 5697 | for(; rc > 0; rc--) |
| 5698 | __free_page(spages[rc-1]); |
| 5699 | return -ENOMEM; |
| 5700 | } |
| 5701 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5702 | struct nfs4_cached_acl { |
| 5703 | int cached; |
| 5704 | size_t len; |
Gustavo A. R. Silva | 5601cda | 2020-03-09 13:24:42 -0500 | [diff] [blame] | 5705 | char data[]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5706 | }; |
| 5707 | |
| 5708 | 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] | 5709 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5710 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5711 | |
| 5712 | spin_lock(&inode->i_lock); |
| 5713 | kfree(nfsi->nfs4_acl); |
| 5714 | nfsi->nfs4_acl = acl; |
| 5715 | spin_unlock(&inode->i_lock); |
| 5716 | } |
| 5717 | |
| 5718 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5719 | { |
| 5720 | nfs4_set_cached_acl(inode, NULL); |
| 5721 | } |
| 5722 | |
| 5723 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5724 | { |
| 5725 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5726 | struct nfs4_cached_acl *acl; |
| 5727 | int ret = -ENOENT; |
| 5728 | |
| 5729 | spin_lock(&inode->i_lock); |
| 5730 | acl = nfsi->nfs4_acl; |
| 5731 | if (acl == NULL) |
| 5732 | goto out; |
| 5733 | if (buf == NULL) /* user is just asking for length */ |
| 5734 | goto out_len; |
| 5735 | if (acl->cached == 0) |
| 5736 | goto out; |
| 5737 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5738 | if (acl->len > buflen) |
| 5739 | goto out; |
| 5740 | memcpy(buf, acl->data, acl->len); |
| 5741 | out_len: |
| 5742 | ret = acl->len; |
| 5743 | out: |
| 5744 | spin_unlock(&inode->i_lock); |
| 5745 | return ret; |
| 5746 | } |
| 5747 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5748 | 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] | 5749 | { |
| 5750 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5751 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5752 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5753 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5754 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5755 | if (acl == NULL) |
| 5756 | goto out; |
| 5757 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5758 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5759 | } else { |
| 5760 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5761 | if (acl == NULL) |
| 5762 | goto out; |
| 5763 | acl->cached = 0; |
| 5764 | } |
| 5765 | acl->len = acl_len; |
| 5766 | out: |
| 5767 | nfs4_set_cached_acl(inode, acl); |
| 5768 | } |
| 5769 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5770 | /* |
| 5771 | * The getxattr API returns the required buffer length when called with a |
| 5772 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5773 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5774 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5775 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5776 | * the cache. If not so, we throw away the page, and cache the required |
| 5777 | * length. The next getxattr call will then produce another round trip to |
| 5778 | * the server, this time with the input buf of the required size. |
| 5779 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5780 | 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] | 5781 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5782 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5783 | struct nfs_getaclargs args = { |
| 5784 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5785 | .acl_len = buflen, |
| 5786 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5787 | struct nfs_getaclres res = { |
| 5788 | .acl_len = buflen, |
| 5789 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5790 | struct rpc_message msg = { |
| 5791 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5792 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5793 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5794 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5795 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5796 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5797 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5798 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5799 | if (buflen == 0) |
| 5800 | buflen = server->rsize; |
| 5801 | |
| 5802 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5803 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5804 | if (!pages) |
| 5805 | return -ENOMEM; |
| 5806 | |
| 5807 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5808 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5809 | for (i = 0; i < npages; i++) { |
| 5810 | pages[i] = alloc_page(GFP_KERNEL); |
| 5811 | if (!pages[i]) |
| 5812 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5813 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5814 | |
| 5815 | /* for decoding across pages */ |
| 5816 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5817 | if (!res.acl_scratch) |
| 5818 | goto out_free; |
| 5819 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5820 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5821 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5822 | 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] | 5823 | __func__, buf, buflen, npages, args.acl_len); |
| 5824 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5825 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5826 | if (ret) |
| 5827 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5828 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5829 | /* Handle the case where the passed-in buffer is too short */ |
| 5830 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5831 | /* Did the user only issue a request for the acl length? */ |
| 5832 | if (buf == NULL) |
| 5833 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5834 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5835 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5836 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5837 | 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] | 5838 | if (buf) { |
| 5839 | if (res.acl_len > buflen) { |
| 5840 | ret = -ERANGE; |
| 5841 | goto out_free; |
| 5842 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5843 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5844 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5845 | out_ok: |
| 5846 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5847 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5848 | for (i = 0; i < npages; i++) |
| 5849 | if (pages[i]) |
| 5850 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5851 | if (res.acl_scratch) |
| 5852 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5853 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5854 | return ret; |
| 5855 | } |
| 5856 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5857 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5858 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5859 | struct nfs4_exception exception = { |
| 5860 | .interruptible = true, |
| 5861 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5862 | ssize_t ret; |
| 5863 | do { |
| 5864 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5865 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5866 | if (ret >= 0) |
| 5867 | break; |
| 5868 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5869 | } while (exception.retry); |
| 5870 | return ret; |
| 5871 | } |
| 5872 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5873 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5874 | { |
| 5875 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5876 | int ret; |
| 5877 | |
| 5878 | if (!nfs4_server_supports_acls(server)) |
| 5879 | return -EOPNOTSUPP; |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 5880 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5881 | if (ret < 0) |
| 5882 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5883 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5884 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5885 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5886 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5887 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5888 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5889 | return ret; |
| 5890 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5891 | } |
| 5892 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5893 | 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] | 5894 | { |
| 5895 | struct nfs_server *server = NFS_SERVER(inode); |
| 5896 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5897 | struct nfs_setaclargs arg = { |
| 5898 | .fh = NFS_FH(inode), |
| 5899 | .acl_pages = pages, |
| 5900 | .acl_len = buflen, |
| 5901 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5902 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5903 | struct rpc_message msg = { |
| 5904 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5905 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5906 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5907 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5908 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5909 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5910 | |
J. Bruce Fields | 4f8be1f | 2021-01-28 17:36:38 -0500 | [diff] [blame] | 5911 | /* You can't remove system.nfs4_acl: */ |
| 5912 | if (buflen == 0) |
| 5913 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5914 | if (!nfs4_server_supports_acls(server)) |
| 5915 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5916 | if (npages > ARRAY_SIZE(pages)) |
| 5917 | return -ERANGE; |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5918 | i = nfs4_buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5919 | if (i < 0) |
| 5920 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5921 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5922 | 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] | 5923 | |
| 5924 | /* |
| 5925 | * Free each page after tx, so the only ref left is |
| 5926 | * held by the network stack |
| 5927 | */ |
| 5928 | for (; i > 0; i--) |
| 5929 | put_page(pages[i-1]); |
| 5930 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5931 | /* |
| 5932 | * Acl update can result in inode attribute update. |
| 5933 | * so mark the attribute cache invalid. |
| 5934 | */ |
| 5935 | spin_lock(&inode->i_lock); |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 5936 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 5937 | NFS_INO_INVALID_CTIME | |
| 5938 | NFS_INO_REVAL_FORCED); |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5939 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5940 | nfs_access_zap_cache(inode); |
| 5941 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5942 | return ret; |
| 5943 | } |
| 5944 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5945 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5946 | { |
| 5947 | struct nfs4_exception exception = { }; |
| 5948 | int err; |
| 5949 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5950 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5951 | trace_nfs4_set_acl(inode, err); |
Dai Ngo | f8849e2 | 2021-05-19 17:15:10 -0400 | [diff] [blame] | 5952 | if (err == -NFS4ERR_BADOWNER || err == -NFS4ERR_BADNAME) { |
| 5953 | /* |
| 5954 | * no need to retry since the kernel |
| 5955 | * isn't involved in encoding the ACEs. |
| 5956 | */ |
| 5957 | err = -EINVAL; |
| 5958 | break; |
| 5959 | } |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5960 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5961 | &exception); |
| 5962 | } while (exception.retry); |
| 5963 | return err; |
| 5964 | } |
| 5965 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5966 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5967 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5968 | size_t buflen) |
| 5969 | { |
| 5970 | struct nfs_server *server = NFS_SERVER(inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5971 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5972 | |
| 5973 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame^] | 5974 | struct nfs_fattr fattr = { |
| 5975 | .label = &label, |
| 5976 | }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5977 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5978 | .fh = NFS_FH(inode), |
| 5979 | .bitmask = bitmask, |
| 5980 | }; |
| 5981 | struct nfs4_getattr_res res = { |
| 5982 | .fattr = &fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5983 | .server = server, |
| 5984 | }; |
| 5985 | struct rpc_message msg = { |
| 5986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5987 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5988 | .rpc_resp = &res, |
| 5989 | }; |
| 5990 | int ret; |
| 5991 | |
| 5992 | nfs_fattr_init(&fattr); |
| 5993 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5994 | 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] | 5995 | if (ret) |
| 5996 | return ret; |
| 5997 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5998 | return -ENOENT; |
Ondrej Mosnacek | 53cb245 | 2021-01-15 18:43:56 +0100 | [diff] [blame] | 5999 | return label.len; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6000 | } |
| 6001 | |
| 6002 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 6003 | size_t buflen) |
| 6004 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6005 | struct nfs4_exception exception = { |
| 6006 | .interruptible = true, |
| 6007 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6008 | int err; |
| 6009 | |
| 6010 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6011 | return -EOPNOTSUPP; |
| 6012 | |
| 6013 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6014 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 6015 | trace_nfs4_get_security_label(inode, err); |
| 6016 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6017 | &exception); |
| 6018 | } while (exception.retry); |
| 6019 | return err; |
| 6020 | } |
| 6021 | |
| 6022 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 6023 | struct nfs4_label *ilabel, |
| 6024 | struct nfs_fattr *fattr, |
| 6025 | struct nfs4_label *olabel) |
| 6026 | { |
| 6027 | |
| 6028 | struct iattr sattr = {0}; |
| 6029 | struct nfs_server *server = NFS_SERVER(inode); |
| 6030 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6031 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6032 | .fh = NFS_FH(inode), |
| 6033 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6034 | .server = server, |
| 6035 | .bitmask = bitmask, |
| 6036 | .label = ilabel, |
| 6037 | }; |
| 6038 | struct nfs_setattrres res = { |
| 6039 | .fattr = fattr, |
| 6040 | .label = olabel, |
| 6041 | .server = server, |
| 6042 | }; |
| 6043 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6044 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 6045 | .rpc_argp = &arg, |
| 6046 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6047 | }; |
| 6048 | int status; |
| 6049 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6050 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6051 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6052 | 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] | 6053 | if (status) |
| 6054 | dprintk("%s failed: %d\n", __func__, status); |
| 6055 | |
| 6056 | return status; |
| 6057 | } |
| 6058 | |
| 6059 | static int nfs4_do_set_security_label(struct inode *inode, |
| 6060 | struct nfs4_label *ilabel, |
| 6061 | struct nfs_fattr *fattr, |
| 6062 | struct nfs4_label *olabel) |
| 6063 | { |
| 6064 | struct nfs4_exception exception = { }; |
| 6065 | int err; |
| 6066 | |
| 6067 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6068 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 6069 | fattr, olabel); |
| 6070 | trace_nfs4_set_security_label(inode, err); |
| 6071 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6072 | &exception); |
| 6073 | } while (exception.retry); |
| 6074 | return err; |
| 6075 | } |
| 6076 | |
| 6077 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6078 | 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] | 6079 | { |
| 6080 | struct nfs4_label ilabel, *olabel = NULL; |
| 6081 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6082 | int status; |
| 6083 | |
| 6084 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6085 | return -EOPNOTSUPP; |
| 6086 | |
| 6087 | nfs_fattr_init(&fattr); |
| 6088 | |
| 6089 | ilabel.pi = 0; |
| 6090 | ilabel.lfs = 0; |
| 6091 | ilabel.label = (char *)buf; |
| 6092 | ilabel.len = buflen; |
| 6093 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6094 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 6095 | if (IS_ERR(olabel)) { |
| 6096 | status = -PTR_ERR(olabel); |
| 6097 | goto out; |
| 6098 | } |
| 6099 | |
| 6100 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 6101 | if (status == 0) |
| 6102 | nfs_setsecurity(inode, &fattr, olabel); |
| 6103 | |
| 6104 | nfs4_label_free(olabel); |
| 6105 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6106 | return status; |
| 6107 | } |
| 6108 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 6109 | |
| 6110 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6111 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 6112 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6113 | { |
| 6114 | __be32 verf[2]; |
| 6115 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6116 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 6117 | /* An impossible timestamp guarantees this value |
| 6118 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6119 | verf[0] = cpu_to_be32(U32_MAX); |
| 6120 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6121 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6122 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6123 | u64 ns = ktime_to_ns(nn->boot_time); |
| 6124 | |
| 6125 | verf[0] = cpu_to_be32(ns >> 32); |
| 6126 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6127 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6128 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 6129 | } |
| 6130 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6131 | static size_t |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6132 | nfs4_get_uniquifier(struct nfs_client *clp, char *buf, size_t buflen) |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6133 | { |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6134 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 6135 | struct nfs_netns_client *nn_clp = nn->nfs_client; |
| 6136 | const char *id; |
| 6137 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6138 | buf[0] = '\0'; |
| 6139 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6140 | if (nn_clp) { |
| 6141 | rcu_read_lock(); |
| 6142 | id = rcu_dereference(nn_clp->identifier); |
| 6143 | if (id) |
| 6144 | strscpy(buf, id, buflen); |
| 6145 | rcu_read_unlock(); |
| 6146 | } |
| 6147 | |
| 6148 | if (nfs4_client_id_uniquifier[0] != '\0' && buf[0] == '\0') |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6149 | strscpy(buf, nfs4_client_id_uniquifier, buflen); |
| 6150 | |
| 6151 | return strlen(buf); |
| 6152 | } |
| 6153 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6154 | static int |
| 6155 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6156 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6157 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6158 | size_t buflen; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6159 | size_t len; |
| 6160 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6161 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6162 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6163 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 6164 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6165 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6166 | len = 14 + |
| 6167 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 6168 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6169 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6170 | 1; |
| 6171 | rcu_read_unlock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6172 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6173 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6174 | if (buflen) |
| 6175 | len += buflen + 1; |
| 6176 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6177 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6178 | return -EINVAL; |
| 6179 | |
| 6180 | /* |
| 6181 | * Since this string is allocated at mount time, and held until the |
| 6182 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6183 | * about a memory-reclaim deadlock. |
| 6184 | */ |
| 6185 | str = kmalloc(len, GFP_KERNEL); |
| 6186 | if (!str) |
| 6187 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6188 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6189 | rcu_read_lock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6190 | if (buflen) |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6191 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6192 | clp->cl_rpcclient->cl_nodename, buf, |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6193 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6194 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6195 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6196 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6197 | clp->cl_rpcclient->cl_nodename, |
| 6198 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6199 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6200 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6201 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6202 | clp->cl_owner_id = str; |
| 6203 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6204 | } |
| 6205 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6206 | static int |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6207 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6208 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6209 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6210 | size_t buflen; |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6211 | size_t len; |
| 6212 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6213 | |
| 6214 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6215 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6216 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6217 | len = 10 + 10 + 1 + 10 + 1 + |
| 6218 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6219 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6220 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6221 | if (buflen) |
| 6222 | len += buflen + 1; |
| 6223 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6224 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6225 | return -EINVAL; |
| 6226 | |
| 6227 | /* |
| 6228 | * Since this string is allocated at mount time, and held until the |
| 6229 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6230 | * about a memory-reclaim deadlock. |
| 6231 | */ |
| 6232 | str = kmalloc(len, GFP_KERNEL); |
| 6233 | if (!str) |
| 6234 | return -ENOMEM; |
| 6235 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6236 | if (buflen) |
| 6237 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
| 6238 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6239 | buf, clp->cl_rpcclient->cl_nodename); |
| 6240 | else |
| 6241 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
| 6242 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6243 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6244 | clp->cl_owner_id = str; |
| 6245 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6246 | } |
| 6247 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6248 | /* |
| 6249 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6250 | * services. Advertise one based on the address family of the |
| 6251 | * clientaddr. |
| 6252 | */ |
| 6253 | static unsigned int |
| 6254 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6255 | { |
| 6256 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6257 | return scnprintf(buf, len, "tcp6"); |
| 6258 | else |
| 6259 | return scnprintf(buf, len, "tcp"); |
| 6260 | } |
| 6261 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6262 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6263 | { |
| 6264 | struct nfs4_setclientid *sc = calldata; |
| 6265 | |
| 6266 | if (task->tk_status == 0) |
| 6267 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6268 | } |
| 6269 | |
| 6270 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6271 | .rpc_call_done = nfs4_setclientid_done, |
| 6272 | }; |
| 6273 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6274 | /** |
| 6275 | * nfs4_proc_setclientid - Negotiate client ID |
| 6276 | * @clp: state data structure |
| 6277 | * @program: RPC program for NFSv4 callback service |
| 6278 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6279 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6280 | * @res: where to place the result |
| 6281 | * |
| 6282 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6283 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6284 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6285 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6286 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6287 | { |
| 6288 | nfs4_verifier sc_verifier; |
| 6289 | struct nfs4_setclientid setclientid = { |
| 6290 | .sc_verifier = &sc_verifier, |
| 6291 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6292 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6293 | }; |
| 6294 | struct rpc_message msg = { |
| 6295 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6296 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6297 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6298 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6299 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6300 | struct rpc_task_setup task_setup_data = { |
| 6301 | .rpc_client = clp->cl_rpcclient, |
| 6302 | .rpc_message = &msg, |
| 6303 | .callback_ops = &nfs4_setclientid_ops, |
| 6304 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6305 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6306 | }; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6307 | unsigned long now = jiffies; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6308 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6310 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6311 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6312 | |
| 6313 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6314 | status = nfs4_init_uniform_client_string(clp); |
| 6315 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6316 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6317 | |
| 6318 | if (status) |
| 6319 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6320 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6321 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6322 | setclientid.sc_netid_len = |
| 6323 | nfs4_init_callback_netid(clp, |
| 6324 | setclientid.sc_netid, |
| 6325 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6326 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6327 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6328 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6329 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6330 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6331 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6332 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6333 | |
| 6334 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6335 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6336 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6337 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6338 | put_rpccred(setclientid.sc_cred); |
| 6339 | } |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6340 | |
| 6341 | if (status == 0) |
| 6342 | do_renew_lease(clp, now); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6343 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6344 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6345 | dprintk("NFS reply setclientid: %d\n", status); |
| 6346 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | } |
| 6348 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6349 | /** |
| 6350 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6351 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6352 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6353 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6354 | * |
| 6355 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6356 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6357 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6358 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6359 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6360 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6361 | struct rpc_message msg = { |
| 6362 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6363 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6364 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6365 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | int status; |
| 6367 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6368 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6369 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6370 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6371 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6372 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6373 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6374 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6375 | return status; |
| 6376 | } |
| 6377 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6378 | struct nfs4_delegreturndata { |
| 6379 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6380 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6381 | struct nfs_fh fh; |
| 6382 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6383 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6384 | struct { |
| 6385 | struct nfs4_layoutreturn_args arg; |
| 6386 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6387 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6388 | u32 roc_barrier; |
| 6389 | bool roc; |
| 6390 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6391 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6392 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6393 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6394 | }; |
| 6395 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6396 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6397 | { |
| 6398 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6399 | struct nfs4_exception exception = { |
| 6400 | .inode = data->inode, |
| 6401 | .stateid = &data->stateid, |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 6402 | .task_is_privileged = data->args.seq_args.sa_privileged, |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6403 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6404 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6405 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6406 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6407 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6408 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6409 | |
| 6410 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6411 | if (pnfs_roc_done(task, &data->args.lr_args, &data->res.lr_res, |
| 6412 | &data->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6413 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6414 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6415 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6416 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6417 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6418 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6419 | case -NFS4ERR_ADMIN_REVOKED: |
| 6420 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6421 | case -NFS4ERR_EXPIRED: |
| 6422 | nfs4_free_revoked_stateid(data->res.server, |
| 6423 | data->args.stateid, |
| 6424 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6425 | fallthrough; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6426 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6427 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 244fcd2 | 2019-12-20 10:43:37 -0500 | [diff] [blame] | 6428 | case -ETIMEDOUT: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6429 | task->tk_status = 0; |
| 6430 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6431 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6432 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6433 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6434 | if (data->args.bitmask) { |
| 6435 | data->args.bitmask = NULL; |
| 6436 | data->res.fattr = NULL; |
| 6437 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6438 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6439 | case -NFS4ERR_ACCESS: |
| 6440 | if (data->args.bitmask) { |
| 6441 | data->args.bitmask = NULL; |
| 6442 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6443 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6444 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6445 | fallthrough; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6446 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6447 | task->tk_status = nfs4_async_handle_exception(task, |
| 6448 | data->res.server, task->tk_status, |
| 6449 | &exception); |
| 6450 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6451 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6452 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6453 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6454 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6455 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6456 | out_restart: |
| 6457 | task->tk_status = 0; |
| 6458 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | static void nfs4_delegreturn_release(void *calldata) |
| 6462 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6463 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6464 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6465 | |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6466 | if (data->lr.roc) |
| 6467 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6468 | data->res.lr_ret); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6469 | if (inode) { |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6470 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6471 | nfs_iput_and_deactive(inode); |
| 6472 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6473 | kfree(calldata); |
| 6474 | } |
| 6475 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6476 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6477 | { |
| 6478 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6479 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6480 | |
| 6481 | d_data = (struct nfs4_delegreturndata *)data; |
| 6482 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6483 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6484 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6485 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6486 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6487 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6488 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6489 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6490 | d_data->args.lr_args = NULL; |
| 6491 | d_data->res.lr_res = NULL; |
| 6492 | } |
| 6493 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6494 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6495 | &d_data->args.seq_args, |
| 6496 | &d_data->res.seq_res, |
| 6497 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6498 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6499 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6500 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6501 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6502 | .rpc_call_done = nfs4_delegreturn_done, |
| 6503 | .rpc_release = nfs4_delegreturn_release, |
| 6504 | }; |
| 6505 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6506 | 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] | 6507 | { |
| 6508 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6509 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6510 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6511 | struct rpc_message msg = { |
| 6512 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6513 | .rpc_cred = cred, |
| 6514 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6515 | struct rpc_task_setup task_setup_data = { |
| 6516 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6517 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6518 | .callback_ops = &nfs4_delegreturn_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 6519 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT | RPC_TASK_MOVEABLE, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6520 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6521 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6522 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6523 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6524 | if (data == NULL) |
| 6525 | return -ENOMEM; |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6526 | |
| 6527 | nfs4_state_protect(server->nfs_client, |
| 6528 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6529 | &task_setup_data.rpc_client, &msg); |
| 6530 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6531 | data->args.fhandle = &data->fh; |
| 6532 | data->args.stateid = &data->stateid; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 6533 | nfs4_bitmask_set(data->args.bitmask_store, |
| 6534 | server->cache_consistency_bitmask, inode, server, |
| 6535 | NULL); |
| 6536 | data->args.bitmask = data->args.bitmask_store; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6537 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6538 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6539 | data->res.fattr = &data->fattr; |
| 6540 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6541 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6542 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6543 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6544 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6545 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6546 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6547 | if (data->inode || issync) { |
| 6548 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, |
| 6549 | cred); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6550 | if (data->lr.roc) { |
| 6551 | data->args.lr_args = &data->lr.arg; |
| 6552 | data->res.lr_res = &data->lr.res; |
| 6553 | } |
| 6554 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6555 | |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 6556 | if (!data->inode) |
| 6557 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, |
| 6558 | 1); |
| 6559 | else |
| 6560 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, |
| 6561 | 0); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6562 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6563 | msg.rpc_argp = &data->args; |
| 6564 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6565 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6566 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6567 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6568 | if (!issync) |
| 6569 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6570 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6571 | if (status != 0) |
| 6572 | goto out; |
| 6573 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6574 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6575 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6576 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6577 | } |
| 6578 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6579 | 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] | 6580 | { |
| 6581 | struct nfs_server *server = NFS_SERVER(inode); |
| 6582 | struct nfs4_exception exception = { }; |
| 6583 | int err; |
| 6584 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6585 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6586 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6587 | switch (err) { |
| 6588 | case -NFS4ERR_STALE_STATEID: |
| 6589 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6590 | case 0: |
| 6591 | return 0; |
| 6592 | } |
| 6593 | err = nfs4_handle_exception(server, err, &exception); |
| 6594 | } while (exception.retry); |
| 6595 | return err; |
| 6596 | } |
| 6597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6598 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6599 | { |
| 6600 | struct inode *inode = state->inode; |
| 6601 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6602 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6603 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6604 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6605 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6606 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6607 | struct nfs_lockt_res res = { |
| 6608 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6609 | }; |
| 6610 | struct rpc_message msg = { |
| 6611 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6612 | .rpc_argp = &arg, |
| 6613 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6614 | .rpc_cred = state->owner->so_cred, |
| 6615 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6616 | struct nfs4_lock_state *lsp; |
| 6617 | int status; |
| 6618 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6619 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6620 | status = nfs4_set_lock_state(state, request); |
| 6621 | if (status != 0) |
| 6622 | goto out; |
| 6623 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6624 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6625 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6626 | 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] | 6627 | switch (status) { |
| 6628 | case 0: |
| 6629 | request->fl_type = F_UNLCK; |
| 6630 | break; |
| 6631 | case -NFS4ERR_DENIED: |
| 6632 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6633 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6634 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6635 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6636 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6637 | return status; |
| 6638 | } |
| 6639 | |
| 6640 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6641 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6642 | struct nfs4_exception exception = { |
| 6643 | .interruptible = true, |
| 6644 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6645 | int err; |
| 6646 | |
| 6647 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6648 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6649 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6650 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6651 | &exception); |
| 6652 | } while (exception.retry); |
| 6653 | return err; |
| 6654 | } |
| 6655 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6656 | /* |
| 6657 | * Update the seqid of a lock stateid after receiving |
| 6658 | * NFS4ERR_OLD_STATEID |
| 6659 | */ |
| 6660 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6661 | struct nfs4_lock_state *lsp) |
| 6662 | { |
| 6663 | struct nfs4_state *state = lsp->ls_state; |
| 6664 | bool ret = false; |
| 6665 | |
| 6666 | spin_lock(&state->state_lock); |
| 6667 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6668 | goto out; |
| 6669 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6670 | nfs4_stateid_seqid_inc(dst); |
| 6671 | else |
| 6672 | dst->seqid = lsp->ls_stateid.seqid; |
| 6673 | ret = true; |
| 6674 | out: |
| 6675 | spin_unlock(&state->state_lock); |
| 6676 | return ret; |
| 6677 | } |
| 6678 | |
| 6679 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6680 | struct nfs4_lock_state *lsp) |
| 6681 | { |
| 6682 | struct nfs4_state *state = lsp->ls_state; |
| 6683 | bool ret; |
| 6684 | |
| 6685 | spin_lock(&state->state_lock); |
| 6686 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6687 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6688 | spin_unlock(&state->state_lock); |
| 6689 | return ret; |
| 6690 | } |
| 6691 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6692 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6693 | struct nfs_locku_args arg; |
| 6694 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6695 | struct nfs4_lock_state *lsp; |
| 6696 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6697 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6698 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6699 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6700 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6701 | }; |
| 6702 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6703 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6704 | struct nfs_open_context *ctx, |
| 6705 | struct nfs4_lock_state *lsp, |
| 6706 | struct nfs_seqid *seqid) |
| 6707 | { |
| 6708 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6709 | struct nfs4_state *state = lsp->ls_state; |
| 6710 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6711 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6712 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6713 | if (p == NULL) |
| 6714 | return NULL; |
| 6715 | p->arg.fh = NFS_FH(inode); |
| 6716 | p->arg.fl = &p->fl; |
| 6717 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6718 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6719 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6720 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6721 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6722 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6723 | locks_init_lock(&p->fl); |
| 6724 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6725 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6726 | spin_lock(&state->state_lock); |
| 6727 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6728 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6729 | return p; |
| 6730 | } |
| 6731 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6732 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6733 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6734 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6735 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6736 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6737 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6738 | put_nfs_open_context(calldata->ctx); |
| 6739 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6740 | } |
| 6741 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6742 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6743 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6744 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6745 | struct nfs4_exception exception = { |
| 6746 | .inode = calldata->lsp->ls_state->inode, |
| 6747 | .stateid = &calldata->arg.stateid, |
| 6748 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6749 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6750 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6751 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6752 | switch (task->tk_status) { |
| 6753 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6754 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6755 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6756 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6757 | &calldata->res.stateid)) |
| 6758 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6759 | fallthrough; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6760 | case -NFS4ERR_ADMIN_REVOKED: |
| 6761 | case -NFS4ERR_EXPIRED: |
| 6762 | nfs4_free_revoked_stateid(calldata->server, |
| 6763 | &calldata->arg.stateid, |
| 6764 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6765 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6766 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6767 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6768 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6769 | calldata->lsp)) |
| 6770 | rpc_restart_call_prepare(task); |
| 6771 | break; |
| 6772 | case -NFS4ERR_OLD_STATEID: |
| 6773 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6774 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6775 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6776 | break; |
| 6777 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6778 | task->tk_status = nfs4_async_handle_exception(task, |
| 6779 | calldata->server, task->tk_status, |
| 6780 | &exception); |
| 6781 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6782 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6783 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6784 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6785 | } |
| 6786 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6787 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6788 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6789 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6791 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6792 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6793 | return; |
| 6794 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6795 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6796 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6797 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6798 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6799 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6800 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6801 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6802 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6803 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6804 | &calldata->res.seq_res, |
| 6805 | task) != 0) |
| 6806 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6807 | return; |
| 6808 | out_no_action: |
| 6809 | task->tk_action = NULL; |
| 6810 | out_wait: |
| 6811 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6812 | } |
| 6813 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6814 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6815 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6816 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6817 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6818 | }; |
| 6819 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6820 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6821 | struct nfs_open_context *ctx, |
| 6822 | struct nfs4_lock_state *lsp, |
| 6823 | struct nfs_seqid *seqid) |
| 6824 | { |
| 6825 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6826 | struct rpc_message msg = { |
| 6827 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6828 | .rpc_cred = ctx->cred, |
| 6829 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6830 | struct rpc_task_setup task_setup_data = { |
| 6831 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6832 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6833 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6834 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6835 | .flags = RPC_TASK_ASYNC, |
| 6836 | }; |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 6837 | struct nfs_client *client = |
| 6838 | NFS_SERVER(lsp->ls_state->inode)->nfs_client; |
| 6839 | |
| 6840 | if (client->cl_minorversion) |
| 6841 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6842 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6843 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6844 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6845 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6846 | /* Ensure this is an unlock - when canceling a lock, the |
| 6847 | * canceled lock is passed in, and it won't be an unlock. |
| 6848 | */ |
| 6849 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6850 | if (fl->fl_flags & FL_CLOSE) |
| 6851 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6852 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6853 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6854 | if (data == NULL) { |
| 6855 | nfs_free_seqid(seqid); |
| 6856 | return ERR_PTR(-ENOMEM); |
| 6857 | } |
| 6858 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6859 | 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] | 6860 | msg.rpc_argp = &data->arg; |
| 6861 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6862 | task_setup_data.callback_data = data; |
| 6863 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6864 | } |
| 6865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6867 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6868 | struct inode *inode = state->inode; |
| 6869 | struct nfs4_state_owner *sp = state->owner; |
| 6870 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6871 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6872 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6873 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6874 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6875 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6876 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6877 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6878 | status = nfs4_set_lock_state(state, request); |
| 6879 | /* Unlock _before_ we do the RPC call */ |
| 6880 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6881 | /* Exclude nfs_delegation_claim_locks() */ |
| 6882 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6883 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6884 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6885 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6886 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6887 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6888 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6889 | } |
| 6890 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6891 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6892 | if (status != 0) |
| 6893 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6894 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6895 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6896 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6897 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6898 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6899 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6900 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6901 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6902 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6903 | 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] | 6904 | status = PTR_ERR(task); |
| 6905 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6906 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6907 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6908 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6909 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6910 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6911 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6912 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6913 | } |
| 6914 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6915 | struct nfs4_lockdata { |
| 6916 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6917 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6918 | struct nfs4_lock_state *lsp; |
| 6919 | struct nfs_open_context *ctx; |
| 6920 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6921 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6922 | int rpc_status; |
| 6923 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6924 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6925 | }; |
| 6926 | |
| 6927 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6928 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6929 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6930 | { |
| 6931 | struct nfs4_lockdata *p; |
| 6932 | struct inode *inode = lsp->ls_state->inode; |
| 6933 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6934 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6935 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6936 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6937 | if (p == NULL) |
| 6938 | return NULL; |
| 6939 | |
| 6940 | p->arg.fh = NFS_FH(inode); |
| 6941 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6942 | 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] | 6943 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6944 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6945 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6946 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6947 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6948 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6949 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6950 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6951 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6952 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6953 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6954 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6955 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6956 | locks_init_lock(&p->fl); |
| 6957 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6958 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6959 | out_free_seqid: |
| 6960 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6961 | out_free: |
| 6962 | kfree(p); |
| 6963 | return NULL; |
| 6964 | } |
| 6965 | |
| 6966 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6967 | { |
| 6968 | struct nfs4_lockdata *data = calldata; |
| 6969 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6970 | |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6971 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6972 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6973 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6974 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6975 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6976 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6977 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6978 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6979 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6980 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6981 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6982 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6983 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6984 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6985 | &data->lsp->ls_stateid); |
| 6986 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6987 | if (!nfs4_valid_open_stateid(state)) { |
| 6988 | data->rpc_status = -EBADF; |
| 6989 | task->tk_action = NULL; |
| 6990 | goto out_release_open_seqid; |
| 6991 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6992 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6993 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6994 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6995 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6996 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6997 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6998 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6999 | nfs_release_seqid(data->arg.open_seqid); |
| 7000 | out_release_lock_seqid: |
| 7001 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 7002 | out_wait: |
| 7003 | nfs4_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 7004 | dprintk("%s: ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 7005 | } |
| 7006 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7007 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 7008 | { |
| 7009 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7010 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7011 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7012 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 7013 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 7014 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7015 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7016 | switch (task->tk_status) { |
| 7017 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 7018 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7019 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7020 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7021 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7022 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7023 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7024 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7025 | if (data->arg.new_lock_owner != 0) { |
| 7026 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 7027 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 7028 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7029 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 7030 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7031 | break; |
| 7032 | case -NFS4ERR_BAD_STATEID: |
| 7033 | case -NFS4ERR_OLD_STATEID: |
| 7034 | case -NFS4ERR_STALE_STATEID: |
| 7035 | case -NFS4ERR_EXPIRED: |
| 7036 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7037 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7038 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7039 | goto out_restart; |
| 7040 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7041 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7042 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7043 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7044 | out_done: |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 7045 | dprintk("%s: ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7046 | return; |
| 7047 | out_restart: |
| 7048 | if (!data->cancelled) |
| 7049 | rpc_restart_call_prepare(task); |
| 7050 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7051 | } |
| 7052 | |
| 7053 | static void nfs4_lock_release(void *calldata) |
| 7054 | { |
| 7055 | struct nfs4_lockdata *data = calldata; |
| 7056 | |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7057 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7058 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7059 | struct rpc_task *task; |
| 7060 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 7061 | data->arg.lock_seqid); |
| 7062 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7063 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7064 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7065 | } else |
| 7066 | nfs_free_seqid(data->arg.lock_seqid); |
| 7067 | nfs4_put_lock_state(data->lsp); |
| 7068 | put_nfs_open_context(data->ctx); |
| 7069 | kfree(data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7070 | } |
| 7071 | |
| 7072 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 7073 | .rpc_call_prepare = nfs4_lock_prepare, |
| 7074 | .rpc_call_done = nfs4_lock_done, |
| 7075 | .rpc_release = nfs4_lock_release, |
| 7076 | }; |
| 7077 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7078 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 7079 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7080 | switch (error) { |
| 7081 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 7082 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7083 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7084 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7085 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 7086 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7087 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7088 | break; |
| 7089 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7090 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7091 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 7092 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7093 | } |
| 7094 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7095 | 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] | 7096 | { |
| 7097 | struct nfs4_lockdata *data; |
| 7098 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7099 | struct rpc_message msg = { |
| 7100 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 7101 | .rpc_cred = state->owner->so_cred, |
| 7102 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7103 | struct rpc_task_setup task_setup_data = { |
| 7104 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7105 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7106 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 7107 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 7108 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7109 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7110 | int ret; |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 7111 | struct nfs_client *client = NFS_SERVER(state->inode)->nfs_client; |
| 7112 | |
| 7113 | if (client->cl_minorversion) |
| 7114 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7115 | |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7116 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7117 | fl->fl_u.nfs4_fl.owner, |
| 7118 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7119 | if (data == NULL) |
| 7120 | return -ENOMEM; |
| 7121 | if (IS_SETLKW(cmd)) |
| 7122 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7123 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 7124 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 7125 | msg.rpc_argp = &data->arg; |
| 7126 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7127 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7128 | if (recovery_type > NFS_LOCK_NEW) { |
| 7129 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 7130 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7131 | } else |
| 7132 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7133 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 7134 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7135 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 7136 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7137 | if (ret == 0) { |
| 7138 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7139 | if (ret) |
| 7140 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 7141 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7142 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 7143 | data->cancelled = true; |
Dave Wysochanski | 3d1a90a | 2020-12-11 05:12:51 -0500 | [diff] [blame] | 7144 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 7145 | rpc_put_task(task); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 7146 | dprintk("%s: ret = %d\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7147 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7148 | } |
| 7149 | |
| 7150 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 7151 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7152 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7153 | struct nfs4_exception exception = { |
| 7154 | .inode = state->inode, |
| 7155 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7156 | int err; |
| 7157 | |
| 7158 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7159 | /* Cache the lock if possible... */ |
| 7160 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7161 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7162 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 7163 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7164 | break; |
| 7165 | nfs4_handle_exception(server, err, &exception); |
| 7166 | } while (exception.retry); |
| 7167 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7171 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7172 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7173 | struct nfs4_exception exception = { |
| 7174 | .inode = state->inode, |
| 7175 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7176 | int err; |
| 7177 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 7178 | err = nfs4_set_lock_state(state, request); |
| 7179 | if (err != 0) |
| 7180 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 7181 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 7182 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 7183 | return 0; |
| 7184 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7185 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7186 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7187 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7188 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7189 | switch (err) { |
| 7190 | default: |
| 7191 | goto out; |
| 7192 | case -NFS4ERR_GRACE: |
| 7193 | case -NFS4ERR_DELAY: |
| 7194 | nfs4_handle_exception(server, err, &exception); |
| 7195 | err = 0; |
| 7196 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7197 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7198 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7199 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7200 | } |
| 7201 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7202 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7203 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7204 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7205 | struct nfs4_lock_state *lsp; |
| 7206 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7207 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7208 | status = nfs4_set_lock_state(state, request); |
| 7209 | if (status != 0) |
| 7210 | return status; |
| 7211 | lsp = request->fl_u.nfs4_fl.owner; |
| 7212 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7213 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7214 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7215 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7216 | } |
| 7217 | #endif |
| 7218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7219 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7220 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7221 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7222 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7223 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7224 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7225 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7226 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7227 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7228 | if (status < 0) |
| 7229 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7230 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7231 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7232 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7233 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7234 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7235 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7236 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7237 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7238 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7239 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7240 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7241 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7242 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7243 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7244 | out: |
| 7245 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7246 | return status; |
| 7247 | } |
| 7248 | |
| 7249 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7250 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7251 | struct nfs4_exception exception = { |
| 7252 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7253 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7254 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7255 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7256 | int err; |
| 7257 | |
| 7258 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7259 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7260 | if (err == -NFS4ERR_DENIED) |
| 7261 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7262 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7263 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7264 | } while (exception.retry); |
| 7265 | return err; |
| 7266 | } |
| 7267 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7268 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7269 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7270 | |
| 7271 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7272 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7273 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7274 | { |
| 7275 | int status = -ERESTARTSYS; |
| 7276 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7277 | |
| 7278 | while(!signalled()) { |
| 7279 | status = nfs4_proc_setlk(state, cmd, request); |
| 7280 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7281 | break; |
| 7282 | freezable_schedule_timeout_interruptible(timeout); |
| 7283 | timeout *= 2; |
| 7284 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7285 | status = -ERESTARTSYS; |
| 7286 | } |
| 7287 | return status; |
| 7288 | } |
| 7289 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7290 | #ifdef CONFIG_NFS_V4_1 |
| 7291 | struct nfs4_lock_waiter { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7292 | struct inode *inode; |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7293 | struct nfs_lowner owner; |
| 7294 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7295 | }; |
| 7296 | |
| 7297 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7298 | 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] | 7299 | { |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7300 | struct nfs4_lock_waiter *waiter = |
| 7301 | container_of(wait, struct nfs4_lock_waiter, wait); |
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 | /* NULL key means to wake up everyone */ |
| 7304 | if (key) { |
| 7305 | struct cb_notify_lock_args *cbnl = key; |
| 7306 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7307 | *wowner = &waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7308 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7309 | /* Only wake if the callback was for the same owner. */ |
| 7310 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7311 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7312 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7313 | /* Make sure it's for the right inode */ |
| 7314 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7315 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7316 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7317 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7318 | return woken_wake_function(wait, mode, flags, key); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7319 | } |
| 7320 | |
| 7321 | static int |
| 7322 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7323 | { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7324 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7325 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7326 | struct nfs_client *clp = server->nfs_client; |
| 7327 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7328 | struct nfs4_lock_waiter waiter = { |
| 7329 | .inode = state->inode, |
| 7330 | .owner = { .clientid = clp->cl_clientid, |
| 7331 | .id = lsp->ls_seqid.owner_id, |
| 7332 | .s_dev = server->s_dev }, |
| 7333 | }; |
| 7334 | int status; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7335 | |
| 7336 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7337 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7338 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7339 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7340 | init_wait(&waiter.wait); |
| 7341 | waiter.wait.func = nfs4_wake_lock_waiter; |
| 7342 | add_wait_queue(q, &waiter.wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7343 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7344 | do { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7345 | status = nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7346 | if (status != -EAGAIN || IS_SETLK(cmd)) |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7347 | break; |
| 7348 | |
| 7349 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7350 | freezer_do_not_count(); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7351 | wait_woken(&waiter.wait, TASK_INTERRUPTIBLE, |
| 7352 | NFS4_LOCK_MAXTIMEOUT); |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7353 | freezer_count(); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7354 | } while (!signalled()); |
| 7355 | |
| 7356 | remove_wait_queue(q, &waiter.wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7357 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7358 | return status; |
| 7359 | } |
| 7360 | #else /* !CONFIG_NFS_V4_1 */ |
| 7361 | static inline int |
| 7362 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7363 | { |
| 7364 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7365 | } |
| 7366 | #endif |
| 7367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7368 | static int |
| 7369 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7370 | { |
| 7371 | struct nfs_open_context *ctx; |
| 7372 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7373 | int status; |
| 7374 | |
| 7375 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7376 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7377 | state = ctx->state; |
| 7378 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7379 | if (IS_GETLK(cmd)) { |
| 7380 | if (state != NULL) |
| 7381 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7382 | return 0; |
| 7383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7384 | |
| 7385 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7386 | return -EINVAL; |
| 7387 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7388 | if (request->fl_type == F_UNLCK) { |
| 7389 | if (state != NULL) |
| 7390 | return nfs4_proc_unlck(state, cmd, request); |
| 7391 | return 0; |
| 7392 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7393 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7394 | if (state == NULL) |
| 7395 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7396 | |
| 7397 | if ((request->fl_flags & FL_POSIX) && |
| 7398 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7399 | return -ENOLCK; |
| 7400 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7401 | /* |
| 7402 | * Don't rely on the VFS having checked the file open mode, |
| 7403 | * since it won't do this for flock() locks. |
| 7404 | */ |
| 7405 | switch (request->fl_type) { |
| 7406 | case F_RDLCK: |
| 7407 | if (!(filp->f_mode & FMODE_READ)) |
| 7408 | return -EBADF; |
| 7409 | break; |
| 7410 | case F_WRLCK: |
| 7411 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7412 | return -EBADF; |
| 7413 | } |
| 7414 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7415 | status = nfs4_set_lock_state(state, request); |
| 7416 | if (status != 0) |
| 7417 | return status; |
| 7418 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7419 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7420 | } |
| 7421 | |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7422 | static int nfs4_delete_lease(struct file *file, void **priv) |
| 7423 | { |
| 7424 | return generic_setlease(file, F_UNLCK, NULL, priv); |
| 7425 | } |
| 7426 | |
| 7427 | static int nfs4_add_lease(struct file *file, long arg, struct file_lock **lease, |
| 7428 | void **priv) |
| 7429 | { |
| 7430 | struct inode *inode = file_inode(file); |
| 7431 | fmode_t type = arg == F_RDLCK ? FMODE_READ : FMODE_WRITE; |
| 7432 | int ret; |
| 7433 | |
| 7434 | /* No delegation, no lease */ |
| 7435 | if (!nfs4_have_delegation(inode, type)) |
Trond Myklebust | df2c7b9 | 2021-06-25 15:08:39 -0400 | [diff] [blame] | 7436 | return -EAGAIN; |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7437 | ret = generic_setlease(file, arg, lease, priv); |
| 7438 | if (ret || nfs4_have_delegation(inode, type)) |
| 7439 | return ret; |
| 7440 | /* We raced with a delegation return */ |
| 7441 | nfs4_delete_lease(file, priv); |
Trond Myklebust | df2c7b9 | 2021-06-25 15:08:39 -0400 | [diff] [blame] | 7442 | return -EAGAIN; |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | int nfs4_proc_setlease(struct file *file, long arg, struct file_lock **lease, |
| 7446 | void **priv) |
| 7447 | { |
| 7448 | switch (arg) { |
| 7449 | case F_RDLCK: |
| 7450 | case F_WRLCK: |
| 7451 | return nfs4_add_lease(file, arg, lease, priv); |
| 7452 | case F_UNLCK: |
| 7453 | return nfs4_delete_lease(file, priv); |
| 7454 | default: |
| 7455 | return -EINVAL; |
| 7456 | } |
| 7457 | } |
| 7458 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7459 | 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] | 7460 | { |
| 7461 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7462 | int err; |
| 7463 | |
| 7464 | err = nfs4_set_lock_state(state, fl); |
| 7465 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7466 | return err; |
Olga Kornievskaia | 3d7a952 | 2020-08-20 18:52:43 -0400 | [diff] [blame] | 7467 | do { |
| 7468 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
| 7469 | if (err != -NFS4ERR_DELAY) |
| 7470 | break; |
| 7471 | ssleep(1); |
| 7472 | } while (err == -NFS4ERR_DELAY); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7473 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7474 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7475 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7476 | struct nfs_release_lockowner_data { |
| 7477 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7478 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7479 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7480 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7481 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7482 | }; |
| 7483 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7484 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7485 | { |
| 7486 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7487 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7488 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7489 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7490 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7491 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7492 | } |
| 7493 | |
| 7494 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7495 | { |
| 7496 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7497 | struct nfs_server *server = data->server; |
| 7498 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7499 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7500 | |
| 7501 | switch (task->tk_status) { |
| 7502 | case 0: |
| 7503 | renew_lease(server, data->timestamp); |
| 7504 | break; |
| 7505 | case -NFS4ERR_STALE_CLIENTID: |
| 7506 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7507 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7508 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7509 | case -NFS4ERR_LEASE_MOVED: |
| 7510 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7511 | if (nfs4_async_handle_error(task, server, |
| 7512 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7513 | rpc_restart_call_prepare(task); |
| 7514 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7515 | } |
| 7516 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7517 | static void nfs4_release_lockowner_release(void *calldata) |
| 7518 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7519 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7520 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7521 | kfree(calldata); |
| 7522 | } |
| 7523 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7524 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7525 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7526 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7527 | .rpc_release = nfs4_release_lockowner_release, |
| 7528 | }; |
| 7529 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7530 | static void |
| 7531 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7532 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7533 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7534 | struct rpc_message msg = { |
| 7535 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7536 | }; |
| 7537 | |
| 7538 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7539 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7540 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7541 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7542 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7543 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7544 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7545 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7546 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7547 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7548 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7549 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7550 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7551 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7552 | 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] | 7553 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7554 | } |
| 7555 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7556 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7557 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7558 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7559 | struct user_namespace *mnt_userns, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7560 | struct dentry *unused, struct inode *inode, |
| 7561 | const char *key, const void *buf, |
| 7562 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7563 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7564 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7565 | } |
| 7566 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7567 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7568 | struct dentry *unused, struct inode *inode, |
| 7569 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7570 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7571 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7572 | } |
| 7573 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7574 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7575 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7576 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7577 | } |
| 7578 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7579 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7580 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7581 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7582 | struct user_namespace *mnt_userns, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7583 | struct dentry *unused, struct inode *inode, |
| 7584 | const char *key, const void *buf, |
| 7585 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7586 | { |
| 7587 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7588 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7589 | |
| 7590 | return -EOPNOTSUPP; |
| 7591 | } |
| 7592 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7593 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7594 | struct dentry *unused, struct inode *inode, |
| 7595 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7596 | { |
| 7597 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7598 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7599 | return -EOPNOTSUPP; |
| 7600 | } |
| 7601 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7602 | static ssize_t |
| 7603 | 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] | 7604 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7605 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7606 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7607 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7608 | len = security_inode_listsecurity(inode, list, list_len); |
Chengguang Xu | 82c596e | 2020-06-17 09:09:39 +0800 | [diff] [blame] | 7609 | if (len >= 0 && list_len && len > list_len) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7610 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7611 | } |
| 7612 | return len; |
| 7613 | } |
| 7614 | |
| 7615 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7616 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7617 | .get = nfs4_xattr_get_nfs4_label, |
| 7618 | .set = nfs4_xattr_set_nfs4_label, |
| 7619 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7620 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7621 | #else |
| 7622 | |
| 7623 | static ssize_t |
| 7624 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7625 | { |
| 7626 | return 0; |
| 7627 | } |
| 7628 | |
| 7629 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7630 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7631 | #ifdef CONFIG_NFS_V4_2 |
| 7632 | static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7633 | struct user_namespace *mnt_userns, |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7634 | struct dentry *unused, struct inode *inode, |
| 7635 | const char *key, const void *buf, |
| 7636 | size_t buflen, int flags) |
| 7637 | { |
| 7638 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7639 | int ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7640 | |
| 7641 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7642 | return -EOPNOTSUPP; |
| 7643 | |
| 7644 | /* |
| 7645 | * There is no mapping from the MAY_* flags to the NFS_ACCESS_XA* |
| 7646 | * flags right now. Handling of xattr operations use the normal |
| 7647 | * file read/write permissions. |
| 7648 | * |
| 7649 | * Just in case the server has other ideas (which RFC 8276 allows), |
| 7650 | * do a cached access check for the XA* flags to possibly avoid |
| 7651 | * doing an RPC and getting EACCES back. |
| 7652 | */ |
| 7653 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7654 | if (!(cache.mask & NFS_ACCESS_XAWRITE)) |
| 7655 | return -EACCES; |
| 7656 | } |
| 7657 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7658 | if (buf == NULL) { |
| 7659 | ret = nfs42_proc_removexattr(inode, key); |
| 7660 | if (!ret) |
| 7661 | nfs4_xattr_cache_remove(inode, key); |
| 7662 | } else { |
| 7663 | ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags); |
| 7664 | if (!ret) |
| 7665 | nfs4_xattr_cache_add(inode, key, buf, NULL, buflen); |
| 7666 | } |
| 7667 | |
| 7668 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7669 | } |
| 7670 | |
| 7671 | static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler, |
| 7672 | struct dentry *unused, struct inode *inode, |
| 7673 | const char *key, void *buf, size_t buflen) |
| 7674 | { |
| 7675 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7676 | ssize_t ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7677 | |
| 7678 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7679 | return -EOPNOTSUPP; |
| 7680 | |
| 7681 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7682 | if (!(cache.mask & NFS_ACCESS_XAREAD)) |
| 7683 | return -EACCES; |
| 7684 | } |
| 7685 | |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 7686 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7687 | if (ret) |
| 7688 | return ret; |
| 7689 | |
| 7690 | ret = nfs4_xattr_cache_get(inode, key, buf, buflen); |
| 7691 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7692 | return ret; |
| 7693 | |
| 7694 | ret = nfs42_proc_getxattr(inode, key, buf, buflen); |
| 7695 | |
| 7696 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7697 | } |
| 7698 | |
| 7699 | static ssize_t |
| 7700 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7701 | { |
| 7702 | u64 cookie; |
| 7703 | bool eof; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7704 | ssize_t ret, size; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7705 | char *buf; |
| 7706 | size_t buflen; |
| 7707 | struct nfs_access_entry cache; |
| 7708 | |
| 7709 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7710 | return 0; |
| 7711 | |
| 7712 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7713 | if (!(cache.mask & NFS_ACCESS_XALIST)) |
| 7714 | return 0; |
| 7715 | } |
| 7716 | |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 7717 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7718 | if (ret) |
| 7719 | return ret; |
| 7720 | |
| 7721 | ret = nfs4_xattr_cache_list(inode, list, list_len); |
| 7722 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7723 | return ret; |
| 7724 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7725 | cookie = 0; |
| 7726 | eof = false; |
| 7727 | buflen = list_len ? list_len : XATTR_LIST_MAX; |
| 7728 | buf = list_len ? list : NULL; |
| 7729 | size = 0; |
| 7730 | |
| 7731 | while (!eof) { |
| 7732 | ret = nfs42_proc_listxattrs(inode, buf, buflen, |
| 7733 | &cookie, &eof); |
| 7734 | if (ret < 0) |
| 7735 | return ret; |
| 7736 | |
| 7737 | if (list_len) { |
| 7738 | buf += ret; |
| 7739 | buflen -= ret; |
| 7740 | } |
| 7741 | size += ret; |
| 7742 | } |
| 7743 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7744 | if (list_len) |
| 7745 | nfs4_xattr_cache_set_list(inode, list, size); |
| 7746 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7747 | return size; |
| 7748 | } |
| 7749 | |
| 7750 | #else |
| 7751 | |
| 7752 | static ssize_t |
| 7753 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7754 | { |
| 7755 | return 0; |
| 7756 | } |
| 7757 | #endif /* CONFIG_NFS_V4_2 */ |
| 7758 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7759 | /* |
| 7760 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7761 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7762 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7763 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7764 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7765 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7766 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7767 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7768 | return; |
| 7769 | |
| 7770 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7771 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7772 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7773 | fattr->nlink = 2; |
| 7774 | } |
| 7775 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7776 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7777 | const struct qstr *name, |
| 7778 | struct nfs4_fs_locations *fs_locations, |
| 7779 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7780 | { |
| 7781 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7782 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7783 | struct nfs4_fs_locations_arg args = { |
| 7784 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7785 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7786 | .page = page, |
| 7787 | .bitmask = bitmask, |
| 7788 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7789 | struct nfs4_fs_locations_res res = { |
| 7790 | .fs_locations = fs_locations, |
| 7791 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7792 | struct rpc_message msg = { |
| 7793 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7794 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7795 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7796 | }; |
| 7797 | int status; |
| 7798 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7799 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7800 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7801 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7802 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7803 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7804 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7805 | * is not supported */ |
| 7806 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7807 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7808 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7809 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7810 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7811 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7812 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7813 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7814 | 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] | 7815 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7816 | return status; |
| 7817 | } |
| 7818 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7819 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7820 | const struct qstr *name, |
| 7821 | struct nfs4_fs_locations *fs_locations, |
| 7822 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7823 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7824 | struct nfs4_exception exception = { |
| 7825 | .interruptible = true, |
| 7826 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7827 | int err; |
| 7828 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7829 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7830 | fs_locations, page); |
| 7831 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7832 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7833 | &exception); |
| 7834 | } while (exception.retry); |
| 7835 | return err; |
| 7836 | } |
| 7837 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7838 | /* |
| 7839 | * This operation also signals the server that this client is |
| 7840 | * performing migration recovery. The server can stop returning |
| 7841 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7842 | * appended to this compound to identify the client ID which is |
| 7843 | * performing recovery. |
| 7844 | */ |
| 7845 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7846 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7847 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7848 | { |
| 7849 | struct nfs_server *server = NFS_SERVER(inode); |
| 7850 | struct rpc_clnt *clnt = server->client; |
| 7851 | u32 bitmask[2] = { |
| 7852 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7853 | }; |
| 7854 | struct nfs4_fs_locations_arg args = { |
| 7855 | .clientid = server->nfs_client->cl_clientid, |
| 7856 | .fh = NFS_FH(inode), |
| 7857 | .page = page, |
| 7858 | .bitmask = bitmask, |
| 7859 | .migration = 1, /* skip LOOKUP */ |
| 7860 | .renew = 1, /* append RENEW */ |
| 7861 | }; |
| 7862 | struct nfs4_fs_locations_res res = { |
| 7863 | .fs_locations = locations, |
| 7864 | .migration = 1, |
| 7865 | .renew = 1, |
| 7866 | }; |
| 7867 | struct rpc_message msg = { |
| 7868 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7869 | .rpc_argp = &args, |
| 7870 | .rpc_resp = &res, |
| 7871 | .rpc_cred = cred, |
| 7872 | }; |
| 7873 | unsigned long now = jiffies; |
| 7874 | int status; |
| 7875 | |
| 7876 | nfs_fattr_init(&locations->fattr); |
| 7877 | locations->server = server; |
| 7878 | locations->nlocations = 0; |
| 7879 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7880 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7881 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7882 | &args.seq_args, &res.seq_res); |
| 7883 | if (status) |
| 7884 | return status; |
| 7885 | |
| 7886 | renew_lease(server, now); |
| 7887 | return 0; |
| 7888 | } |
| 7889 | |
| 7890 | #ifdef CONFIG_NFS_V4_1 |
| 7891 | |
| 7892 | /* |
| 7893 | * This operation also signals the server that this client is |
| 7894 | * performing migration recovery. The server can stop asserting |
| 7895 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7896 | * performing this operation is identified in the SEQUENCE |
| 7897 | * operation in this compound. |
| 7898 | * |
| 7899 | * When the client supports GETATTR(fs_locations_info), it can |
| 7900 | * be plumbed in here. |
| 7901 | */ |
| 7902 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7903 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7904 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7905 | { |
| 7906 | struct nfs_server *server = NFS_SERVER(inode); |
| 7907 | struct rpc_clnt *clnt = server->client; |
| 7908 | u32 bitmask[2] = { |
| 7909 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7910 | }; |
| 7911 | struct nfs4_fs_locations_arg args = { |
| 7912 | .fh = NFS_FH(inode), |
| 7913 | .page = page, |
| 7914 | .bitmask = bitmask, |
| 7915 | .migration = 1, /* skip LOOKUP */ |
| 7916 | }; |
| 7917 | struct nfs4_fs_locations_res res = { |
| 7918 | .fs_locations = locations, |
| 7919 | .migration = 1, |
| 7920 | }; |
| 7921 | struct rpc_message msg = { |
| 7922 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7923 | .rpc_argp = &args, |
| 7924 | .rpc_resp = &res, |
| 7925 | .rpc_cred = cred, |
| 7926 | }; |
| 7927 | int status; |
| 7928 | |
| 7929 | nfs_fattr_init(&locations->fattr); |
| 7930 | locations->server = server; |
| 7931 | locations->nlocations = 0; |
| 7932 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7933 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7934 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7935 | &args.seq_args, &res.seq_res); |
| 7936 | if (status == NFS4_OK && |
| 7937 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7938 | status = -NFS4ERR_LEASE_MOVED; |
| 7939 | return status; |
| 7940 | } |
| 7941 | |
| 7942 | #endif /* CONFIG_NFS_V4_1 */ |
| 7943 | |
| 7944 | /** |
| 7945 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7946 | * @inode: inode on FSID that is migrating |
| 7947 | * @locations: result of query |
| 7948 | * @page: buffer |
| 7949 | * @cred: credential to use for this operation |
| 7950 | * |
| 7951 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7952 | * operation failed, or a negative errno if a local error occurred. |
| 7953 | * |
| 7954 | * On success, "locations" is filled in, but if the server has |
| 7955 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7956 | * asserted. |
| 7957 | * |
| 7958 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7959 | * from this client that require migration recovery. |
| 7960 | */ |
| 7961 | int nfs4_proc_get_locations(struct inode *inode, |
| 7962 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7963 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7964 | { |
| 7965 | struct nfs_server *server = NFS_SERVER(inode); |
| 7966 | struct nfs_client *clp = server->nfs_client; |
| 7967 | const struct nfs4_mig_recovery_ops *ops = |
| 7968 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7969 | struct nfs4_exception exception = { |
| 7970 | .interruptible = true, |
| 7971 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7972 | int status; |
| 7973 | |
| 7974 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7975 | (unsigned long long)server->fsid.major, |
| 7976 | (unsigned long long)server->fsid.minor, |
| 7977 | clp->cl_hostname); |
| 7978 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7979 | |
| 7980 | do { |
| 7981 | status = ops->get_locations(inode, locations, page, cred); |
| 7982 | if (status != -NFS4ERR_DELAY) |
| 7983 | break; |
| 7984 | nfs4_handle_exception(server, status, &exception); |
| 7985 | } while (exception.retry); |
| 7986 | return status; |
| 7987 | } |
| 7988 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7989 | /* |
| 7990 | * This operation also signals the server that this client is |
| 7991 | * performing "lease moved" recovery. The server can stop |
| 7992 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7993 | * is appended to this compound to identify the client ID which is |
| 7994 | * performing recovery. |
| 7995 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7996 | 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] | 7997 | { |
| 7998 | struct nfs_server *server = NFS_SERVER(inode); |
| 7999 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 8000 | struct rpc_clnt *clnt = server->client; |
| 8001 | struct nfs4_fsid_present_arg args = { |
| 8002 | .fh = NFS_FH(inode), |
| 8003 | .clientid = clp->cl_clientid, |
| 8004 | .renew = 1, /* append RENEW */ |
| 8005 | }; |
| 8006 | struct nfs4_fsid_present_res res = { |
| 8007 | .renew = 1, |
| 8008 | }; |
| 8009 | struct rpc_message msg = { |
| 8010 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 8011 | .rpc_argp = &args, |
| 8012 | .rpc_resp = &res, |
| 8013 | .rpc_cred = cred, |
| 8014 | }; |
| 8015 | unsigned long now = jiffies; |
| 8016 | int status; |
| 8017 | |
| 8018 | res.fh = nfs_alloc_fhandle(); |
| 8019 | if (res.fh == NULL) |
| 8020 | return -ENOMEM; |
| 8021 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8022 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8023 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 8024 | &args.seq_args, &res.seq_res); |
| 8025 | nfs_free_fhandle(res.fh); |
| 8026 | if (status) |
| 8027 | return status; |
| 8028 | |
| 8029 | do_renew_lease(clp, now); |
| 8030 | return 0; |
| 8031 | } |
| 8032 | |
| 8033 | #ifdef CONFIG_NFS_V4_1 |
| 8034 | |
| 8035 | /* |
| 8036 | * This operation also signals the server that this client is |
| 8037 | * performing "lease moved" recovery. The server can stop asserting |
| 8038 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 8039 | * this operation is identified in the SEQUENCE operation in this |
| 8040 | * compound. |
| 8041 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8042 | 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] | 8043 | { |
| 8044 | struct nfs_server *server = NFS_SERVER(inode); |
| 8045 | struct rpc_clnt *clnt = server->client; |
| 8046 | struct nfs4_fsid_present_arg args = { |
| 8047 | .fh = NFS_FH(inode), |
| 8048 | }; |
| 8049 | struct nfs4_fsid_present_res res = { |
| 8050 | }; |
| 8051 | struct rpc_message msg = { |
| 8052 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 8053 | .rpc_argp = &args, |
| 8054 | .rpc_resp = &res, |
| 8055 | .rpc_cred = cred, |
| 8056 | }; |
| 8057 | int status; |
| 8058 | |
| 8059 | res.fh = nfs_alloc_fhandle(); |
| 8060 | if (res.fh == NULL) |
| 8061 | return -ENOMEM; |
| 8062 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8063 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8064 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 8065 | &args.seq_args, &res.seq_res); |
| 8066 | nfs_free_fhandle(res.fh); |
| 8067 | if (status == NFS4_OK && |
| 8068 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 8069 | status = -NFS4ERR_LEASE_MOVED; |
| 8070 | return status; |
| 8071 | } |
| 8072 | |
| 8073 | #endif /* CONFIG_NFS_V4_1 */ |
| 8074 | |
| 8075 | /** |
| 8076 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 8077 | * @inode: inode on FSID to check |
| 8078 | * @cred: credential to use for this operation |
| 8079 | * |
| 8080 | * Server indicates whether the FSID is present, moved, or not |
| 8081 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 8082 | * condition for this client ID. |
| 8083 | * |
| 8084 | * Returns NFS4_OK if the FSID is present on this server, |
| 8085 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 8086 | * NFS4ERR code if some error occurred on the server, or a |
| 8087 | * negative errno if a local failure occurred. |
| 8088 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8089 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8090 | { |
| 8091 | struct nfs_server *server = NFS_SERVER(inode); |
| 8092 | struct nfs_client *clp = server->nfs_client; |
| 8093 | const struct nfs4_mig_recovery_ops *ops = |
| 8094 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8095 | struct nfs4_exception exception = { |
| 8096 | .interruptible = true, |
| 8097 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8098 | int status; |
| 8099 | |
| 8100 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 8101 | (unsigned long long)server->fsid.major, |
| 8102 | (unsigned long long)server->fsid.minor, |
| 8103 | clp->cl_hostname); |
| 8104 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 8105 | |
| 8106 | do { |
| 8107 | status = ops->fsid_present(inode, cred); |
| 8108 | if (status != -NFS4ERR_DELAY) |
| 8109 | break; |
| 8110 | nfs4_handle_exception(server, status, &exception); |
| 8111 | } while (exception.retry); |
| 8112 | return status; |
| 8113 | } |
| 8114 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 8115 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8116 | * If 'use_integrity' is true and the state managment nfs_client |
| 8117 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 8118 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 8119 | * Considerations sections. Otherwise, just use the user cred with the |
| 8120 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 8121 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8122 | 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] | 8123 | { |
| 8124 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8125 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 8126 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8127 | struct nfs4_secinfo_arg args = { |
| 8128 | .dir_fh = NFS_FH(dir), |
| 8129 | .name = name, |
| 8130 | }; |
| 8131 | struct nfs4_secinfo_res res = { |
| 8132 | .flavors = flavors, |
| 8133 | }; |
| 8134 | struct rpc_message msg = { |
| 8135 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 8136 | .rpc_argp = &args, |
| 8137 | .rpc_resp = &res, |
| 8138 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8139 | struct nfs4_call_sync_data data = { |
| 8140 | .seq_server = NFS_SERVER(dir), |
| 8141 | .seq_args = &args.seq_args, |
| 8142 | .seq_res = &res.seq_res, |
| 8143 | }; |
| 8144 | struct rpc_task_setup task_setup = { |
| 8145 | .rpc_client = clnt, |
| 8146 | .rpc_message = &msg, |
| 8147 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 8148 | .callback_data = &data, |
| 8149 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 8150 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8151 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8152 | |
| 8153 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8154 | clnt = clp->cl_rpcclient; |
| 8155 | task_setup.rpc_client = clnt; |
| 8156 | |
| 8157 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8158 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8159 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8160 | |
| 8161 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8162 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8163 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 8164 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 8165 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8166 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8167 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8168 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8169 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8170 | return status; |
| 8171 | } |
| 8172 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 8173 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 8174 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8175 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8176 | struct nfs4_exception exception = { |
| 8177 | .interruptible = true, |
| 8178 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8179 | int err; |
| 8180 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8181 | err = -NFS4ERR_WRONGSEC; |
| 8182 | |
| 8183 | /* try to use integrity protection with machine cred */ |
| 8184 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 8185 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 8186 | |
| 8187 | /* |
| 8188 | * if unable to use integrity protection, or SECINFO with |
| 8189 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8190 | * disallowed by spec, but exists in deployed servers) use |
| 8191 | * the current filesystem's rpc_client and the user cred. |
| 8192 | */ |
| 8193 | if (err == -NFS4ERR_WRONGSEC) |
| 8194 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 8195 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 8196 | trace_nfs4_secinfo(dir, name, err); |
| 8197 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8198 | &exception); |
| 8199 | } while (exception.retry); |
| 8200 | return err; |
| 8201 | } |
| 8202 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8203 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8204 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8205 | * Check the exchange flags returned by the server for invalid flags, having |
| 8206 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 8207 | * DS flags set. |
| 8208 | */ |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8209 | static int nfs4_check_cl_exchange_flags(u32 flags, u32 version) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8210 | { |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8211 | if (version >= 2 && (flags & ~EXCHGID4_2_FLAG_MASK_R)) |
| 8212 | goto out_inval; |
| 8213 | else if (version < 2 && (flags & ~EXCHGID4_FLAG_MASK_R)) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8214 | goto out_inval; |
| 8215 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 8216 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 8217 | goto out_inval; |
| 8218 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 8219 | goto out_inval; |
| 8220 | return NFS_OK; |
| 8221 | out_inval: |
| 8222 | return -NFS4ERR_INVAL; |
| 8223 | } |
| 8224 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8225 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 8226 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 8227 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8228 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 8229 | if (a->server_scope_sz != b->server_scope_sz) |
| 8230 | return false; |
| 8231 | 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] | 8232 | } |
| 8233 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8234 | static void |
| 8235 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 8236 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8237 | 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] | 8238 | 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] | 8239 | struct nfs_client *clp = args->client; |
| 8240 | |
| 8241 | switch (task->tk_status) { |
| 8242 | case -NFS4ERR_BADSESSION: |
| 8243 | case -NFS4ERR_DEADSESSION: |
| 8244 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8245 | task->tk_status); |
| 8246 | } |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8247 | if (args->dir == NFS4_CDFC4_FORE_OR_BOTH && |
| 8248 | res->dir != NFS4_CDFS4_BOTH) { |
| 8249 | rpc_task_close_connection(task); |
| 8250 | if (args->retries++ < MAX_BIND_CONN_TO_SESSION_RETRIES) |
| 8251 | rpc_restart_call(task); |
| 8252 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8253 | } |
| 8254 | |
| 8255 | 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] | 8256 | .rpc_call_done = nfs4_bind_one_conn_to_session_done, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8257 | }; |
| 8258 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8259 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8260 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8261 | * |
| 8262 | * The 4.1 client currently uses the same TCP connection for the |
| 8263 | * fore and backchannel. |
| 8264 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8265 | static |
| 8266 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 8267 | struct rpc_xprt *xprt, |
| 8268 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8269 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8270 | { |
| 8271 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8272 | struct nfs41_bind_conn_to_session_args args = { |
| 8273 | .client = clp, |
| 8274 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8275 | .retries = 0, |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8276 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8277 | struct nfs41_bind_conn_to_session_res res; |
| 8278 | struct rpc_message msg = { |
| 8279 | .rpc_proc = |
| 8280 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8281 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8282 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 8283 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8284 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8285 | struct rpc_task_setup task_setup_data = { |
| 8286 | .rpc_client = clnt, |
| 8287 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8288 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8289 | .rpc_message = &msg, |
| 8290 | .flags = RPC_TASK_TIMEOUT, |
| 8291 | }; |
| 8292 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8293 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8294 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 8295 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 8296 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8297 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8298 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 8299 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 8300 | args.dir = NFS4_CDFC4_FORE; |
| 8301 | |
| 8302 | task = rpc_run_task(&task_setup_data); |
| 8303 | if (!IS_ERR(task)) { |
| 8304 | status = task->tk_status; |
| 8305 | rpc_put_task(task); |
| 8306 | } else |
| 8307 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8308 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8309 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8310 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8311 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 8312 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8313 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8314 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8315 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8316 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 8317 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8318 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8319 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8320 | 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] | 8321 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 8322 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8323 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8324 | } |
| 8325 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8326 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8327 | return status; |
| 8328 | } |
| 8329 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8330 | struct rpc_bind_conn_calldata { |
| 8331 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8332 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8333 | }; |
| 8334 | |
| 8335 | static int |
| 8336 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 8337 | struct rpc_xprt *xprt, |
| 8338 | void *calldata) |
| 8339 | { |
| 8340 | struct rpc_bind_conn_calldata *p = calldata; |
| 8341 | |
| 8342 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 8343 | } |
| 8344 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8345 | 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] | 8346 | { |
| 8347 | struct rpc_bind_conn_calldata data = { |
| 8348 | .clp = clp, |
| 8349 | .cred = cred, |
| 8350 | }; |
| 8351 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 8352 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 8353 | } |
| 8354 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8355 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8356 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 8357 | * 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] | 8358 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8359 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 8360 | .how = SP4_MACH_CRED, |
| 8361 | .enforce.u.words = { |
| 8362 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8363 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8364 | 1 << (OP_CREATE_SESSION - 32) | |
| 8365 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8366 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8367 | }, |
| 8368 | .allow.u.words = { |
| 8369 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8370 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8371 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8372 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8373 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8374 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8375 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8376 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8377 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8378 | 1 << (OP_FREE_STATEID - 32) | |
| 8379 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8380 | } |
| 8381 | }; |
| 8382 | |
| 8383 | /* |
| 8384 | * Select the state protection mode for client `clp' given the server results |
| 8385 | * from exchange_id in `sp'. |
| 8386 | * |
| 8387 | * Returns 0 on success, negative errno otherwise. |
| 8388 | */ |
| 8389 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8390 | struct nfs41_state_protection *sp) |
| 8391 | { |
| 8392 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8393 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8394 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8395 | 1 << (OP_CREATE_SESSION - 32) | |
| 8396 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8397 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8398 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8399 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8400 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8401 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8402 | |
| 8403 | if (sp->how == SP4_MACH_CRED) { |
| 8404 | /* Print state protect result */ |
| 8405 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8406 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8407 | if (test_bit(i, sp->enforce.u.longs)) |
| 8408 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8409 | if (test_bit(i, sp->allow.u.longs)) |
| 8410 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8411 | } |
| 8412 | |
| 8413 | /* make sure nothing is on enforce list that isn't supported */ |
| 8414 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8415 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8416 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8417 | ret = -EINVAL; |
| 8418 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8419 | } |
| 8420 | } |
| 8421 | |
| 8422 | /* |
| 8423 | * Minimal mode - state operations are allowed to use machine |
| 8424 | * credential. Note this already happens by default, so the |
| 8425 | * client doesn't have to do anything more than the negotiation. |
| 8426 | * |
| 8427 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8428 | * we're already using the machine cred for exchange_id |
| 8429 | * and will never use a different cred. |
| 8430 | */ |
| 8431 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8432 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8433 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8434 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8435 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8436 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8437 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8438 | } else { |
| 8439 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8440 | ret = -EINVAL; |
| 8441 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8442 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8443 | |
| 8444 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8445 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8446 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8447 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8448 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8449 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8450 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8451 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8452 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8453 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8454 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8455 | } |
| 8456 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8457 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8458 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8459 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8460 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8461 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8462 | |
| 8463 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8464 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8465 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8466 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8467 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8468 | |
| 8469 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8470 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8471 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8472 | } |
| 8473 | |
| 8474 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8475 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8476 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8477 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8478 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8479 | out: |
| 8480 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8481 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8482 | } |
| 8483 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8484 | struct nfs41_exchange_id_data { |
| 8485 | struct nfs41_exchange_id_res res; |
| 8486 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8487 | }; |
| 8488 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8489 | static void nfs4_exchange_id_release(void *data) |
| 8490 | { |
| 8491 | struct nfs41_exchange_id_data *cdata = |
| 8492 | (struct nfs41_exchange_id_data *)data; |
| 8493 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8494 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8495 | kfree(cdata->res.impl_id); |
| 8496 | kfree(cdata->res.server_scope); |
| 8497 | kfree(cdata->res.server_owner); |
| 8498 | kfree(cdata); |
| 8499 | } |
| 8500 | |
| 8501 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8502 | .rpc_release = nfs4_exchange_id_release, |
| 8503 | }; |
| 8504 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8505 | /* |
| 8506 | * _nfs4_proc_exchange_id() |
| 8507 | * |
| 8508 | * Wrapper for EXCHANGE_ID operation. |
| 8509 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8510 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8511 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8512 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8513 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8514 | struct rpc_message msg = { |
| 8515 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8516 | .rpc_cred = cred, |
| 8517 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8518 | struct rpc_task_setup task_setup_data = { |
| 8519 | .rpc_client = clp->cl_rpcclient, |
| 8520 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8521 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8522 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8523 | }; |
| 8524 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8525 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8526 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8527 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8528 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8529 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8530 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8531 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8532 | if (!calldata) |
| 8533 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8534 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8535 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8536 | |
| 8537 | status = nfs4_init_uniform_client_string(clp); |
| 8538 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8539 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8540 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8541 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8542 | GFP_NOFS); |
| 8543 | status = -ENOMEM; |
| 8544 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8545 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8546 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8547 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8548 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8549 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8550 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8551 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8552 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8553 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8554 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8555 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8556 | switch (sp4_how) { |
| 8557 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8558 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8559 | break; |
| 8560 | |
| 8561 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8562 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8563 | break; |
| 8564 | |
| 8565 | default: |
| 8566 | /* unsupported! */ |
| 8567 | WARN_ON_ONCE(1); |
| 8568 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8569 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8570 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8571 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8572 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8573 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8574 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8575 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8576 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8577 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8578 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8579 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8580 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8581 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8582 | #endif |
| 8583 | msg.rpc_argp = &calldata->args; |
| 8584 | msg.rpc_resp = &calldata->res; |
| 8585 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8586 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8587 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8588 | |
| 8589 | out_impl_id: |
| 8590 | kfree(calldata->res.impl_id); |
| 8591 | out_server_scope: |
| 8592 | kfree(calldata->res.server_scope); |
| 8593 | out_server_owner: |
| 8594 | kfree(calldata->res.server_owner); |
| 8595 | out_calldata: |
| 8596 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8597 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8598 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8599 | return ERR_PTR(status); |
| 8600 | } |
| 8601 | |
| 8602 | /* |
| 8603 | * _nfs4_proc_exchange_id() |
| 8604 | * |
| 8605 | * Wrapper for EXCHANGE_ID operation. |
| 8606 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8607 | 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] | 8608 | u32 sp4_how) |
| 8609 | { |
| 8610 | struct rpc_task *task; |
| 8611 | struct nfs41_exchange_id_args *argp; |
| 8612 | struct nfs41_exchange_id_res *resp; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8613 | unsigned long now = jiffies; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8614 | int status; |
| 8615 | |
| 8616 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8617 | if (IS_ERR(task)) |
| 8618 | return PTR_ERR(task); |
| 8619 | |
| 8620 | argp = task->tk_msg.rpc_argp; |
| 8621 | resp = task->tk_msg.rpc_resp; |
| 8622 | status = task->tk_status; |
| 8623 | if (status != 0) |
| 8624 | goto out; |
| 8625 | |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8626 | status = nfs4_check_cl_exchange_flags(resp->flags, |
| 8627 | clp->cl_mvops->minor_version); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8628 | if (status != 0) |
| 8629 | goto out; |
| 8630 | |
| 8631 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8632 | if (status != 0) |
| 8633 | goto out; |
| 8634 | |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8635 | do_renew_lease(clp, now); |
| 8636 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8637 | clp->cl_clientid = resp->clientid; |
| 8638 | clp->cl_exchange_flags = resp->flags; |
| 8639 | clp->cl_seqid = resp->seqid; |
| 8640 | /* Client ID is not confirmed */ |
| 8641 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8642 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8643 | &clp->cl_session->session_state); |
| 8644 | |
| 8645 | if (clp->cl_serverscope != NULL && |
| 8646 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8647 | resp->server_scope)) { |
| 8648 | dprintk("%s: server_scope mismatch detected\n", |
| 8649 | __func__); |
| 8650 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8651 | } |
| 8652 | |
| 8653 | swap(clp->cl_serverowner, resp->server_owner); |
| 8654 | swap(clp->cl_serverscope, resp->server_scope); |
| 8655 | swap(clp->cl_implid, resp->impl_id); |
| 8656 | |
| 8657 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8658 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8659 | sizeof(clp->cl_confirm.data)); |
| 8660 | out: |
| 8661 | trace_nfs4_exchange_id(clp, status); |
| 8662 | rpc_put_task(task); |
| 8663 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8664 | } |
| 8665 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8666 | /* |
| 8667 | * nfs4_proc_exchange_id() |
| 8668 | * |
| 8669 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8670 | * |
| 8671 | * Since the clientid has expired, all compounds using sessions |
| 8672 | * associated with the stale clientid will be returning |
| 8673 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8674 | * be in some phase of session reset. |
| 8675 | * |
| 8676 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8677 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8678 | 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] | 8679 | { |
| 8680 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8681 | int status; |
| 8682 | |
| 8683 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8684 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8685 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8686 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8687 | if (!status) |
| 8688 | return 0; |
| 8689 | } |
| 8690 | |
| 8691 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8692 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8693 | } |
| 8694 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8695 | /** |
| 8696 | * nfs4_test_session_trunk |
| 8697 | * |
| 8698 | * This is an add_xprt_test() test function called from |
| 8699 | * rpc_clnt_setup_test_and_add_xprt. |
| 8700 | * |
| 8701 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8702 | * and is dereferrenced in nfs4_exchange_id_release |
| 8703 | * |
| 8704 | * Upon success, add the new transport to the rpc_clnt |
| 8705 | * |
| 8706 | * @clnt: struct rpc_clnt to get new transport |
| 8707 | * @xprt: the rpc_xprt to test |
| 8708 | * @data: call data for _nfs4_proc_exchange_id. |
| 8709 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8710 | 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] | 8711 | void *data) |
| 8712 | { |
| 8713 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8714 | struct rpc_task *task; |
| 8715 | int status; |
| 8716 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8717 | u32 sp4_how; |
| 8718 | |
| 8719 | dprintk("--> %s try %s\n", __func__, |
| 8720 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8721 | |
| 8722 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8723 | |
| 8724 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8725 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8726 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8727 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8728 | |
| 8729 | status = task->tk_status; |
| 8730 | if (status == 0) |
| 8731 | status = nfs4_detect_session_trunking(adata->clp, |
| 8732 | task->tk_msg.rpc_resp, xprt); |
| 8733 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8734 | if (status == 0) |
| 8735 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8736 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8737 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8738 | } |
| 8739 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8740 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8741 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8742 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8743 | { |
| 8744 | struct rpc_message msg = { |
| 8745 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8746 | .rpc_argp = clp, |
| 8747 | .rpc_cred = cred, |
| 8748 | }; |
| 8749 | int status; |
| 8750 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8751 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8752 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8753 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8754 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8755 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8756 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8757 | return status; |
| 8758 | } |
| 8759 | |
| 8760 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8761 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8762 | { |
| 8763 | unsigned int loop; |
| 8764 | int ret; |
| 8765 | |
| 8766 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8767 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8768 | switch (ret) { |
| 8769 | case -NFS4ERR_DELAY: |
| 8770 | case -NFS4ERR_CLIENTID_BUSY: |
| 8771 | ssleep(1); |
| 8772 | break; |
| 8773 | default: |
| 8774 | return ret; |
| 8775 | } |
| 8776 | } |
| 8777 | return 0; |
| 8778 | } |
| 8779 | |
| 8780 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8781 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8782 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8783 | int ret = 0; |
| 8784 | |
| 8785 | if (clp->cl_mvops->minor_version < 1) |
| 8786 | goto out; |
| 8787 | if (clp->cl_exchange_flags == 0) |
| 8788 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8789 | if (clp->cl_preserve_clid) |
| 8790 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8791 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8792 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8793 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8794 | switch (ret) { |
| 8795 | case 0: |
| 8796 | case -NFS4ERR_STALE_CLIENTID: |
| 8797 | clp->cl_exchange_flags = 0; |
| 8798 | } |
| 8799 | out: |
| 8800 | return ret; |
| 8801 | } |
| 8802 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8803 | #endif /* CONFIG_NFS_V4_1 */ |
| 8804 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8805 | struct nfs4_get_lease_time_data { |
| 8806 | struct nfs4_get_lease_time_args *args; |
| 8807 | struct nfs4_get_lease_time_res *res; |
| 8808 | struct nfs_client *clp; |
| 8809 | }; |
| 8810 | |
| 8811 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8812 | void *calldata) |
| 8813 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8814 | struct nfs4_get_lease_time_data *data = |
| 8815 | (struct nfs4_get_lease_time_data *)calldata; |
| 8816 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8817 | /* just setup sequence, do not trigger session recovery |
| 8818 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8819 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8820 | &data->args->la_seq_args, |
| 8821 | &data->res->lr_seq_res, |
| 8822 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8823 | } |
| 8824 | |
| 8825 | /* |
| 8826 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8827 | * from sequence operation or clientid errors. |
| 8828 | */ |
| 8829 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8830 | { |
| 8831 | struct nfs4_get_lease_time_data *data = |
| 8832 | (struct nfs4_get_lease_time_data *)calldata; |
| 8833 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8834 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8835 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8836 | switch (task->tk_status) { |
| 8837 | case -NFS4ERR_DELAY: |
| 8838 | case -NFS4ERR_GRACE: |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8839 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8840 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 8841 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8842 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8843 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8844 | return; |
| 8845 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8846 | } |
| 8847 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8848 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8849 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8850 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8851 | }; |
| 8852 | |
| 8853 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8854 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8855 | struct nfs4_get_lease_time_args args; |
| 8856 | struct nfs4_get_lease_time_res res = { |
| 8857 | .lr_fsinfo = fsinfo, |
| 8858 | }; |
| 8859 | struct nfs4_get_lease_time_data data = { |
| 8860 | .args = &args, |
| 8861 | .res = &res, |
| 8862 | .clp = clp, |
| 8863 | }; |
| 8864 | struct rpc_message msg = { |
| 8865 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8866 | .rpc_argp = &args, |
| 8867 | .rpc_resp = &res, |
| 8868 | }; |
| 8869 | struct rpc_task_setup task_setup = { |
| 8870 | .rpc_client = clp->cl_rpcclient, |
| 8871 | .rpc_message = &msg, |
| 8872 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8873 | .callback_data = &data, |
| 8874 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8875 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8876 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8877 | 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] | 8878 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8879 | } |
| 8880 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8881 | #ifdef CONFIG_NFS_V4_1 |
| 8882 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8883 | /* |
| 8884 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8885 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8886 | * use them. |
| 8887 | * |
| 8888 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8889 | * always set csa_cachethis to FALSE because the current implementation |
| 8890 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8891 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8892 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8893 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8894 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8895 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8896 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8897 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8898 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8899 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8900 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8901 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8902 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8903 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8904 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8905 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8906 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8907 | |
| 8908 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8909 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8910 | __func__, |
| 8911 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8912 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8913 | |
| 8914 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8915 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8916 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8917 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8918 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8919 | 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] | 8920 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8921 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8922 | |
| 8923 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8924 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8925 | __func__, |
| 8926 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8927 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8928 | args->bc_attrs.max_reqs); |
| 8929 | } |
| 8930 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8931 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8932 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8933 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8934 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8935 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8936 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8937 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8938 | return -EINVAL; |
| 8939 | /* |
| 8940 | * Our requested max_ops is the minimum we need; we're not |
| 8941 | * prepared to break up compounds into smaller pieces than that. |
| 8942 | * So, no point even trying to continue if the server won't |
| 8943 | * cooperate: |
| 8944 | */ |
| 8945 | if (rcvd->max_ops < sent->max_ops) |
| 8946 | return -EINVAL; |
| 8947 | if (rcvd->max_reqs == 0) |
| 8948 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8949 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8950 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8951 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8952 | } |
| 8953 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8954 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8955 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8956 | { |
| 8957 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8958 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8959 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8960 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8961 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8962 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8963 | return -EINVAL; |
| 8964 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8965 | return -EINVAL; |
| 8966 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8967 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8968 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8969 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8970 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8971 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8972 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8973 | return 0; |
| 8974 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8975 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8976 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8977 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8978 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8979 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8980 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8981 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8982 | if (ret) |
| 8983 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8984 | return nfs4_verify_back_channel_attrs(args, res); |
| 8985 | } |
| 8986 | |
| 8987 | static void nfs4_update_session(struct nfs4_session *session, |
| 8988 | struct nfs41_create_session_res *res) |
| 8989 | { |
| 8990 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8991 | /* Mark client id and session as being confirmed */ |
| 8992 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8993 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8994 | session->flags = res->flags; |
| 8995 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8996 | if (res->flags & SESSION4_BACK_CHAN) |
| 8997 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8998 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8999 | } |
| 9000 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9001 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9002 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9003 | { |
| 9004 | struct nfs4_session *session = clp->cl_session; |
| 9005 | struct nfs41_create_session_args args = { |
| 9006 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9007 | .clientid = clp->cl_clientid, |
| 9008 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9009 | .cb_program = NFS4_CALLBACK, |
| 9010 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9011 | struct nfs41_create_session_res res; |
| 9012 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9013 | struct rpc_message msg = { |
| 9014 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 9015 | .rpc_argp = &args, |
| 9016 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9017 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9018 | }; |
| 9019 | int status; |
| 9020 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 9021 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 9022 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9023 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9024 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9025 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9026 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9027 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 9028 | switch (status) { |
| 9029 | case -NFS4ERR_STALE_CLIENTID: |
| 9030 | case -NFS4ERR_DELAY: |
| 9031 | case -ETIMEDOUT: |
| 9032 | case -EACCES: |
| 9033 | case -EAGAIN: |
| 9034 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 9035 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 9036 | |
| 9037 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 9038 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9039 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9040 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9041 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9042 | if (status) |
| 9043 | goto out; |
| 9044 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9045 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9046 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9047 | return status; |
| 9048 | } |
| 9049 | |
| 9050 | /* |
| 9051 | * Issues a CREATE_SESSION operation to the server. |
| 9052 | * It is the responsibility of the caller to verify the session is |
| 9053 | * expired before calling this routine. |
| 9054 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9055 | 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] | 9056 | { |
| 9057 | int status; |
| 9058 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9059 | struct nfs4_session *session = clp->cl_session; |
| 9060 | |
| 9061 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 9062 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9063 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9064 | if (status) |
| 9065 | goto out; |
| 9066 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 9067 | /* Init or reset the session slot tables */ |
| 9068 | status = nfs4_setup_session_slot_tables(session); |
| 9069 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9070 | if (status) |
| 9071 | goto out; |
| 9072 | |
| 9073 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 9074 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 9075 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9076 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9077 | return status; |
| 9078 | } |
| 9079 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9080 | /* |
| 9081 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 9082 | * The caller must serialize access to this routine. |
| 9083 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9084 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9085 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9086 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9087 | struct rpc_message msg = { |
| 9088 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 9089 | .rpc_argp = session, |
| 9090 | .rpc_cred = cred, |
| 9091 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9092 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9093 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9094 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 9095 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 9096 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9097 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9098 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9099 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9100 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9101 | |
| 9102 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 9103 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9104 | "Session has been destroyed regardless...\n", status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9105 | return status; |
| 9106 | } |
| 9107 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 9108 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9109 | * Renew the cl_session lease. |
| 9110 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9111 | struct nfs4_sequence_data { |
| 9112 | struct nfs_client *clp; |
| 9113 | struct nfs4_sequence_args args; |
| 9114 | struct nfs4_sequence_res res; |
| 9115 | }; |
| 9116 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9117 | static void nfs41_sequence_release(void *data) |
| 9118 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9119 | struct nfs4_sequence_data *calldata = data; |
| 9120 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9121 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9122 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9123 | nfs4_schedule_state_renewal(clp); |
| 9124 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9125 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9126 | } |
| 9127 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9128 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9129 | { |
| 9130 | switch(task->tk_status) { |
| 9131 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9132 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 9133 | return -EAGAIN; |
| 9134 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9135 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9136 | } |
| 9137 | return 0; |
| 9138 | } |
| 9139 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9140 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9141 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9142 | struct nfs4_sequence_data *calldata = data; |
| 9143 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9144 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9145 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 9146 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9147 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9148 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9149 | if (task->tk_status < 0) { |
| 9150 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9151 | if (refcount_read(&clp->cl_count) == 1) |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 9152 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9153 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9154 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 9155 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9156 | return; |
| 9157 | } |
| 9158 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9159 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9160 | } |
| 9161 | |
| 9162 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 9163 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9164 | struct nfs4_sequence_data *calldata = data; |
| 9165 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9166 | struct nfs4_sequence_args *args; |
| 9167 | struct nfs4_sequence_res *res; |
| 9168 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9169 | args = task->tk_msg.rpc_argp; |
| 9170 | res = task->tk_msg.rpc_resp; |
| 9171 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9172 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9173 | } |
| 9174 | |
| 9175 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 9176 | .rpc_call_done = nfs41_sequence_call_done, |
| 9177 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9178 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9179 | }; |
| 9180 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9181 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9182 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9183 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9184 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9185 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9186 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9187 | struct rpc_message msg = { |
| 9188 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 9189 | .rpc_cred = cred, |
| 9190 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9191 | struct rpc_task_setup task_setup_data = { |
| 9192 | .rpc_client = clp->cl_rpcclient, |
| 9193 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9194 | .callback_ops = &nfs41_sequence_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9195 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT | RPC_TASK_MOVEABLE, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9196 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9197 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9198 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9199 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9200 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9201 | goto out_err; |
| 9202 | |
| 9203 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 9204 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9205 | if (calldata == NULL) |
| 9206 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9207 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9208 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9209 | msg.rpc_argp = &calldata->args; |
| 9210 | msg.rpc_resp = &calldata->res; |
| 9211 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9212 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9213 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9214 | ret = rpc_run_task(&task_setup_data); |
| 9215 | if (IS_ERR(ret)) |
| 9216 | goto out_err; |
| 9217 | return ret; |
| 9218 | out_put_clp: |
| 9219 | nfs_put_client(clp); |
| 9220 | out_err: |
| 9221 | nfs41_release_slot(slot); |
| 9222 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9223 | } |
| 9224 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9225 | 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] | 9226 | { |
| 9227 | struct rpc_task *task; |
| 9228 | int ret = 0; |
| 9229 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 9230 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 9231 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9232 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9233 | if (IS_ERR(task)) |
| 9234 | ret = PTR_ERR(task); |
| 9235 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 9236 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9237 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9238 | return ret; |
| 9239 | } |
| 9240 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9241 | 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] | 9242 | { |
| 9243 | struct rpc_task *task; |
| 9244 | int ret; |
| 9245 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9246 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9247 | if (IS_ERR(task)) { |
| 9248 | ret = PTR_ERR(task); |
| 9249 | goto out; |
| 9250 | } |
| 9251 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 9252 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9253 | ret = task->tk_status; |
| 9254 | rpc_put_task(task); |
| 9255 | out: |
| 9256 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9257 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9258 | } |
| 9259 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9260 | struct nfs4_reclaim_complete_data { |
| 9261 | struct nfs_client *clp; |
| 9262 | struct nfs41_reclaim_complete_args arg; |
| 9263 | struct nfs41_reclaim_complete_res res; |
| 9264 | }; |
| 9265 | |
| 9266 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 9267 | { |
| 9268 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9269 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9270 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9271 | &calldata->arg.seq_args, |
| 9272 | &calldata->res.seq_res, |
| 9273 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9274 | } |
| 9275 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9276 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9277 | { |
| 9278 | switch(task->tk_status) { |
| 9279 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 9280 | wake_up_all(&clp->cl_lock_waitq); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9281 | fallthrough; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9282 | case -NFS4ERR_COMPLETE_ALREADY: |
| 9283 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 9284 | break; |
| 9285 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9286 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9287 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 9288 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9289 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9290 | case -NFS4ERR_BADSESSION: |
| 9291 | case -NFS4ERR_DEADSESSION: |
| 9292 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9293 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9294 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9295 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9296 | } |
| 9297 | return 0; |
| 9298 | } |
| 9299 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9300 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 9301 | { |
| 9302 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9303 | struct nfs_client *clp = calldata->clp; |
| 9304 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 9305 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9306 | if (!nfs41_sequence_done(task, res)) |
| 9307 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9308 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9309 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9310 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 9311 | rpc_restart_call_prepare(task); |
| 9312 | return; |
| 9313 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9314 | } |
| 9315 | |
| 9316 | static void nfs4_free_reclaim_complete_data(void *data) |
| 9317 | { |
| 9318 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9319 | |
| 9320 | kfree(calldata); |
| 9321 | } |
| 9322 | |
| 9323 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 9324 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 9325 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 9326 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 9327 | }; |
| 9328 | |
| 9329 | /* |
| 9330 | * Issue a global reclaim complete. |
| 9331 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9332 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9333 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9334 | { |
| 9335 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9336 | struct rpc_message msg = { |
| 9337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9338 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9339 | }; |
| 9340 | struct rpc_task_setup task_setup_data = { |
| 9341 | .rpc_client = clp->cl_rpcclient, |
| 9342 | .rpc_message = &msg, |
| 9343 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9344 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9345 | }; |
| 9346 | int status = -ENOMEM; |
| 9347 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 9348 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9349 | if (calldata == NULL) |
| 9350 | goto out; |
| 9351 | calldata->clp = clp; |
| 9352 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9353 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9354 | 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] | 9355 | msg.rpc_argp = &calldata->arg; |
| 9356 | msg.rpc_resp = &calldata->res; |
| 9357 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9358 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9359 | out: |
| 9360 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9361 | return status; |
| 9362 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9363 | |
| 9364 | static void |
| 9365 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9366 | { |
| 9367 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9368 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9369 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9370 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9371 | &lgp->res.seq_res, task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9372 | } |
| 9373 | |
| 9374 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9375 | { |
| 9376 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9377 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9378 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9379 | } |
| 9380 | |
| 9381 | static int |
| 9382 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9383 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9384 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9385 | struct inode *inode = lgp->args.inode; |
| 9386 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4e89bc | 2021-07-02 17:24:22 -0400 | [diff] [blame] | 9387 | struct pnfs_layout_hdr *lo = lgp->lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9388 | int nfs4err = task->tk_status; |
| 9389 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9390 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9391 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9392 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9393 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9394 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9395 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9396 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9397 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9398 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9399 | |
| 9400 | /* |
| 9401 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9402 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9403 | * retry go inband. |
| 9404 | */ |
| 9405 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9406 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9407 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9408 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9409 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9410 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9411 | */ |
| 9412 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9413 | status = -EOVERFLOW; |
| 9414 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9415 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9416 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9417 | * (or clients) writing to the same RAID stripe except when |
| 9418 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9419 | * |
| 9420 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9421 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9422 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9423 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9424 | if (lgp->args.minlength == 0) { |
| 9425 | status = -EOVERFLOW; |
| 9426 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9427 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9428 | status = -EBUSY; |
| 9429 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9430 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9431 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9432 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9433 | case -NFS4ERR_DELEG_REVOKED: |
| 9434 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9435 | case -NFS4ERR_EXPIRED: |
| 9436 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9437 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9438 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9439 | /* If the open stateid was bad, then recover it. */ |
| 9440 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9441 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9442 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9443 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9444 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9445 | break; |
| 9446 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9447 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9448 | /* |
| 9449 | * Mark the bad layout state as invalid, then retry |
| 9450 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9451 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9452 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9453 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9454 | pnfs_free_lseg_list(&head); |
| 9455 | status = -EAGAIN; |
| 9456 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9457 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9458 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9459 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9460 | if (!status) { |
| 9461 | if (exception->retry) |
| 9462 | status = -EAGAIN; |
| 9463 | else |
| 9464 | status = err; |
| 9465 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9466 | out: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9467 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9468 | } |
| 9469 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9470 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9471 | { |
| 9472 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9473 | return nfs_page_array_len(0, max_resp_sz); |
| 9474 | } |
| 9475 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9476 | static void nfs4_layoutget_release(void *calldata) |
| 9477 | { |
| 9478 | struct nfs4_layoutget *lgp = calldata; |
| 9479 | |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9480 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9481 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9482 | } |
| 9483 | |
| 9484 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9485 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9486 | .rpc_call_done = nfs4_layoutget_done, |
| 9487 | .rpc_release = nfs4_layoutget_release, |
| 9488 | }; |
| 9489 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9490 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9491 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9492 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9493 | struct inode *inode = lgp->args.inode; |
| 9494 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9495 | struct rpc_task *task; |
| 9496 | struct rpc_message msg = { |
| 9497 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9498 | .rpc_argp = &lgp->args, |
| 9499 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9500 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9501 | }; |
| 9502 | struct rpc_task_setup task_setup_data = { |
| 9503 | .rpc_client = server->client, |
| 9504 | .rpc_message = &msg, |
| 9505 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9506 | .callback_data = lgp, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9507 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF | |
| 9508 | RPC_TASK_MOVEABLE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9509 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9510 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9511 | struct nfs4_exception exception = { |
| 9512 | .inode = inode, |
| 9513 | .timeout = *timeout, |
| 9514 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9515 | int status = 0; |
| 9516 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9517 | 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] | 9518 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9519 | task = rpc_run_task(&task_setup_data); |
Xiyu Yang | 6e47666 | 2020-04-25 21:04:40 +0800 | [diff] [blame] | 9520 | |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9521 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9522 | if (status != 0) |
| 9523 | goto out; |
| 9524 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9525 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9526 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9527 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9528 | } else if (lgp->res.layoutp->len == 0) { |
| 9529 | status = -EAGAIN; |
| 9530 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9531 | } else |
| 9532 | lseg = pnfs_layout_process(lgp); |
| 9533 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9534 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9535 | &lgp->args.range, |
| 9536 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9537 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9538 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9539 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9540 | rpc_put_task(task); |
| 9541 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9542 | if (status) |
| 9543 | return ERR_PTR(status); |
| 9544 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9545 | } |
| 9546 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9547 | static void |
| 9548 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9549 | { |
| 9550 | struct nfs4_layoutreturn *lrp = calldata; |
| 9551 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9552 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9553 | &lrp->args.seq_args, |
| 9554 | &lrp->res.seq_res, |
| 9555 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9556 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9557 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9558 | } |
| 9559 | |
| 9560 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9561 | { |
| 9562 | struct nfs4_layoutreturn *lrp = calldata; |
| 9563 | struct nfs_server *server; |
| 9564 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9565 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9566 | return; |
| 9567 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9568 | /* |
| 9569 | * Was there an RPC level error? Assume the call succeeded, |
| 9570 | * and that we need to release the layout |
| 9571 | */ |
| 9572 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9573 | lrp->res.lrs_present = 0; |
| 9574 | return; |
| 9575 | } |
| 9576 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9577 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9578 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9579 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9580 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9581 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9582 | lrp->args.inode)) |
| 9583 | goto out_restart; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9584 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9585 | default: |
| 9586 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9587 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9588 | case 0: |
| 9589 | break; |
| 9590 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9591 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9592 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9593 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9594 | } |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9595 | return; |
| 9596 | out_restart: |
| 9597 | task->tk_status = 0; |
| 9598 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9599 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9600 | } |
| 9601 | |
| 9602 | static void nfs4_layoutreturn_release(void *calldata) |
| 9603 | { |
| 9604 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9605 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9606 | |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9607 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9608 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9609 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9610 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9611 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9612 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9613 | nfs_iput_and_deactive(lrp->inode); |
Trond Myklebust | 44ea8df | 2020-04-02 15:37:02 -0400 | [diff] [blame] | 9614 | put_cred(lrp->cred); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9615 | kfree(calldata); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9616 | } |
| 9617 | |
| 9618 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9619 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9620 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9621 | .rpc_release = nfs4_layoutreturn_release, |
| 9622 | }; |
| 9623 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9624 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9625 | { |
| 9626 | struct rpc_task *task; |
| 9627 | struct rpc_message msg = { |
| 9628 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9629 | .rpc_argp = &lrp->args, |
| 9630 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9631 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9632 | }; |
| 9633 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9634 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9635 | .rpc_message = &msg, |
| 9636 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9637 | .callback_data = lrp, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9638 | .flags = RPC_TASK_MOVEABLE, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9639 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9640 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9641 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9642 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9643 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9644 | &task_setup_data.rpc_client, &msg); |
| 9645 | |
Trond Myklebust | c3aba89 | 2021-06-01 11:35:56 -0400 | [diff] [blame] | 9646 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9647 | if (!sync) { |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9648 | if (!lrp->inode) { |
| 9649 | nfs4_layoutreturn_release(lrp); |
| 9650 | return -EAGAIN; |
| 9651 | } |
| 9652 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9653 | } |
Trond Myklebust | c3aba89 | 2021-06-01 11:35:56 -0400 | [diff] [blame] | 9654 | if (!lrp->inode) |
| 9655 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, |
| 9656 | 1); |
| 9657 | else |
| 9658 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, |
| 9659 | 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9660 | task = rpc_run_task(&task_setup_data); |
| 9661 | if (IS_ERR(task)) |
| 9662 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9663 | if (sync) |
| 9664 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9665 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9666 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9667 | rpc_put_task(task); |
| 9668 | return status; |
| 9669 | } |
| 9670 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9671 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9672 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9673 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9674 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9675 | { |
| 9676 | struct nfs4_getdeviceinfo_args args = { |
| 9677 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9678 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9679 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9680 | }; |
| 9681 | struct nfs4_getdeviceinfo_res res = { |
| 9682 | .pdev = pdev, |
| 9683 | }; |
| 9684 | struct rpc_message msg = { |
| 9685 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9686 | .rpc_argp = &args, |
| 9687 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9688 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9689 | }; |
| 9690 | int status; |
| 9691 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9692 | 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] | 9693 | if (res.notification & ~args.notify_types) |
| 9694 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9695 | if (res.notification != args.notify_types) |
| 9696 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9697 | |
Trond Myklebust | cac1d3a | 2020-12-16 16:31:26 -0500 | [diff] [blame] | 9698 | trace_nfs4_getdeviceinfo(server, &pdev->dev_id, status); |
| 9699 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9700 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9701 | |
| 9702 | return status; |
| 9703 | } |
| 9704 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9705 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9706 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9707 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9708 | { |
| 9709 | struct nfs4_exception exception = { }; |
| 9710 | int err; |
| 9711 | |
| 9712 | do { |
| 9713 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9714 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9715 | &exception); |
| 9716 | } while (exception.retry); |
| 9717 | return err; |
| 9718 | } |
| 9719 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9720 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9721 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9722 | { |
| 9723 | struct nfs4_layoutcommit_data *data = calldata; |
| 9724 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9725 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9726 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9727 | &data->args.seq_args, |
| 9728 | &data->res.seq_res, |
| 9729 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9730 | } |
| 9731 | |
| 9732 | static void |
| 9733 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9734 | { |
| 9735 | struct nfs4_layoutcommit_data *data = calldata; |
| 9736 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9737 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9738 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9739 | return; |
| 9740 | |
| 9741 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9742 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9743 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9744 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9745 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9746 | task->tk_status = 0; |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame] | 9747 | break; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9748 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9749 | break; |
| 9750 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9751 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9752 | rpc_restart_call_prepare(task); |
| 9753 | return; |
| 9754 | } |
| 9755 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9756 | } |
| 9757 | |
| 9758 | static void nfs4_layoutcommit_release(void *calldata) |
| 9759 | { |
| 9760 | struct nfs4_layoutcommit_data *data = calldata; |
| 9761 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9762 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9763 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9764 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9765 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9766 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9767 | kfree(data); |
| 9768 | } |
| 9769 | |
| 9770 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9771 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9772 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9773 | .rpc_release = nfs4_layoutcommit_release, |
| 9774 | }; |
| 9775 | |
| 9776 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9777 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9778 | { |
| 9779 | struct rpc_message msg = { |
| 9780 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9781 | .rpc_argp = &data->args, |
| 9782 | .rpc_resp = &data->res, |
| 9783 | .rpc_cred = data->cred, |
| 9784 | }; |
| 9785 | struct rpc_task_setup task_setup_data = { |
| 9786 | .task = &data->task, |
| 9787 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9788 | .rpc_message = &msg, |
| 9789 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9790 | .callback_data = data, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9791 | .flags = RPC_TASK_MOVEABLE, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9792 | }; |
| 9793 | struct rpc_task *task; |
| 9794 | int status = 0; |
| 9795 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9796 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9797 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9798 | data->args.lastbytewritten, |
| 9799 | data->args.inode->i_ino); |
| 9800 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9801 | if (!sync) { |
| 9802 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9803 | if (data->inode == NULL) { |
| 9804 | nfs4_layoutcommit_release(data); |
| 9805 | return -EAGAIN; |
| 9806 | } |
| 9807 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9808 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9809 | 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] | 9810 | task = rpc_run_task(&task_setup_data); |
| 9811 | if (IS_ERR(task)) |
| 9812 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9813 | if (sync) |
| 9814 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9815 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9816 | dprintk("%s: status %d\n", __func__, status); |
| 9817 | rpc_put_task(task); |
| 9818 | return status; |
| 9819 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9820 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9821 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9822 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9823 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9824 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9825 | static int |
| 9826 | _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] | 9827 | struct nfs_fsinfo *info, |
| 9828 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9829 | { |
| 9830 | struct nfs41_secinfo_no_name_args args = { |
| 9831 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9832 | }; |
| 9833 | struct nfs4_secinfo_res res = { |
| 9834 | .flavors = flavors, |
| 9835 | }; |
| 9836 | struct rpc_message msg = { |
| 9837 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9838 | .rpc_argp = &args, |
| 9839 | .rpc_resp = &res, |
| 9840 | }; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9841 | struct nfs4_call_sync_data data = { |
| 9842 | .seq_server = server, |
| 9843 | .seq_args = &args.seq_args, |
| 9844 | .seq_res = &res.seq_res, |
| 9845 | }; |
| 9846 | struct rpc_task_setup task_setup = { |
| 9847 | .rpc_client = server->client, |
| 9848 | .rpc_message = &msg, |
| 9849 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9850 | .callback_data = &data, |
| 9851 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9852 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9853 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9854 | int status; |
| 9855 | |
| 9856 | if (use_integrity) { |
Colin Ian King | 48bb6ec | 2020-06-10 00:22:57 +0100 | [diff] [blame] | 9857 | task_setup.rpc_client = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9858 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9859 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9860 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9861 | } |
| 9862 | |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9863 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9864 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9865 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9866 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9867 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9868 | |
| 9869 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9870 | } |
| 9871 | |
| 9872 | static int |
| 9873 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9874 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9875 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9876 | struct nfs4_exception exception = { |
| 9877 | .interruptible = true, |
| 9878 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9879 | int err; |
| 9880 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9881 | /* first try using integrity protection */ |
| 9882 | err = -NFS4ERR_WRONGSEC; |
| 9883 | |
| 9884 | /* try to use integrity protection with machine cred */ |
| 9885 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9886 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9887 | flavors, true); |
| 9888 | |
| 9889 | /* |
| 9890 | * if unable to use integrity protection, or SECINFO with |
| 9891 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9892 | * disallowed by spec, but exists in deployed servers) use |
| 9893 | * the current filesystem's rpc_client and the user cred. |
| 9894 | */ |
| 9895 | if (err == -NFS4ERR_WRONGSEC) |
| 9896 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9897 | flavors, false); |
| 9898 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9899 | switch (err) { |
| 9900 | case 0: |
| 9901 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9902 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9903 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9904 | default: |
| 9905 | err = nfs4_handle_exception(server, err, &exception); |
| 9906 | } |
| 9907 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9908 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9909 | return err; |
| 9910 | } |
| 9911 | |
| 9912 | static int |
| 9913 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9914 | struct nfs_fsinfo *info) |
| 9915 | { |
| 9916 | int err; |
| 9917 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9918 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9919 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9920 | struct nfs4_secinfo4 *secinfo; |
| 9921 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9922 | |
| 9923 | page = alloc_page(GFP_KERNEL); |
| 9924 | if (!page) { |
| 9925 | err = -ENOMEM; |
| 9926 | goto out; |
| 9927 | } |
| 9928 | |
| 9929 | flavors = page_address(page); |
| 9930 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9931 | |
| 9932 | /* |
| 9933 | * Fall back on "guess and check" method if |
| 9934 | * the server doesn't support SECINFO_NO_NAME |
| 9935 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9936 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9937 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9938 | goto out_freepage; |
| 9939 | } |
| 9940 | if (err) |
| 9941 | goto out_freepage; |
| 9942 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9943 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9944 | secinfo = &flavors->flavors[i]; |
| 9945 | |
| 9946 | switch (secinfo->flavor) { |
| 9947 | case RPC_AUTH_NULL: |
| 9948 | case RPC_AUTH_UNIX: |
| 9949 | case RPC_AUTH_GSS: |
| 9950 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9951 | &secinfo->flavor_info); |
| 9952 | break; |
| 9953 | default: |
| 9954 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9955 | break; |
| 9956 | } |
| 9957 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9958 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9959 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9960 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9961 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9962 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9963 | info, flavor); |
| 9964 | if (!err) |
| 9965 | break; |
| 9966 | } |
| 9967 | } |
| 9968 | |
| 9969 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9970 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9971 | |
| 9972 | out_freepage: |
| 9973 | put_page(page); |
| 9974 | if (err == -EACCES) |
| 9975 | return -EPERM; |
| 9976 | out: |
| 9977 | return err; |
| 9978 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9979 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9980 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9981 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9982 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9983 | { |
| 9984 | int status; |
| 9985 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9986 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9987 | }; |
| 9988 | struct nfs41_test_stateid_res res; |
| 9989 | struct rpc_message msg = { |
| 9990 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9991 | .rpc_argp = &args, |
| 9992 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9993 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9994 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9995 | struct rpc_clnt *rpc_client = server->client; |
| 9996 | |
| 9997 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9998 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9999 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10000 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10001 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10002 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 10003 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10004 | if (status != NFS_OK) { |
| 10005 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 10006 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10007 | } |
| 10008 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 10009 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10010 | } |
| 10011 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10012 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 10013 | int err, struct nfs4_exception *exception) |
| 10014 | { |
| 10015 | exception->retry = 0; |
| 10016 | switch(err) { |
| 10017 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 10018 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10019 | nfs4_handle_exception(server, err, exception); |
| 10020 | break; |
| 10021 | case -NFS4ERR_BADSESSION: |
| 10022 | case -NFS4ERR_BADSLOT: |
| 10023 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 10024 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 10025 | case -NFS4ERR_DEADSESSION: |
| 10026 | nfs4_do_handle_exception(server, err, exception); |
| 10027 | } |
| 10028 | } |
| 10029 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10030 | /** |
| 10031 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 10032 | * |
| 10033 | * @server: server / transport on which to perform the operation |
| 10034 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10035 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10036 | * |
| 10037 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 10038 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 10039 | * failed or the state ID is not currently valid. |
| 10040 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10041 | static int nfs41_test_stateid(struct nfs_server *server, |
| 10042 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10043 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10044 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 10045 | struct nfs4_exception exception = { |
| 10046 | .interruptible = true, |
| 10047 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10048 | int err; |
| 10049 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10050 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10051 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10052 | } while (exception.retry); |
| 10053 | return err; |
| 10054 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10055 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10056 | struct nfs_free_stateid_data { |
| 10057 | struct nfs_server *server; |
| 10058 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10059 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10060 | }; |
| 10061 | |
| 10062 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 10063 | { |
| 10064 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 10065 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10066 | &data->args.seq_args, |
| 10067 | &data->res.seq_res, |
| 10068 | task); |
| 10069 | } |
| 10070 | |
| 10071 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 10072 | { |
| 10073 | struct nfs_free_stateid_data *data = calldata; |
| 10074 | |
| 10075 | nfs41_sequence_done(task, &data->res.seq_res); |
| 10076 | |
| 10077 | switch (task->tk_status) { |
| 10078 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 10079 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10080 | rpc_restart_call_prepare(task); |
| 10081 | } |
| 10082 | } |
| 10083 | |
| 10084 | static void nfs41_free_stateid_release(void *calldata) |
| 10085 | { |
Scott Mayhew | 576acc2 | 2021-11-03 06:24:40 -0400 | [diff] [blame] | 10086 | struct nfs_free_stateid_data *data = calldata; |
| 10087 | struct nfs_client *clp = data->server->nfs_client; |
| 10088 | |
| 10089 | nfs_put_client(clp); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10090 | kfree(calldata); |
| 10091 | } |
| 10092 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10093 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10094 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 10095 | .rpc_call_done = nfs41_free_stateid_done, |
| 10096 | .rpc_release = nfs41_free_stateid_release, |
| 10097 | }; |
| 10098 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10099 | /** |
| 10100 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 10101 | * |
| 10102 | * @server: server / transport on which to perform the operation |
| 10103 | * @stateid: state ID to release |
| 10104 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 10105 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10106 | * |
| 10107 | * Note: this function is always asynchronous. |
| 10108 | */ |
| 10109 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10110 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10111 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10112 | bool privileged) |
| 10113 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10114 | struct rpc_message msg = { |
| 10115 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10116 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10117 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10118 | struct rpc_task_setup task_setup = { |
| 10119 | .rpc_client = server->client, |
| 10120 | .rpc_message = &msg, |
| 10121 | .callback_ops = &nfs41_free_stateid_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 10122 | .flags = RPC_TASK_ASYNC | RPC_TASK_MOVEABLE, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10123 | }; |
| 10124 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10125 | struct rpc_task *task; |
Scott Mayhew | 576acc2 | 2021-11-03 06:24:40 -0400 | [diff] [blame] | 10126 | struct nfs_client *clp = server->nfs_client; |
| 10127 | |
| 10128 | if (!refcount_inc_not_zero(&clp->cl_count)) |
| 10129 | return -EIO; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10130 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10131 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 10132 | &task_setup.rpc_client, &msg); |
| 10133 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10134 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10135 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 10136 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10137 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10138 | data->server = server; |
| 10139 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 10140 | |
| 10141 | task_setup.callback_data = data; |
| 10142 | |
| 10143 | msg.rpc_argp = &data->args; |
| 10144 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10145 | 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] | 10146 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10147 | if (IS_ERR(task)) |
| 10148 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10149 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10150 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10151 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10152 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 10153 | static void |
| 10154 | 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] | 10155 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10156 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10157 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10158 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10159 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10160 | } |
| 10161 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10162 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 10163 | const nfs4_stateid *s2) |
| 10164 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 10165 | if (s1->type != s2->type) |
| 10166 | return false; |
| 10167 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10168 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10169 | return false; |
| 10170 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10171 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10172 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10173 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 10174 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10175 | } |
| 10176 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 10177 | #endif /* CONFIG_NFS_V4_1 */ |
| 10178 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10179 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 10180 | const nfs4_stateid *s2) |
| 10181 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10182 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10183 | } |
| 10184 | |
| 10185 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10186 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10187 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10188 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10189 | .recover_open = nfs4_open_reclaim, |
| 10190 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10191 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10192 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10193 | }; |
| 10194 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10195 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10196 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10197 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 10198 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 10199 | .recover_open = nfs4_open_reclaim, |
| 10200 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10201 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 10202 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10203 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10204 | }; |
| 10205 | #endif /* CONFIG_NFS_V4_1 */ |
| 10206 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10207 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10208 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10209 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 10210 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10211 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10212 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10213 | }; |
| 10214 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10215 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10216 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10217 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 10218 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 10219 | .recover_open = nfs41_open_expired, |
| 10220 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10221 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10222 | }; |
| 10223 | #endif /* CONFIG_NFS_V4_1 */ |
| 10224 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10225 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10226 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10227 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10228 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10229 | }; |
| 10230 | |
| 10231 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10232 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10233 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10234 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10235 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10236 | }; |
| 10237 | #endif |
| 10238 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10239 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10240 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10241 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10242 | }; |
| 10243 | |
| 10244 | #if defined(CONFIG_NFS_V4_1) |
| 10245 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10246 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10247 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10248 | }; |
| 10249 | #endif /* CONFIG_NFS_V4_1 */ |
| 10250 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10251 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 10252 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10253 | .init_caps = NFS_CAP_READDIRPLUS |
| 10254 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10255 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10256 | .init_client = nfs40_init_client, |
| 10257 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10258 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10259 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10260 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10261 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10262 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10263 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10264 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 10265 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 10266 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10267 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10268 | }; |
| 10269 | |
| 10270 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10271 | static struct nfs_seqid * |
| 10272 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 10273 | { |
| 10274 | return NULL; |
| 10275 | } |
| 10276 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10277 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 10278 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10279 | .init_caps = NFS_CAP_READDIRPLUS |
| 10280 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 10281 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 10282 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10283 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 10284 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10285 | .init_client = nfs41_init_client, |
| 10286 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10287 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10288 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10289 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10290 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10291 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10292 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10293 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10294 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10295 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10296 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10297 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10298 | }; |
| 10299 | #endif |
| 10300 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10301 | #if defined(CONFIG_NFS_V4_2) |
| 10302 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 10303 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10304 | .init_caps = NFS_CAP_READDIRPLUS |
| 10305 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10306 | | NFS_CAP_POSIX_LOCK |
| 10307 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 10308 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10309 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 10310 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 10311 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 10312 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 10313 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 10314 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 10315 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 10316 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 10317 | | NFS_CAP_CLONE |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 10318 | | NFS_CAP_LAYOUTERROR |
| 10319 | | NFS_CAP_READ_PLUS, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10320 | .init_client = nfs41_init_client, |
| 10321 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10322 | .match_stateid = nfs41_match_stateid, |
| 10323 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10324 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10325 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10326 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10327 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10328 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10329 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10330 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10331 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 10332 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10333 | }; |
| 10334 | #endif |
| 10335 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10336 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 10337 | [0] = &nfs_v4_0_minor_ops, |
| 10338 | #if defined(CONFIG_NFS_V4_1) |
| 10339 | [1] = &nfs_v4_1_minor_ops, |
| 10340 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10341 | #if defined(CONFIG_NFS_V4_2) |
| 10342 | [2] = &nfs_v4_2_minor_ops, |
| 10343 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10344 | }; |
| 10345 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 10346 | 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] | 10347 | { |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10348 | ssize_t error, error2, error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10349 | |
| 10350 | error = generic_listxattr(dentry, list, size); |
| 10351 | if (error < 0) |
| 10352 | return error; |
| 10353 | if (list) { |
| 10354 | list += error; |
| 10355 | size -= error; |
| 10356 | } |
| 10357 | |
| 10358 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10359 | if (error2 < 0) |
| 10360 | return error2; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10361 | |
| 10362 | if (list) { |
| 10363 | list += error2; |
| 10364 | size -= error2; |
| 10365 | } |
| 10366 | |
| 10367 | error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); |
| 10368 | if (error3 < 0) |
| 10369 | return error3; |
| 10370 | |
| 10371 | return error + error2 + error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10372 | } |
| 10373 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10374 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10375 | .create = nfs_create, |
| 10376 | .lookup = nfs_lookup, |
| 10377 | .atomic_open = nfs_atomic_open, |
| 10378 | .link = nfs_link, |
| 10379 | .unlink = nfs_unlink, |
| 10380 | .symlink = nfs_symlink, |
| 10381 | .mkdir = nfs_mkdir, |
| 10382 | .rmdir = nfs_rmdir, |
| 10383 | .mknod = nfs_mknod, |
| 10384 | .rename = nfs_rename, |
| 10385 | .permission = nfs_permission, |
| 10386 | .getattr = nfs_getattr, |
| 10387 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10388 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10389 | }; |
| 10390 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10391 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10392 | .permission = nfs_permission, |
| 10393 | .getattr = nfs_getattr, |
| 10394 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10395 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10396 | }; |
| 10397 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10398 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10399 | .version = 4, /* protocol version */ |
| 10400 | .dentry_ops = &nfs4_dentry_operations, |
| 10401 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10402 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10403 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10404 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10405 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10406 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10407 | .getattr = nfs4_proc_getattr, |
| 10408 | .setattr = nfs4_proc_setattr, |
| 10409 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10410 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10411 | .access = nfs4_proc_access, |
| 10412 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10413 | .create = nfs4_proc_create, |
| 10414 | .remove = nfs4_proc_remove, |
| 10415 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10416 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10417 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10418 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10419 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10420 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10421 | .link = nfs4_proc_link, |
| 10422 | .symlink = nfs4_proc_symlink, |
| 10423 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10424 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10425 | .readdir = nfs4_proc_readdir, |
| 10426 | .mknod = nfs4_proc_mknod, |
| 10427 | .statfs = nfs4_proc_statfs, |
| 10428 | .fsinfo = nfs4_proc_fsinfo, |
| 10429 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10430 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10431 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10432 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10433 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10434 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10435 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10436 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10437 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10438 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10439 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10440 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10441 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10442 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10443 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10444 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10445 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10446 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10447 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10448 | .create_server = nfs4_create_server, |
| 10449 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10450 | }; |
| 10451 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10452 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10453 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10454 | .list = nfs4_xattr_list_nfs4_acl, |
| 10455 | .get = nfs4_xattr_get_nfs4_acl, |
| 10456 | .set = nfs4_xattr_set_nfs4_acl, |
| 10457 | }; |
| 10458 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10459 | #ifdef CONFIG_NFS_V4_2 |
| 10460 | static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { |
| 10461 | .prefix = XATTR_USER_PREFIX, |
| 10462 | .get = nfs4_xattr_get_nfs4_user, |
| 10463 | .set = nfs4_xattr_set_nfs4_user, |
| 10464 | }; |
| 10465 | #endif |
| 10466 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10467 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10468 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10469 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10470 | &nfs4_xattr_nfs4_label_handler, |
| 10471 | #endif |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10472 | #ifdef CONFIG_NFS_V4_2 |
| 10473 | &nfs4_xattr_nfs4_user_handler, |
| 10474 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10475 | NULL |
| 10476 | }; |