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); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 96 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 97 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 98 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 99 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 100 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 101 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 102 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 103 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 104 | struct nfs4_slot *slot, |
| 105 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 106 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 107 | const struct cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 108 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 109 | const struct cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 110 | #endif |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 111 | static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], |
| 112 | const __u32 *src, struct inode *inode, |
| 113 | struct nfs_server *server, |
| 114 | struct nfs4_label *label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 115 | |
| 116 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 117 | static inline struct nfs4_label * |
| 118 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 119 | struct iattr *sattr, struct nfs4_label *label) |
| 120 | { |
| 121 | int err; |
| 122 | |
| 123 | if (label == NULL) |
| 124 | return NULL; |
| 125 | |
| 126 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 127 | return NULL; |
| 128 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 129 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 130 | &dentry->d_name, (void **)&label->label, &label->len); |
| 131 | if (err == 0) |
| 132 | return label; |
| 133 | |
| 134 | return NULL; |
| 135 | } |
| 136 | static inline void |
| 137 | nfs4_label_release_security(struct nfs4_label *label) |
| 138 | { |
| 139 | if (label) |
| 140 | security_release_secctx(label->label, label->len); |
| 141 | } |
| 142 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 143 | { |
| 144 | if (label) |
| 145 | return server->attr_bitmask; |
| 146 | |
| 147 | return server->attr_bitmask_nl; |
| 148 | } |
| 149 | #else |
| 150 | static inline struct nfs4_label * |
| 151 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 152 | struct iattr *sattr, struct nfs4_label *l) |
| 153 | { return NULL; } |
| 154 | static inline void |
| 155 | nfs4_label_release_security(struct nfs4_label *label) |
| 156 | { return; } |
| 157 | static inline u32 * |
| 158 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 159 | { return server->attr_bitmask; } |
| 160 | #endif |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 163 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 165 | if (err >= -1000) |
| 166 | return err; |
| 167 | switch (err) { |
| 168 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 169 | case -NFS4ERR_LAYOUTTRYLATER: |
| 170 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 171 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 172 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 173 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 174 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 175 | case -NFS4ERR_BADOWNER: |
| 176 | case -NFS4ERR_BADNAME: |
| 177 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 178 | case -NFS4ERR_SHARE_DENIED: |
| 179 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 180 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 181 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 182 | case -NFS4ERR_FILE_OPEN: |
| 183 | return -EBUSY; |
Trond Myklebust | 9fff59e | 2020-11-02 20:11:32 -0500 | [diff] [blame] | 184 | case -NFS4ERR_NOT_SAME: |
| 185 | return -ENOTSYNC; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 186 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 188 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 189 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 191 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* |
| 195 | * This is our standard bitmap for GETATTR requests. |
| 196 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 197 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | FATTR4_WORD0_TYPE |
| 199 | | FATTR4_WORD0_CHANGE |
| 200 | | FATTR4_WORD0_SIZE |
| 201 | | FATTR4_WORD0_FSID |
| 202 | | FATTR4_WORD0_FILEID, |
| 203 | FATTR4_WORD1_MODE |
| 204 | | FATTR4_WORD1_NUMLINKS |
| 205 | | FATTR4_WORD1_OWNER |
| 206 | | FATTR4_WORD1_OWNER_GROUP |
| 207 | | FATTR4_WORD1_RAWDEV |
| 208 | | FATTR4_WORD1_SPACE_USED |
| 209 | | FATTR4_WORD1_TIME_ACCESS |
| 210 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 211 | | FATTR4_WORD1_TIME_MODIFY |
| 212 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 213 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 214 | FATTR4_WORD2_SECURITY_LABEL |
| 215 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | }; |
| 217 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 218 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 219 | FATTR4_WORD0_TYPE |
| 220 | | FATTR4_WORD0_CHANGE |
| 221 | | FATTR4_WORD0_SIZE |
| 222 | | FATTR4_WORD0_FSID |
| 223 | | FATTR4_WORD0_FILEID, |
| 224 | FATTR4_WORD1_MODE |
| 225 | | FATTR4_WORD1_NUMLINKS |
| 226 | | FATTR4_WORD1_OWNER |
| 227 | | FATTR4_WORD1_OWNER_GROUP |
| 228 | | FATTR4_WORD1_RAWDEV |
| 229 | | FATTR4_WORD1_SPACE_USED |
| 230 | | FATTR4_WORD1_TIME_ACCESS |
| 231 | | FATTR4_WORD1_TIME_METADATA |
| 232 | | FATTR4_WORD1_TIME_MODIFY, |
| 233 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 234 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 235 | | FATTR4_WORD2_SECURITY_LABEL |
| 236 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 237 | }; |
| 238 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 239 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 240 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 241 | | FATTR4_WORD0_FILEID, |
| 242 | }; |
| 243 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 244 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | FATTR4_WORD0_FILES_AVAIL |
| 246 | | FATTR4_WORD0_FILES_FREE |
| 247 | | FATTR4_WORD0_FILES_TOTAL, |
| 248 | FATTR4_WORD1_SPACE_AVAIL |
| 249 | | FATTR4_WORD1_SPACE_FREE |
| 250 | | FATTR4_WORD1_SPACE_TOTAL |
| 251 | }; |
| 252 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 253 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | FATTR4_WORD0_MAXLINK |
| 255 | | FATTR4_WORD0_MAXNAME, |
| 256 | 0 |
| 257 | }; |
| 258 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 259 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | | FATTR4_WORD0_MAXREAD |
| 261 | | FATTR4_WORD0_MAXWRITE |
| 262 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 263 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 264 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 265 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 266 | | FATTR4_WORD2_CLONE_BLKSIZE |
Frank van der Linden | b78ef84 | 2020-06-23 22:38:55 +0000 | [diff] [blame] | 267 | | FATTR4_WORD2_XATTR_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | }; |
| 269 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 270 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 271 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 272 | | FATTR4_WORD0_SIZE |
| 273 | | FATTR4_WORD0_FSID |
| 274 | | FATTR4_WORD0_FILEID |
| 275 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 276 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 277 | | FATTR4_WORD1_OWNER_GROUP |
| 278 | | FATTR4_WORD1_RAWDEV |
| 279 | | FATTR4_WORD1_SPACE_USED |
| 280 | | FATTR4_WORD1_TIME_ACCESS |
| 281 | | FATTR4_WORD1_TIME_METADATA |
| 282 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 283 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 284 | }; |
| 285 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 286 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 287 | struct inode *inode, unsigned long flags) |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 288 | { |
| 289 | unsigned long cache_validity; |
| 290 | |
| 291 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 292 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 293 | return; |
| 294 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 295 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity) | flags; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 296 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 297 | /* Remove the attributes over which we have full control */ |
| 298 | dst[1] &= ~FATTR4_WORD1_RAWDEV; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 299 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 300 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 301 | |
| 302 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 303 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 304 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 305 | if (!(cache_validity & NFS_INO_INVALID_OTHER)) |
| 306 | dst[1] &= ~(FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | |
| 307 | FATTR4_WORD1_OWNER_GROUP); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 308 | } |
| 309 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 310 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | struct nfs4_readdir_arg *readdir) |
| 312 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 313 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 314 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 317 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | readdir->cookie = 0; |
| 323 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 324 | if (cookie == 2) |
| 325 | return; |
| 326 | |
| 327 | /* |
| 328 | * NFSv4 servers do not return entries for '.' and '..' |
| 329 | * Therefore, we fake these entries here. We let '.' |
| 330 | * have cookie 0 and '..' have cookie 1. Note that |
| 331 | * when talking to the server, we always send cookie 0 |
| 332 | * instead of 1 or 2. |
| 333 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 334 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | if (cookie == 0) { |
| 337 | *p++ = xdr_one; /* next */ |
| 338 | *p++ = xdr_zero; /* cookie, first word */ |
| 339 | *p++ = xdr_one; /* cookie, second word */ |
| 340 | *p++ = xdr_one; /* entry len */ |
| 341 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 342 | p++; |
| 343 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 344 | *p++ = htonl(attrs); /* bitmap */ |
| 345 | *p++ = htonl(12); /* attribute buffer length */ |
| 346 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 347 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | *p++ = xdr_one; /* next */ |
| 351 | *p++ = xdr_zero; /* cookie, first word */ |
| 352 | *p++ = xdr_two; /* cookie, second word */ |
| 353 | *p++ = xdr_two; /* entry len */ |
| 354 | memcpy(p, "..\0\0", 4); /* entry */ |
| 355 | p++; |
| 356 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 357 | *p++ = htonl(attrs); /* bitmap */ |
| 358 | *p++ = htonl(12); /* attribute buffer length */ |
| 359 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 360 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | readdir->pgbase = (char *)p - (char *)start; |
| 363 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 364 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 367 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 368 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 369 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 370 | { |
| 371 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 372 | |
| 373 | ops->test_and_free_expired(server, stateid, cred); |
| 374 | } |
| 375 | |
| 376 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 377 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 378 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 379 | { |
| 380 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 381 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 382 | } |
| 383 | |
| 384 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 385 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 386 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 387 | { |
| 388 | nfs4_stateid tmp; |
| 389 | |
| 390 | nfs4_stateid_copy(&tmp, stateid); |
| 391 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 392 | } |
| 393 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 394 | static long nfs4_update_delay(long *timeout) |
| 395 | { |
| 396 | long ret; |
| 397 | if (!timeout) |
| 398 | return NFS4_POLL_RETRY_MAX; |
| 399 | if (*timeout <= 0) |
| 400 | *timeout = NFS4_POLL_RETRY_MIN; |
| 401 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 402 | *timeout = NFS4_POLL_RETRY_MAX; |
| 403 | ret = *timeout; |
| 404 | *timeout <<= 1; |
| 405 | return ret; |
| 406 | } |
| 407 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 408 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 409 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 410 | might_sleep(); |
| 411 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 412 | freezable_schedule_timeout_killable_unsafe( |
| 413 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 414 | if (!__fatal_signal_pending(current)) |
| 415 | return 0; |
| 416 | return -EINTR; |
| 417 | } |
| 418 | |
| 419 | static int nfs4_delay_interruptible(long *timeout) |
| 420 | { |
| 421 | might_sleep(); |
| 422 | |
He Zhe | 59679d9 | 2020-07-06 17:52:24 +0800 | [diff] [blame] | 423 | freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 424 | if (!signal_pending(current)) |
| 425 | return 0; |
| 426 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 427 | } |
| 428 | |
| 429 | static int nfs4_delay(long *timeout, bool interruptible) |
| 430 | { |
| 431 | if (interruptible) |
| 432 | return nfs4_delay_interruptible(timeout); |
| 433 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 434 | } |
| 435 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 436 | static const nfs4_stateid * |
| 437 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 438 | { |
| 439 | if (!stateid) |
| 440 | return NULL; |
| 441 | switch (stateid->type) { |
| 442 | case NFS4_OPEN_STATEID_TYPE: |
| 443 | case NFS4_LOCK_STATEID_TYPE: |
| 444 | case NFS4_DELEGATION_STATEID_TYPE: |
| 445 | return stateid; |
| 446 | default: |
| 447 | break; |
| 448 | } |
| 449 | return NULL; |
| 450 | } |
| 451 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 452 | /* This is the error handling routine for processes that are allowed |
| 453 | * to sleep. |
| 454 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 455 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 456 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 457 | { |
| 458 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 459 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 460 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 461 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 462 | int ret = errorcode; |
| 463 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 464 | exception->delay = 0; |
| 465 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 466 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 467 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 468 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 469 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 470 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 471 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 472 | switch(errorcode) { |
| 473 | case 0: |
| 474 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 475 | case -NFS4ERR_BADHANDLE: |
| 476 | case -ESTALE: |
| 477 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 478 | pnfs_destroy_layout(NFS_I(inode)); |
| 479 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 480 | case -NFS4ERR_DELEG_REVOKED: |
| 481 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 482 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 483 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame] | 484 | case -NFS4ERR_PARTNER_NO_AUTH: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 485 | if (inode != NULL && stateid != NULL) { |
| 486 | nfs_inode_find_state_and_recover(inode, |
| 487 | stateid); |
| 488 | goto wait_on_recovery; |
| 489 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 490 | fallthrough; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 491 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 492 | if (inode) { |
| 493 | int err; |
| 494 | |
| 495 | err = nfs_async_inode_return_delegation(inode, |
| 496 | stateid); |
| 497 | if (err == 0) |
| 498 | goto wait_on_recovery; |
| 499 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 500 | exception->retry = 1; |
| 501 | break; |
| 502 | } |
| 503 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 504 | if (state == NULL) |
| 505 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 506 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 507 | if (ret < 0) |
| 508 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 509 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 510 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 511 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 512 | nfs4_schedule_lease_recovery(clp); |
| 513 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 514 | case -NFS4ERR_MOVED: |
| 515 | ret = nfs4_schedule_migration_recovery(server); |
| 516 | if (ret < 0) |
| 517 | break; |
| 518 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 519 | case -NFS4ERR_LEASE_MOVED: |
| 520 | nfs4_schedule_lease_moved_recovery(clp); |
| 521 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 522 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 523 | case -NFS4ERR_BADSESSION: |
| 524 | case -NFS4ERR_BADSLOT: |
| 525 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 526 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 527 | case -NFS4ERR_DEADSESSION: |
| 528 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 529 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 530 | /* Handled in nfs41_sequence_process() */ |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 531 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 532 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 533 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 534 | if (exception->timeout > HZ) { |
| 535 | /* We have retried a decent amount, time to |
| 536 | * fail |
| 537 | */ |
| 538 | ret = -EBUSY; |
| 539 | break; |
| 540 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 541 | fallthrough; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 542 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 543 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 544 | fallthrough; |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 545 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 546 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 547 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 548 | exception->delay = 1; |
| 549 | return 0; |
| 550 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 551 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 552 | case -NFS4ERR_OLD_STATEID: |
| 553 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 554 | break; |
| 555 | case -NFS4ERR_BADOWNER: |
| 556 | /* The following works around a Linux server bug! */ |
| 557 | case -NFS4ERR_BADNAME: |
| 558 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 559 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 560 | exception->retry = 1; |
| 561 | printk(KERN_WARNING "NFS: v4 server %s " |
| 562 | "does not accept raw " |
| 563 | "uid/gids. " |
| 564 | "Reenabling the idmapper.\n", |
| 565 | server->nfs_client->cl_hostname); |
| 566 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 567 | } |
| 568 | /* We failed to handle the error */ |
| 569 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 570 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 571 | exception->recovering = 1; |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | /* This is the error handling routine for processes that are allowed |
| 576 | * to sleep. |
| 577 | */ |
| 578 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 579 | { |
| 580 | struct nfs_client *clp = server->nfs_client; |
| 581 | int ret; |
| 582 | |
| 583 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 584 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 585 | ret = nfs4_delay(&exception->timeout, |
| 586 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 587 | goto out_retry; |
| 588 | } |
| 589 | if (exception->recovering) { |
| 590 | ret = nfs4_wait_clnt_recover(clp); |
| 591 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 592 | return -EIO; |
| 593 | goto out_retry; |
| 594 | } |
| 595 | return ret; |
| 596 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 597 | if (ret == 0) |
| 598 | exception->retry = 1; |
| 599 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 600 | } |
| 601 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 602 | static int |
| 603 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 604 | int errorcode, struct nfs4_exception *exception) |
| 605 | { |
| 606 | struct nfs_client *clp = server->nfs_client; |
| 607 | int ret; |
| 608 | |
| 609 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 610 | if (exception->delay) { |
| 611 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 612 | goto out_retry; |
| 613 | } |
| 614 | if (exception->recovering) { |
| 615 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 616 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 617 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 618 | goto out_retry; |
| 619 | } |
| 620 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 621 | ret = -EIO; |
| 622 | return ret; |
| 623 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 624 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 625 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 626 | /* |
| 627 | * For NFS4ERR_MOVED, the client transport will need to |
| 628 | * be recomputed after migration recovery has completed. |
| 629 | */ |
| 630 | if (errorcode == -NFS4ERR_MOVED) |
| 631 | rpc_task_release_transport(task); |
| 632 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 633 | return ret; |
| 634 | } |
| 635 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 636 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 637 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 638 | struct nfs4_state *state, long *timeout) |
| 639 | { |
| 640 | struct nfs4_exception exception = { |
| 641 | .state = state, |
| 642 | }; |
| 643 | |
| 644 | if (task->tk_status >= 0) |
| 645 | return 0; |
| 646 | if (timeout) |
| 647 | exception.timeout = *timeout; |
| 648 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 649 | task->tk_status, |
| 650 | &exception); |
| 651 | if (exception.delay && timeout) |
| 652 | *timeout = exception.timeout; |
| 653 | if (exception.retry) |
| 654 | return -EAGAIN; |
| 655 | return 0; |
| 656 | } |
| 657 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 658 | /* |
| 659 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 660 | * or 'false' otherwise. |
| 661 | */ |
| 662 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 663 | { |
| 664 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 665 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 666 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 667 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 668 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | spin_lock(&clp->cl_lock); |
| 671 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 672 | clp->cl_last_renewal = timestamp; |
| 673 | spin_unlock(&clp->cl_lock); |
| 674 | } |
| 675 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 676 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 677 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 678 | struct nfs_client *clp = server->nfs_client; |
| 679 | |
| 680 | if (!nfs4_has_session(clp)) |
| 681 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 682 | } |
| 683 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 684 | struct nfs4_call_sync_data { |
| 685 | const struct nfs_server *seq_server; |
| 686 | struct nfs4_sequence_args *seq_args; |
| 687 | struct nfs4_sequence_res *seq_res; |
| 688 | }; |
| 689 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 690 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 691 | struct nfs4_sequence_res *res, int cache_reply, |
| 692 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 693 | { |
| 694 | args->sa_slot = NULL; |
| 695 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 696 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 697 | |
| 698 | res->sr_slot = NULL; |
| 699 | } |
| 700 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 701 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 702 | { |
| 703 | struct nfs4_slot *slot = res->sr_slot; |
| 704 | struct nfs4_slot_table *tbl; |
| 705 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 706 | tbl = slot->table; |
| 707 | spin_lock(&tbl->slot_tbl_lock); |
| 708 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 709 | nfs4_free_slot(tbl, slot); |
| 710 | spin_unlock(&tbl->slot_tbl_lock); |
| 711 | |
| 712 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static int nfs40_sequence_done(struct rpc_task *task, |
| 716 | struct nfs4_sequence_res *res) |
| 717 | { |
| 718 | if (res->sr_slot != NULL) |
| 719 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 720 | return 1; |
| 721 | } |
| 722 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 723 | #if defined(CONFIG_NFS_V4_1) |
| 724 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 725 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 726 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 727 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 728 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 729 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 730 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 731 | if (!slot) |
| 732 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 733 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 734 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 735 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 736 | /* Bump the slot sequence number */ |
| 737 | if (slot->seq_done) |
| 738 | slot->seq_nr++; |
| 739 | slot->seq_done = 0; |
| 740 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 741 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 742 | /* Be nice to the server: try to ensure that the last transmitted |
| 743 | * value for highest_user_slotid <= target_highest_slotid |
| 744 | */ |
| 745 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 746 | send_new_highest_used_slotid = true; |
| 747 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 748 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 749 | send_new_highest_used_slotid = false; |
| 750 | goto out_unlock; |
| 751 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 752 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 753 | |
| 754 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 755 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 756 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 757 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 758 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 759 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 760 | if (waitqueue_active(&tbl->slot_waitq)) |
| 761 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 762 | } |
| 763 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 764 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 765 | { |
| 766 | nfs41_release_slot(res->sr_slot); |
| 767 | res->sr_slot = NULL; |
| 768 | } |
| 769 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 770 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 771 | u32 seqnr) |
| 772 | { |
| 773 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 774 | slot->seq_nr_highest_sent = seqnr; |
| 775 | } |
| 776 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 777 | u32 seqnr) |
| 778 | { |
| 779 | slot->seq_nr_highest_sent = seqnr; |
| 780 | slot->seq_nr_last_acked = seqnr; |
| 781 | } |
| 782 | |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 783 | static void nfs4_probe_sequence(struct nfs_client *client, const struct cred *cred, |
| 784 | struct nfs4_slot *slot) |
| 785 | { |
| 786 | struct rpc_task *task = _nfs41_proc_sequence(client, cred, slot, true); |
| 787 | if (!IS_ERR(task)) |
| 788 | rpc_put_task_async(task); |
| 789 | } |
| 790 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 791 | static int nfs41_sequence_process(struct rpc_task *task, |
| 792 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 793 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 794 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 795 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 796 | struct nfs_client *clp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 797 | int status; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 798 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 799 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 800 | if (slot == NULL) |
| 801 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 802 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 803 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 804 | goto out; |
| 805 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 806 | session = slot->table->session; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 807 | clp = session->clp; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 808 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 809 | trace_nfs4_sequence_done(session, res); |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 810 | |
| 811 | status = res->sr_status; |
| 812 | if (task->tk_status == -NFS4ERR_DEADSESSION) |
| 813 | status = -NFS4ERR_DEADSESSION; |
| 814 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 815 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 816 | switch (status) { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 817 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 818 | /* Mark this sequence number as having been acked */ |
| 819 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 820 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 821 | slot->seq_done = 1; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 822 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 823 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 824 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 825 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 826 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 827 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 828 | case 1: |
| 829 | /* |
| 830 | * sr_status remains 1 if an RPC level error occurred. |
| 831 | * The server may or may not have processed the sequence |
| 832 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 833 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 834 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 835 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 836 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 837 | case -NFS4ERR_DELAY: |
| 838 | /* The server detected a resend of the RPC call and |
| 839 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 840 | * of RFC5661. |
| 841 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 842 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 843 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 844 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 845 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 846 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 847 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 848 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 849 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 850 | /* |
| 851 | * The server thinks we tried to replay a request. |
| 852 | * Retry the call after bumping the sequence ID. |
| 853 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 854 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 855 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 856 | case -NFS4ERR_BADSLOT: |
| 857 | /* |
| 858 | * The slot id we used was probably retired. Try again |
| 859 | * using a different slot id. |
| 860 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 861 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 862 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 863 | goto retry_nowait; |
| 864 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 865 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 866 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 867 | * Were one or more calls using this slot interrupted? |
| 868 | * If the server never received the request, then our |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 869 | * transmitted slot sequence number may be too high. However, |
| 870 | * if the server did receive the request then it might |
| 871 | * accidentally give us a reply with a mismatched operation. |
| 872 | * We can sort this out by sending a lone sequence operation |
| 873 | * to the server on the same slot. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 874 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 875 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 876 | slot->seq_nr--; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 877 | if (task->tk_msg.rpc_proc != &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE]) { |
| 878 | nfs4_probe_sequence(clp, task->tk_msg.rpc_cred, slot); |
| 879 | res->sr_slot = NULL; |
| 880 | } |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 881 | goto retry_nowait; |
| 882 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 883 | /* |
| 884 | * RFC5661: |
| 885 | * A retry might be sent while the original request is |
| 886 | * still in progress on the replier. The replier SHOULD |
| 887 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 888 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 889 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 890 | * |
| 891 | * Restart the search after a delay. |
| 892 | */ |
| 893 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 894 | goto out_retry; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 895 | case -NFS4ERR_BADSESSION: |
| 896 | case -NFS4ERR_DEADSESSION: |
| 897 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 898 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 899 | default: |
| 900 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 901 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 902 | } |
| 903 | out: |
| 904 | /* The session may be reset by one of the error handlers. */ |
| 905 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 906 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 907 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 908 | session_recover: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 909 | nfs4_schedule_session_recovery(session, status); |
| 910 | dprintk("%s ERROR: %d Reset session\n", __func__, status); |
| 911 | nfs41_sequence_free_slot(res); |
| 912 | goto out; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 913 | retry_new_seq: |
| 914 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 915 | retry_nowait: |
| 916 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 917 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 918 | task->tk_status = 0; |
| 919 | ret = 0; |
| 920 | } |
| 921 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 922 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 923 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 924 | goto out; |
| 925 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 926 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 927 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 928 | |
| 929 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 930 | { |
| 931 | if (!nfs41_sequence_process(task, res)) |
| 932 | return 0; |
| 933 | if (res->sr_slot != NULL) |
| 934 | nfs41_sequence_free_slot(res); |
| 935 | return 1; |
| 936 | |
| 937 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 938 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 939 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 940 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 941 | { |
| 942 | if (res->sr_slot == NULL) |
| 943 | return 1; |
| 944 | if (res->sr_slot->table->session != NULL) |
| 945 | return nfs41_sequence_process(task, res); |
| 946 | return nfs40_sequence_done(task, res); |
| 947 | } |
| 948 | |
| 949 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 950 | { |
| 951 | if (res->sr_slot != NULL) { |
| 952 | if (res->sr_slot->table->session != NULL) |
| 953 | nfs41_sequence_free_slot(res); |
| 954 | else |
| 955 | nfs40_sequence_free_slot(res); |
| 956 | } |
| 957 | } |
| 958 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 959 | 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] | 960 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 961 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 962 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 963 | if (!res->sr_slot->table->session) |
| 964 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 965 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 966 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 967 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 968 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 969 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 970 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 971 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 972 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 973 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 974 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 975 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 976 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 977 | } |
| 978 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 979 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 980 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 981 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 982 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 983 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 984 | } |
| 985 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 986 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 987 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 988 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 989 | }; |
| 990 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 991 | #else /* !CONFIG_NFS_V4_1 */ |
| 992 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 993 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 994 | { |
| 995 | return nfs40_sequence_done(task, res); |
| 996 | } |
| 997 | |
| 998 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 999 | { |
| 1000 | if (res->sr_slot != NULL) |
| 1001 | nfs40_sequence_free_slot(res); |
| 1002 | } |
| 1003 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1004 | int nfs4_sequence_done(struct rpc_task *task, |
| 1005 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1006 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1007 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1008 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1009 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1010 | |
| 1011 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1012 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1013 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 1014 | { |
| 1015 | res->sr_timestamp = jiffies; |
| 1016 | res->sr_status_flags = 0; |
| 1017 | res->sr_status = 1; |
| 1018 | } |
| 1019 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1020 | static |
| 1021 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 1022 | struct nfs4_sequence_res *res, |
| 1023 | struct nfs4_slot *slot) |
| 1024 | { |
| 1025 | if (!slot) |
| 1026 | return; |
| 1027 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 1028 | args->sa_slot = slot; |
| 1029 | |
| 1030 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1034 | struct nfs4_sequence_args *args, |
| 1035 | struct nfs4_sequence_res *res, |
| 1036 | struct rpc_task *task) |
| 1037 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1038 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1039 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1040 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1041 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1042 | /* slot already allocated? */ |
| 1043 | if (res->sr_slot != NULL) |
| 1044 | goto out_start; |
| 1045 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1046 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1047 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1048 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1049 | spin_lock(&tbl->slot_tbl_lock); |
| 1050 | /* The state manager will wait until the slot table is empty */ |
| 1051 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1052 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1053 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1054 | slot = nfs4_alloc_slot(tbl); |
| 1055 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1056 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1057 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1058 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1059 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1060 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1061 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1062 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1063 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1064 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1065 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1066 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1067 | rpc_call_start(task); |
| 1068 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1069 | out_sleep_timeout: |
| 1070 | /* Try again in 1/4 second */ |
| 1071 | if (args->sa_privileged) |
| 1072 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1073 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1074 | else |
| 1075 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1076 | NULL, jiffies + (HZ >> 2)); |
| 1077 | spin_unlock(&tbl->slot_tbl_lock); |
| 1078 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1079 | out_sleep: |
| 1080 | if (args->sa_privileged) |
| 1081 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1082 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1083 | else |
| 1084 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1085 | spin_unlock(&tbl->slot_tbl_lock); |
| 1086 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1087 | } |
| 1088 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1089 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1090 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1091 | { |
| 1092 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1093 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1094 | data->seq_args, data->seq_res, task); |
| 1095 | } |
| 1096 | |
| 1097 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1098 | { |
| 1099 | struct nfs4_call_sync_data *data = calldata; |
| 1100 | nfs4_sequence_done(task, data->seq_res); |
| 1101 | } |
| 1102 | |
| 1103 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1104 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1105 | .rpc_call_done = nfs40_call_sync_done, |
| 1106 | }; |
| 1107 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1108 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1109 | { |
| 1110 | int ret; |
| 1111 | struct rpc_task *task; |
| 1112 | |
| 1113 | task = rpc_run_task(task_setup); |
| 1114 | if (IS_ERR(task)) |
| 1115 | return PTR_ERR(task); |
| 1116 | |
| 1117 | ret = task->tk_status; |
| 1118 | rpc_put_task(task); |
| 1119 | return ret; |
| 1120 | } |
| 1121 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1122 | static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
| 1123 | struct nfs_server *server, |
| 1124 | struct rpc_message *msg, |
| 1125 | struct nfs4_sequence_args *args, |
| 1126 | struct nfs4_sequence_res *res, |
| 1127 | unsigned short task_flags) |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1128 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1129 | struct nfs_client *clp = server->nfs_client; |
| 1130 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1131 | .seq_server = server, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1132 | .seq_args = args, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1133 | .seq_res = res, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1134 | }; |
| 1135 | struct rpc_task_setup task_setup = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1136 | .rpc_client = clnt, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1137 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1138 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1139 | .callback_data = &data, |
| 1140 | .flags = task_flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1141 | }; |
| 1142 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1143 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1144 | } |
| 1145 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1146 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 1147 | struct nfs_server *server, |
| 1148 | struct rpc_message *msg, |
| 1149 | struct nfs4_sequence_args *args, |
| 1150 | struct nfs4_sequence_res *res) |
| 1151 | { |
| 1152 | return nfs4_do_call_sync(clnt, server, msg, args, res, 0); |
| 1153 | } |
| 1154 | |
| 1155 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1156 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1157 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1158 | struct rpc_message *msg, |
| 1159 | struct nfs4_sequence_args *args, |
| 1160 | struct nfs4_sequence_res *res, |
| 1161 | int cache_reply) |
| 1162 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1163 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1164 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1167 | static void |
| 1168 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1169 | { |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame^] | 1170 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_NLINK); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1171 | inc_nlink(inode); |
| 1172 | } |
| 1173 | |
| 1174 | static void |
| 1175 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1176 | { |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame^] | 1177 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_NLINK); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1178 | drop_nlink(inode); |
| 1179 | } |
| 1180 | |
| 1181 | static void |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1182 | nfs4_update_changeattr_locked(struct inode *inode, |
| 1183 | struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1184 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1186 | struct nfs_inode *nfsi = NFS_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 1188 | cache_validity |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1189 | |
| 1190 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(inode)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1191 | nfsi->attrtimeo_timestamp = jiffies; |
| 1192 | } else { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1193 | if (S_ISDIR(inode->i_mode)) { |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 1194 | cache_validity |= NFS_INO_INVALID_DATA; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1195 | nfs_force_lookup_revalidate(inode); |
| 1196 | } else { |
| 1197 | if (!NFS_PROTO(inode)->have_delegation(inode, |
| 1198 | FMODE_READ)) |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 1199 | cache_validity |= NFS_INO_REVAL_PAGECACHE; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | if (cinfo->before != inode_peek_iversion_raw(inode)) |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 1203 | cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1204 | NFS_INO_INVALID_ACL | |
| 1205 | NFS_INO_INVALID_XATTR; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1206 | } |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1207 | inode_set_iversion_raw(inode, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1208 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1209 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 1210 | nfs_set_cache_invalid(inode, cache_validity); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1211 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1212 | } |
| 1213 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1214 | void |
| 1215 | nfs4_update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1216 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1217 | { |
| 1218 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1219 | nfs4_update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | spin_unlock(&dir->i_lock); |
| 1221 | } |
| 1222 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1223 | struct nfs4_open_createattrs { |
| 1224 | struct nfs4_label *label; |
| 1225 | struct iattr *sattr; |
| 1226 | const __u32 verf[2]; |
| 1227 | }; |
| 1228 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1229 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1230 | int err, struct nfs4_exception *exception) |
| 1231 | { |
| 1232 | if (err != -EINVAL) |
| 1233 | return false; |
| 1234 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1235 | return false; |
| 1236 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1237 | exception->retry = 1; |
| 1238 | return true; |
| 1239 | } |
| 1240 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1241 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1242 | { |
| 1243 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1244 | } |
| 1245 | |
| 1246 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1247 | { |
| 1248 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1249 | |
| 1250 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1251 | } |
| 1252 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1253 | static u32 |
| 1254 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1255 | fmode_t fmode, int openflags) |
| 1256 | { |
| 1257 | u32 res = 0; |
| 1258 | |
| 1259 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1260 | case FMODE_READ: |
| 1261 | res = NFS4_SHARE_ACCESS_READ; |
| 1262 | break; |
| 1263 | case FMODE_WRITE: |
| 1264 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1265 | break; |
| 1266 | case FMODE_READ|FMODE_WRITE: |
| 1267 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1268 | } |
| 1269 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1270 | goto out; |
| 1271 | /* Want no delegation if we're using O_DIRECT */ |
| 1272 | if (openflags & O_DIRECT) |
| 1273 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1274 | out: |
| 1275 | return res; |
| 1276 | } |
| 1277 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1278 | static enum open_claim_type4 |
| 1279 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1280 | enum open_claim_type4 claim) |
| 1281 | { |
| 1282 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1283 | return claim; |
| 1284 | switch (claim) { |
| 1285 | default: |
| 1286 | return claim; |
| 1287 | case NFS4_OPEN_CLAIM_FH: |
| 1288 | return NFS4_OPEN_CLAIM_NULL; |
| 1289 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1290 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1291 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1292 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1293 | } |
| 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
| 1296 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1297 | { |
| 1298 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1299 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1300 | p->o_res.seqid = p->o_arg.seqid; |
| 1301 | p->c_res.seqid = p->c_arg.seqid; |
| 1302 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1303 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1304 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1305 | 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] | 1306 | } |
| 1307 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1308 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1309 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1310 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1311 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1312 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1313 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1314 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1315 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1316 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1317 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1318 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1319 | struct nfs4_opendata *p; |
| 1320 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1321 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1322 | if (p == NULL) |
| 1323 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1324 | |
| 1325 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1326 | if (IS_ERR(p->f_label)) |
| 1327 | goto err_free_p; |
| 1328 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1329 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1330 | if (IS_ERR(p->a_label)) |
| 1331 | goto err_free_f; |
| 1332 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1333 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1334 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1335 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1336 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1337 | nfs_sb_active(dentry->d_sb); |
| 1338 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1339 | p->dir = parent; |
| 1340 | p->owner = sp; |
| 1341 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1342 | p->o_arg.open_flags = flags; |
| 1343 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1344 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1345 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1346 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1347 | if (flags & O_CREAT) { |
| 1348 | p->o_arg.umask = current_umask(); |
| 1349 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1350 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1351 | p->o_arg.u.attrs = &p->attrs; |
| 1352 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1353 | |
| 1354 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1355 | sizeof(p->o_arg.u.verifier.data)); |
| 1356 | } |
| 1357 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1358 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1359 | * will return permission denied for all bits until close */ |
| 1360 | if (!(flags & O_EXCL)) { |
| 1361 | /* ask server to check for all possible rights as results |
| 1362 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1363 | switch (p->o_arg.claim) { |
| 1364 | default: |
| 1365 | break; |
| 1366 | case NFS4_OPEN_CLAIM_NULL: |
| 1367 | case NFS4_OPEN_CLAIM_FH: |
| 1368 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1369 | NFS4_ACCESS_MODIFY | |
| 1370 | NFS4_ACCESS_EXTEND | |
| 1371 | NFS4_ACCESS_EXECUTE; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1372 | #ifdef CONFIG_NFS_V4_2 |
| 1373 | if (server->caps & NFS_CAP_XATTR) |
| 1374 | p->o_arg.access |= NFS4_ACCESS_XAREAD | |
| 1375 | NFS4_ACCESS_XAWRITE | |
| 1376 | NFS4_ACCESS_XALIST; |
| 1377 | #endif |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1378 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1379 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1380 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1381 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1382 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1383 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1384 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1385 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1386 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1387 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1388 | case NFS4_OPEN_CLAIM_NULL: |
| 1389 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1390 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1391 | p->o_arg.fh = NFS_FH(dir); |
| 1392 | break; |
| 1393 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1394 | case NFS4_OPEN_CLAIM_FH: |
| 1395 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1396 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1397 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1398 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1399 | p->c_arg.fh = &p->o_res.fh; |
| 1400 | p->c_arg.stateid = &p->o_res.stateid; |
| 1401 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1402 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1403 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1404 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1405 | |
| 1406 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1407 | nfs4_label_free(p->a_label); |
| 1408 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1409 | nfs4_label_free(p->f_label); |
| 1410 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1411 | kfree(p); |
| 1412 | err: |
| 1413 | dput(parent); |
| 1414 | return NULL; |
| 1415 | } |
| 1416 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1417 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1418 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1419 | struct nfs4_opendata *p = container_of(kref, |
| 1420 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1421 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1422 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1423 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1424 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1425 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1426 | if (p->state != NULL) |
| 1427 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1428 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1429 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1430 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1431 | nfs4_label_free(p->f_label); |
| 1432 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1433 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1434 | dput(p->dentry); |
| 1435 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1436 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1437 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1438 | kfree(p); |
| 1439 | } |
| 1440 | |
| 1441 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1442 | { |
| 1443 | if (p != NULL) |
| 1444 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1447 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1448 | fmode_t fmode) |
| 1449 | { |
| 1450 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1451 | case FMODE_READ|FMODE_WRITE: |
| 1452 | return state->n_rdwr != 0; |
| 1453 | case FMODE_WRITE: |
| 1454 | return state->n_wronly != 0; |
| 1455 | case FMODE_READ: |
| 1456 | return state->n_rdonly != 0; |
| 1457 | } |
| 1458 | WARN_ON_ONCE(1); |
| 1459 | return false; |
| 1460 | } |
| 1461 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1462 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1463 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1464 | { |
| 1465 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1466 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1467 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1468 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1469 | switch (claim) { |
| 1470 | case NFS4_OPEN_CLAIM_NULL: |
| 1471 | case NFS4_OPEN_CLAIM_FH: |
| 1472 | goto out; |
| 1473 | default: |
| 1474 | break; |
| 1475 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1476 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1477 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1478 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1479 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1480 | break; |
| 1481 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1482 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1483 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1484 | break; |
| 1485 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1486 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1487 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1488 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1489 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1490 | return ret; |
| 1491 | } |
| 1492 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1493 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1494 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1495 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1496 | if (delegation == NULL) |
| 1497 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1498 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1499 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1500 | switch (claim) { |
| 1501 | case NFS4_OPEN_CLAIM_NULL: |
| 1502 | case NFS4_OPEN_CLAIM_FH: |
| 1503 | break; |
| 1504 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1505 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1506 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1507 | fallthrough; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1508 | default: |
| 1509 | return 0; |
| 1510 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1511 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1512 | return 1; |
| 1513 | } |
| 1514 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1515 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1516 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1517 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1518 | case FMODE_WRITE: |
| 1519 | state->n_wronly++; |
| 1520 | break; |
| 1521 | case FMODE_READ: |
| 1522 | state->n_rdonly++; |
| 1523 | break; |
| 1524 | case FMODE_READ|FMODE_WRITE: |
| 1525 | state->n_rdwr++; |
| 1526 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1527 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1528 | } |
| 1529 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1530 | #ifdef CONFIG_NFS_V4_1 |
| 1531 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1532 | { |
| 1533 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1534 | return true; |
| 1535 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1536 | return true; |
| 1537 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1538 | return true; |
| 1539 | return false; |
| 1540 | } |
| 1541 | #endif /* CONFIG_NFS_V4_1 */ |
| 1542 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1543 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1544 | { |
| 1545 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1546 | wake_up_all(&state->waitq); |
| 1547 | } |
| 1548 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1549 | 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] | 1550 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1551 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1552 | bool need_recover = false; |
| 1553 | |
| 1554 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1555 | need_recover = true; |
| 1556 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1557 | need_recover = true; |
| 1558 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1559 | need_recover = true; |
| 1560 | if (need_recover) |
| 1561 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1562 | } |
| 1563 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1564 | /* |
| 1565 | * Check for whether or not the caller may update the open stateid |
| 1566 | * to the value passed in by stateid. |
| 1567 | * |
| 1568 | * Note: This function relies heavily on the server implementing |
| 1569 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1570 | * correctly. |
| 1571 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1572 | * are then incremented on every state transition. |
| 1573 | */ |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1574 | static bool nfs_stateid_is_sequential(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1575 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1576 | { |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1577 | if (test_bit(NFS_OPEN_STATE, &state->flags)) { |
| 1578 | /* The common case - we're updating to a new sequence number */ |
| 1579 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1580 | nfs4_stateid_is_next(&state->open_stateid, stateid)) { |
| 1581 | return true; |
| 1582 | } |
| 1583 | } else { |
| 1584 | /* This is the first OPEN in this generation */ |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1585 | if (stateid->seqid == cpu_to_be32(1)) |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1586 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1587 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1588 | return false; |
| 1589 | } |
| 1590 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1591 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1592 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1593 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1594 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1595 | if (state->n_wronly) |
| 1596 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1597 | if (state->n_rdonly) |
| 1598 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1599 | if (state->n_rdwr) |
| 1600 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1601 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1602 | } |
| 1603 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1604 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1605 | nfs4_stateid *stateid, fmode_t fmode) |
| 1606 | { |
| 1607 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1608 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1609 | case FMODE_WRITE: |
| 1610 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1611 | break; |
| 1612 | case FMODE_READ: |
| 1613 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1614 | break; |
| 1615 | case 0: |
| 1616 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1617 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1618 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1619 | } |
| 1620 | if (stateid == NULL) |
| 1621 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1622 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1623 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1624 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1625 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1626 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1627 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1628 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1629 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1630 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1631 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1632 | out: |
| 1633 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1634 | } |
| 1635 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1636 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1637 | nfs4_stateid *arg_stateid, |
| 1638 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1639 | { |
| 1640 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1641 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1642 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1643 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1644 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1645 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1646 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1647 | } |
| 1648 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1649 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1650 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1651 | __must_hold(&state->owner->so_lock) |
| 1652 | __must_hold(&state->seqlock) |
| 1653 | __must_hold(RCU) |
| 1654 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1655 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1656 | DEFINE_WAIT(wait); |
| 1657 | int status = 0; |
| 1658 | for (;;) { |
| 1659 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1660 | if (nfs_stateid_is_sequential(state, stateid)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1661 | break; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1662 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1663 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1664 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1665 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1666 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1667 | break; |
| 1668 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1669 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1670 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1671 | /* |
| 1672 | * Ensure we process the state changes in the same order |
| 1673 | * in which the server processed them by delaying the |
| 1674 | * update of the stateid until we are in sequence. |
| 1675 | */ |
| 1676 | write_sequnlock(&state->seqlock); |
| 1677 | spin_unlock(&state->owner->so_lock); |
| 1678 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1679 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1680 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1681 | if (!signal_pending(current)) { |
| 1682 | if (schedule_timeout(5*HZ) == 0) |
| 1683 | status = -EAGAIN; |
| 1684 | else |
| 1685 | status = 0; |
| 1686 | } else |
| 1687 | status = -EINTR; |
| 1688 | finish_wait(&state->waitq, &wait); |
| 1689 | rcu_read_lock(); |
| 1690 | spin_lock(&state->owner->so_lock); |
| 1691 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1692 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1693 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1694 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1695 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1696 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1697 | nfs_test_and_clear_all_open_stateid(state); |
| 1698 | } |
| 1699 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1700 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1701 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1702 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1703 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1704 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1705 | } |
| 1706 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1707 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1708 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1709 | fmode_t fmode, |
| 1710 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1712 | /* |
| 1713 | * Protect the call to nfs4_state_set_mode_locked and |
| 1714 | * serialise the stateid update |
| 1715 | */ |
| 1716 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1717 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1718 | switch (fmode) { |
| 1719 | case FMODE_READ: |
| 1720 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1721 | break; |
| 1722 | case FMODE_WRITE: |
| 1723 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1724 | break; |
| 1725 | case FMODE_READ|FMODE_WRITE: |
| 1726 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1727 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1728 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1729 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1730 | } |
| 1731 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1732 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1733 | { |
| 1734 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1735 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1736 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1737 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1738 | } |
| 1739 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1740 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1741 | const nfs4_stateid *deleg_stateid, |
| 1742 | fmode_t fmode) |
| 1743 | { |
| 1744 | /* |
| 1745 | * Protect the call to nfs4_state_set_mode_locked and |
| 1746 | * serialise the stateid update |
| 1747 | */ |
| 1748 | write_seqlock(&state->seqlock); |
| 1749 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1750 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1751 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1754 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1755 | { |
| 1756 | write_seqlock(&state->seqlock); |
| 1757 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1758 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1759 | write_sequnlock(&state->seqlock); |
| 1760 | } |
| 1761 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1762 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1763 | const nfs4_stateid *open_stateid, |
| 1764 | const nfs4_stateid *delegation, |
| 1765 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1766 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1767 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1768 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1769 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1770 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1771 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1772 | int ret = 0; |
| 1773 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1774 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1775 | |
| 1776 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1777 | spin_lock(&state->owner->so_lock); |
| 1778 | if (open_stateid != NULL) { |
| 1779 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1780 | ret = 1; |
| 1781 | } |
| 1782 | |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1783 | deleg_cur = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1784 | if (deleg_cur == NULL) |
| 1785 | goto no_delegation; |
| 1786 | |
| 1787 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1788 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1789 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1790 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1791 | goto no_delegation_unlock; |
| 1792 | |
| 1793 | if (delegation == NULL) |
| 1794 | delegation = &deleg_cur->stateid; |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1795 | else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1796 | goto no_delegation_unlock; |
| 1797 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1798 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1799 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1800 | ret = 1; |
| 1801 | no_delegation_unlock: |
| 1802 | spin_unlock(&deleg_cur->lock); |
| 1803 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1804 | if (ret) |
| 1805 | update_open_stateflags(state, fmode); |
| 1806 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1807 | rcu_read_unlock(); |
| 1808 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1809 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1810 | nfs4_schedule_state_manager(clp); |
| 1811 | if (freeme.type != 0) |
| 1812 | nfs4_test_and_free_stateid(server, &freeme, |
| 1813 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1814 | |
| 1815 | return ret; |
| 1816 | } |
| 1817 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1818 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1819 | const nfs4_stateid *stateid) |
| 1820 | { |
| 1821 | struct nfs4_state *state = lsp->ls_state; |
| 1822 | bool ret = false; |
| 1823 | |
| 1824 | spin_lock(&state->state_lock); |
| 1825 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1826 | goto out_noupdate; |
| 1827 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1828 | goto out_noupdate; |
| 1829 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1830 | ret = true; |
| 1831 | out_noupdate: |
| 1832 | spin_unlock(&state->state_lock); |
| 1833 | return ret; |
| 1834 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1835 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1836 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1837 | { |
| 1838 | struct nfs_delegation *delegation; |
| 1839 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1840 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1841 | rcu_read_lock(); |
Trond Myklebust | 40e6aa1 | 2019-10-27 13:38:45 -0400 | [diff] [blame] | 1842 | delegation = nfs4_get_valid_delegation(inode); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1843 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1844 | rcu_read_unlock(); |
| 1845 | return; |
| 1846 | } |
| 1847 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1848 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1849 | } |
| 1850 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1851 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1852 | { |
| 1853 | struct nfs4_state *state = opendata->state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1854 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1855 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1856 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1857 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1858 | nfs4_stateid stateid; |
| 1859 | int ret = -EAGAIN; |
| 1860 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1861 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1862 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1863 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1864 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1865 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1866 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1867 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1868 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1869 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 1870 | delegation = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1871 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1872 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1873 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1874 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1875 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1876 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1877 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1878 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1879 | if (!opendata->is_recover) { |
| 1880 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1881 | if (ret != 0) |
| 1882 | goto out; |
| 1883 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1884 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1885 | |
| 1886 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1887 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1888 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1889 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1890 | out: |
| 1891 | return ERR_PTR(ret); |
| 1892 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1893 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1894 | return state; |
| 1895 | } |
| 1896 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1897 | static void |
| 1898 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1899 | { |
| 1900 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1901 | struct nfs_delegation *delegation; |
| 1902 | int delegation_flags = 0; |
| 1903 | |
| 1904 | rcu_read_lock(); |
| 1905 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1906 | if (delegation) |
| 1907 | delegation_flags = delegation->flags; |
| 1908 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1909 | switch (data->o_arg.claim) { |
| 1910 | default: |
| 1911 | break; |
| 1912 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1913 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1914 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1915 | "returning a delegation for " |
| 1916 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1917 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1918 | return; |
| 1919 | } |
| 1920 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1921 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1922 | data->owner->so_cred, |
| 1923 | data->o_res.delegation_type, |
| 1924 | &data->o_res.delegation, |
| 1925 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1926 | else |
| 1927 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1928 | data->owner->so_cred, |
| 1929 | data->o_res.delegation_type, |
| 1930 | &data->o_res.delegation, |
| 1931 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1932 | |
| 1933 | if (data->o_res.do_recall) |
| 1934 | nfs_async_inode_return_delegation(state->inode, |
| 1935 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | /* |
| 1939 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1940 | * and update the nfs4_state. |
| 1941 | */ |
| 1942 | static struct nfs4_state * |
| 1943 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1944 | { |
| 1945 | struct inode *inode = data->state->inode; |
| 1946 | struct nfs4_state *state = data->state; |
| 1947 | int ret; |
| 1948 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1949 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1950 | if (data->rpc_status) |
| 1951 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1952 | /* cached opens have already been processed */ |
| 1953 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1954 | } |
| 1955 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1956 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1957 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1958 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1959 | |
| 1960 | if (data->o_res.delegation_type != 0) |
| 1961 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1962 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1963 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1964 | NULL, data->o_arg.fmode)) |
| 1965 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1966 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1967 | |
| 1968 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1969 | } |
| 1970 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1971 | static struct inode * |
| 1972 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1973 | { |
| 1974 | struct inode *inode; |
| 1975 | |
| 1976 | switch (data->o_arg.claim) { |
| 1977 | case NFS4_OPEN_CLAIM_NULL: |
| 1978 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1979 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1980 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1981 | return ERR_PTR(-EAGAIN); |
| 1982 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1983 | &data->f_attr, data->f_label); |
| 1984 | break; |
| 1985 | default: |
| 1986 | inode = d_inode(data->dentry); |
| 1987 | ihold(inode); |
| 1988 | nfs_refresh_inode(inode, &data->f_attr); |
| 1989 | } |
| 1990 | return inode; |
| 1991 | } |
| 1992 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1993 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1994 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1995 | { |
| 1996 | struct nfs4_state *state; |
| 1997 | struct inode *inode; |
| 1998 | |
| 1999 | inode = nfs4_opendata_get_inode(data); |
| 2000 | if (IS_ERR(inode)) |
| 2001 | return ERR_CAST(inode); |
| 2002 | if (data->state != NULL && data->state->inode == inode) { |
| 2003 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2004 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2005 | } else |
| 2006 | state = nfs4_get_open_state(inode, data->owner); |
| 2007 | iput(inode); |
| 2008 | if (state == NULL) |
| 2009 | state = ERR_PTR(-ENOMEM); |
| 2010 | return state; |
| 2011 | } |
| 2012 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2013 | static struct nfs4_state * |
| 2014 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2015 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2016 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2017 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2018 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2019 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2020 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2021 | goto out; |
| 2022 | } |
| 2023 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2024 | state = nfs4_opendata_find_nfs4_state(data); |
| 2025 | if (IS_ERR(state)) |
| 2026 | goto out; |
| 2027 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2028 | if (data->o_res.delegation_type != 0) |
| 2029 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 2030 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 2031 | NULL, data->o_arg.fmode)) { |
| 2032 | nfs4_put_open_state(state); |
| 2033 | state = ERR_PTR(-EAGAIN); |
| 2034 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2035 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 2036 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2037 | return state; |
| 2038 | } |
| 2039 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2040 | static struct nfs4_state * |
| 2041 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2042 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2043 | struct nfs4_state *ret; |
| 2044 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2045 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2046 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2047 | else |
| 2048 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2049 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2050 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2051 | } |
| 2052 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2053 | static struct nfs_open_context * |
| 2054 | 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] | 2055 | { |
| 2056 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2057 | struct nfs_open_context *ctx; |
| 2058 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2059 | rcu_read_lock(); |
| 2060 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2061 | if (ctx->state != state) |
| 2062 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2063 | if ((ctx->mode & mode) != mode) |
| 2064 | continue; |
| 2065 | if (!get_nfs_open_context(ctx)) |
| 2066 | continue; |
| 2067 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2068 | return ctx; |
| 2069 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2070 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2071 | return ERR_PTR(-ENOENT); |
| 2072 | } |
| 2073 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2074 | static struct nfs_open_context * |
| 2075 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2076 | { |
| 2077 | struct nfs_open_context *ctx; |
| 2078 | |
| 2079 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2080 | if (!IS_ERR(ctx)) |
| 2081 | return ctx; |
| 2082 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2083 | if (!IS_ERR(ctx)) |
| 2084 | return ctx; |
| 2085 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2086 | } |
| 2087 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2088 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2089 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2090 | { |
| 2091 | struct nfs4_opendata *opendata; |
| 2092 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2093 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2094 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2095 | if (opendata == NULL) |
| 2096 | return ERR_PTR(-ENOMEM); |
| 2097 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2098 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2099 | return opendata; |
| 2100 | } |
| 2101 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2102 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2103 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2104 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2105 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2106 | int ret; |
| 2107 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2108 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2109 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2110 | opendata->o_arg.open_flags = 0; |
| 2111 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2112 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2113 | NFS_SB(opendata->dentry->d_sb), |
| 2114 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2115 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2116 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2117 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2118 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2119 | if (ret != 0) |
| 2120 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2121 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2122 | if (IS_ERR(newstate)) |
| 2123 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2124 | if (newstate != opendata->state) |
| 2125 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2126 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2127 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2131 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2132 | int ret; |
| 2133 | |
| 2134 | /* memory barrier prior to reading state->n_* */ |
| 2135 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2136 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2137 | if (ret != 0) |
| 2138 | return ret; |
| 2139 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2140 | if (ret != 0) |
| 2141 | return ret; |
| 2142 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2143 | if (ret != 0) |
| 2144 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2145 | /* |
| 2146 | * We may have performed cached opens for all three recoveries. |
| 2147 | * Check if we need to update the current stateid. |
| 2148 | */ |
| 2149 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2150 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2151 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2152 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2153 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2154 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2155 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2156 | return 0; |
| 2157 | } |
| 2158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | /* |
| 2160 | * OPEN_RECLAIM: |
| 2161 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2163 | 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] | 2164 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2165 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2166 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2167 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | int status; |
| 2169 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2170 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2171 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2172 | if (IS_ERR(opendata)) |
| 2173 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2174 | rcu_read_lock(); |
| 2175 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2176 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2177 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2178 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2179 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2180 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2181 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | return status; |
| 2183 | } |
| 2184 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2185 | 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] | 2186 | { |
| 2187 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2188 | struct nfs4_exception exception = { }; |
| 2189 | int err; |
| 2190 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2191 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2192 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2193 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2194 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2195 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2196 | break; |
| 2197 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | } while (exception.retry); |
| 2199 | return err; |
| 2200 | } |
| 2201 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2202 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2203 | { |
| 2204 | struct nfs_open_context *ctx; |
| 2205 | int ret; |
| 2206 | |
| 2207 | ctx = nfs4_state_find_open_context(state); |
| 2208 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2209 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2210 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2211 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2212 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2213 | put_nfs_open_context(ctx); |
| 2214 | return ret; |
| 2215 | } |
| 2216 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2217 | 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] | 2218 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2219 | switch (err) { |
| 2220 | default: |
| 2221 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2222 | "%d.\n", __func__, err); |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame] | 2223 | fallthrough; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2224 | case 0: |
| 2225 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2226 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2227 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2228 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2229 | break; |
| 2230 | case -NFS4ERR_BADSESSION: |
| 2231 | case -NFS4ERR_BADSLOT: |
| 2232 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2233 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2234 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2235 | return -EAGAIN; |
| 2236 | case -NFS4ERR_STALE_CLIENTID: |
| 2237 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2238 | /* Don't recall a delegation if it was lost */ |
| 2239 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2240 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2241 | case -NFS4ERR_MOVED: |
| 2242 | nfs4_schedule_migration_recovery(server); |
| 2243 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2244 | case -NFS4ERR_LEASE_MOVED: |
| 2245 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2246 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2247 | case -NFS4ERR_DELEG_REVOKED: |
| 2248 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2249 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2250 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2251 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2252 | nfs_inode_find_state_and_recover(state->inode, |
| 2253 | stateid); |
| 2254 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2255 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2256 | case -NFS4ERR_DELAY: |
| 2257 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2258 | ssleep(1); |
| 2259 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2260 | case -ENOMEM: |
| 2261 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2262 | if (fl) { |
| 2263 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2264 | if (lsp) |
| 2265 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2266 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2267 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | return err; |
| 2270 | } |
| 2271 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2272 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2273 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2274 | { |
| 2275 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2276 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2277 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2278 | |
| 2279 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2280 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2281 | if (IS_ERR(opendata)) |
| 2282 | return PTR_ERR(opendata); |
| 2283 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2284 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2285 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2286 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2287 | goto out; |
| 2288 | } |
| 2289 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2290 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2291 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2292 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2293 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2294 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2295 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2296 | if (err) |
| 2297 | goto out; |
| 2298 | } |
| 2299 | nfs_state_clear_delegation(state); |
| 2300 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2301 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2302 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2303 | } |
| 2304 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2305 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2306 | { |
| 2307 | struct nfs4_opendata *data = calldata; |
| 2308 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2309 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2310 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2311 | } |
| 2312 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2313 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2314 | { |
| 2315 | struct nfs4_opendata *data = calldata; |
| 2316 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2317 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2318 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2319 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2320 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2321 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2322 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2323 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2324 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2325 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | static void nfs4_open_confirm_release(void *calldata) |
| 2329 | { |
| 2330 | struct nfs4_opendata *data = calldata; |
| 2331 | struct nfs4_state *state = NULL; |
| 2332 | |
| 2333 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2334 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2335 | goto out_free; |
| 2336 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2337 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2338 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2339 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2340 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2341 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2342 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2343 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2347 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2348 | .rpc_call_done = nfs4_open_confirm_done, |
| 2349 | .rpc_release = nfs4_open_confirm_release, |
| 2350 | }; |
| 2351 | |
| 2352 | /* |
| 2353 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2354 | */ |
| 2355 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2356 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2357 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2358 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2359 | struct rpc_message msg = { |
| 2360 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2361 | .rpc_argp = &data->c_arg, |
| 2362 | .rpc_resp = &data->c_res, |
| 2363 | .rpc_cred = data->owner->so_cred, |
| 2364 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2365 | struct rpc_task_setup task_setup_data = { |
| 2366 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2367 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2368 | .callback_ops = &nfs4_open_confirm_ops, |
| 2369 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2370 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2371 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2372 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | int status; |
| 2374 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2375 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2376 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2377 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2378 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2379 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2380 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2381 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2382 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2383 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2384 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2385 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2386 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2387 | smp_wmb(); |
| 2388 | } else |
| 2389 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2390 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | return status; |
| 2392 | } |
| 2393 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2394 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2396 | struct nfs4_opendata *data = calldata; |
| 2397 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2398 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2399 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2400 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2401 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2402 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2403 | /* |
| 2404 | * Check if we still need to send an OPEN call, or if we can use |
| 2405 | * a delegation instead. |
| 2406 | */ |
| 2407 | if (data->state != NULL) { |
| 2408 | struct nfs_delegation *delegation; |
| 2409 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2410 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2411 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2412 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2413 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 2414 | delegation = nfs4_get_valid_delegation(data->state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2415 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2416 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2417 | rcu_read_unlock(); |
| 2418 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2419 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2420 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2421 | switch (claim) { |
| 2422 | default: |
| 2423 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2424 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2425 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2426 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2427 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2428 | fallthrough; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2429 | case NFS4_OPEN_CLAIM_FH: |
| 2430 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2431 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2432 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2433 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2434 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2435 | &data->o_res.seq_res, |
| 2436 | task) != 0) |
| 2437 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2438 | |
| 2439 | /* Set the create mode (note dependency on the session type) */ |
| 2440 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2441 | if (data->o_arg.open_flags & O_EXCL) { |
| 2442 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2443 | if (nfs4_has_persistent_session(clp)) |
| 2444 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2445 | else if (clp->cl_mvops->minor_version > 0) |
| 2446 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2447 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2448 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2449 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2450 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2451 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2452 | out_no_action: |
| 2453 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2454 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2455 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2456 | } |
| 2457 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2458 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2459 | { |
| 2460 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2462 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2463 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2464 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2465 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2466 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2467 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2468 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2469 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2470 | case S_IFREG: |
| 2471 | break; |
| 2472 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2473 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2474 | break; |
| 2475 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2476 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2477 | break; |
| 2478 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2479 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2480 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2481 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2482 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2483 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2484 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2485 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2486 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2487 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2488 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2489 | static void nfs4_open_release(void *calldata) |
| 2490 | { |
| 2491 | struct nfs4_opendata *data = calldata; |
| 2492 | struct nfs4_state *state = NULL; |
| 2493 | |
| 2494 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2495 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2496 | goto out_free; |
| 2497 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2498 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2499 | goto out_free; |
| 2500 | /* In case we need an open_confirm, no cleanup! */ |
| 2501 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2502 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2503 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2504 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2505 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2506 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2507 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2511 | .rpc_call_prepare = nfs4_open_prepare, |
| 2512 | .rpc_call_done = nfs4_open_done, |
| 2513 | .rpc_release = nfs4_open_release, |
| 2514 | }; |
| 2515 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2516 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2517 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2518 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2519 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2520 | struct nfs_server *server = NFS_SERVER(dir); |
| 2521 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2522 | struct nfs_openres *o_res = &data->o_res; |
| 2523 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2524 | struct rpc_message msg = { |
| 2525 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2526 | .rpc_argp = o_arg, |
| 2527 | .rpc_resp = o_res, |
| 2528 | .rpc_cred = data->owner->so_cred, |
| 2529 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2530 | struct rpc_task_setup task_setup_data = { |
| 2531 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2532 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2533 | .callback_ops = &nfs4_open_ops, |
| 2534 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2535 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2536 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2537 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2538 | int status; |
| 2539 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2540 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2541 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2542 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2543 | data->cancelled = false; |
| 2544 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2545 | if (!ctx) { |
| 2546 | 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] | 2547 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2548 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2549 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2550 | 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] | 2551 | pnfs_lgopen_prepare(data, ctx); |
| 2552 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2553 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2554 | if (IS_ERR(task)) |
| 2555 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2556 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2557 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2558 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2559 | smp_wmb(); |
| 2560 | } else |
| 2561 | status = data->rpc_status; |
| 2562 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2563 | |
| 2564 | return status; |
| 2565 | } |
| 2566 | |
| 2567 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2568 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2569 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2570 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2571 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2572 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2573 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2574 | if (status != 0 || !data->rpc_done) |
| 2575 | return status; |
| 2576 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2577 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2578 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2579 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2580 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2581 | |
| 2582 | return status; |
| 2583 | } |
| 2584 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2585 | /* |
| 2586 | * Additional permission checks in order to distinguish between an |
| 2587 | * open for read, and an open for execute. This works around the |
| 2588 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2589 | * the same. |
| 2590 | * Note that in the non-execute case, we want to turn off permission |
| 2591 | * checking if we just created a new file (POSIX open() semantics). |
| 2592 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2593 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2594 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2595 | struct nfs4_state *state, fmode_t fmode, |
| 2596 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2597 | { |
| 2598 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2599 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2600 | |
| 2601 | /* access call failed or for some reason the server doesn't |
| 2602 | * support any access modes -- defer access call until later */ |
| 2603 | if (opendata->o_res.access_supported == 0) |
| 2604 | return 0; |
| 2605 | |
| 2606 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2607 | /* |
| 2608 | * Use openflags to check for exec, because fmode won't |
| 2609 | * always have FMODE_EXEC set when file open for exec. |
| 2610 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2611 | if (openflags & __FMODE_EXEC) { |
| 2612 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2613 | if (S_ISDIR(state->inode->i_mode)) |
| 2614 | mask = NFS4_ACCESS_LOOKUP; |
| 2615 | else |
| 2616 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2617 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2618 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2619 | |
| 2620 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2621 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2622 | nfs_access_add_cache(state->inode, &cache); |
| 2623 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2624 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2625 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2626 | return 0; |
| 2627 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2628 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2629 | } |
| 2630 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2631 | /* |
| 2632 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2633 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2634 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2635 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2636 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2637 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2638 | struct nfs_server *server = NFS_SERVER(dir); |
| 2639 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2640 | struct nfs_openres *o_res = &data->o_res; |
| 2641 | int status; |
| 2642 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2643 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2644 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2645 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2646 | if (status != 0) { |
| 2647 | if (status == -NFS4ERR_BADNAME && |
| 2648 | !(o_arg->open_flags & O_CREAT)) |
| 2649 | return -ENOENT; |
| 2650 | return status; |
| 2651 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2652 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2653 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2654 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2655 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2656 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2657 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2658 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2659 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2660 | if (data->file_created || |
| 2661 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 2662 | nfs4_update_changeattr(dir, &o_res->cinfo, |
| 2663 | o_res->f_attr->time_start, |
| 2664 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2665 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2666 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2667 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2669 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2671 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2673 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2674 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2675 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2676 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2677 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2678 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | /* |
| 2682 | * OPEN_EXPIRED: |
| 2683 | * reclaim state on the server after a network partition. |
| 2684 | * Assumes caller holds the appropriate lock |
| 2685 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2686 | 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] | 2687 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2688 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2689 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2691 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2692 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2693 | if (IS_ERR(opendata)) |
| 2694 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2695 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2696 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2697 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2698 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2699 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2702 | 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] | 2703 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2704 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2705 | struct nfs4_exception exception = { }; |
| 2706 | int err; |
| 2707 | |
| 2708 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2709 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2710 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2711 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2712 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2713 | switch (err) { |
| 2714 | default: |
| 2715 | goto out; |
| 2716 | case -NFS4ERR_GRACE: |
| 2717 | case -NFS4ERR_DELAY: |
| 2718 | nfs4_handle_exception(server, err, &exception); |
| 2719 | err = 0; |
| 2720 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2721 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2722 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2723 | return err; |
| 2724 | } |
| 2725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2727 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2729 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2731 | ctx = nfs4_state_find_open_context(state); |
| 2732 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2733 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2734 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2735 | put_nfs_open_context(ctx); |
| 2736 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2739 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2740 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2741 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2742 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2743 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2747 | { |
| 2748 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2749 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2753 | { |
| 2754 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2755 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2756 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2757 | return nfs4_open_expired(sp, state); |
| 2758 | } |
| 2759 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2760 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2761 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2762 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2763 | { |
| 2764 | return -NFS4ERR_BAD_STATEID; |
| 2765 | } |
| 2766 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2767 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2768 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2769 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2770 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2771 | { |
| 2772 | int status; |
| 2773 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2774 | switch (stateid->type) { |
| 2775 | default: |
| 2776 | break; |
| 2777 | case NFS4_INVALID_STATEID_TYPE: |
| 2778 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2779 | return -NFS4ERR_BAD_STATEID; |
| 2780 | case NFS4_REVOKED_STATEID_TYPE: |
| 2781 | goto out_free; |
| 2782 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2783 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2784 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2785 | switch (status) { |
| 2786 | case -NFS4ERR_EXPIRED: |
| 2787 | case -NFS4ERR_ADMIN_REVOKED: |
| 2788 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2789 | break; |
| 2790 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2791 | return status; |
| 2792 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2793 | out_free: |
| 2794 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2795 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2796 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2797 | } |
| 2798 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2799 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2800 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2801 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2802 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2803 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2804 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2805 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2806 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2807 | /* Get the delegation credential for use by test/free_stateid */ |
| 2808 | rcu_read_lock(); |
| 2809 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2810 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2811 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2812 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2813 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2814 | } |
| 2815 | |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2816 | spin_lock(&delegation->lock); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2817 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2818 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2819 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2820 | &delegation->flags)) { |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2821 | spin_unlock(&delegation->lock); |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2822 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2823 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2824 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2825 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2826 | if (delegation->cred) |
| 2827 | cred = get_cred(delegation->cred); |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2828 | spin_unlock(&delegation->lock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2829 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2830 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2831 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2832 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2833 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2834 | else |
| 2835 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2836 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2837 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2838 | return ret; |
| 2839 | } |
| 2840 | |
| 2841 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2842 | { |
| 2843 | nfs4_stateid tmp; |
| 2844 | |
| 2845 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2846 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2847 | &tmp, NULL) && |
| 2848 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2849 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2850 | else |
| 2851 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2855 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2856 | * |
| 2857 | * @state: NFSv4 state for an inode |
| 2858 | * |
| 2859 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2860 | * Otherwise a negative NFS4ERR value is returned. |
| 2861 | */ |
| 2862 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2863 | { |
| 2864 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2865 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2866 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2867 | |
| 2868 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2869 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2870 | |
| 2871 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2872 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2873 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2874 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2875 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2876 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2877 | spin_unlock(&state->state_lock); |
| 2878 | |
| 2879 | nfs4_put_lock_state(prev); |
| 2880 | prev = lsp; |
| 2881 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2882 | status = nfs41_test_and_free_expired_stateid(server, |
| 2883 | &lsp->ls_stateid, |
| 2884 | cred); |
| 2885 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2886 | if (status == -NFS4ERR_EXPIRED || |
| 2887 | status == -NFS4ERR_BAD_STATEID) { |
| 2888 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2889 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2890 | if (!recover_lost_locks) |
| 2891 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2892 | } else if (status != NFS_OK) { |
| 2893 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2894 | nfs4_put_lock_state(prev); |
| 2895 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2896 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2897 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2898 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2899 | } |
| 2900 | spin_unlock(&state->state_lock); |
| 2901 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2902 | out: |
| 2903 | return ret; |
| 2904 | } |
| 2905 | |
| 2906 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2907 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2908 | * |
| 2909 | * @state: NFSv4 state for an inode |
| 2910 | * |
| 2911 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2912 | * Otherwise a negative NFS4ERR value is returned. |
| 2913 | */ |
| 2914 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2915 | { |
| 2916 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2917 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2918 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2919 | int status; |
| 2920 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2921 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2922 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2923 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2924 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2925 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2926 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2927 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2928 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2929 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2930 | if (nfs_open_stateid_recover_openmode(state)) |
| 2931 | return -NFS4ERR_OPENMODE; |
| 2932 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2936 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2937 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2938 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2939 | status = nfs41_check_delegation_stateid(state); |
| 2940 | if (status != NFS_OK) |
| 2941 | return status; |
| 2942 | nfs41_delegation_recover_stateid(state); |
| 2943 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2944 | status = nfs41_check_expired_locks(state); |
| 2945 | if (status != NFS_OK) |
| 2946 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2947 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2948 | if (status != NFS_OK) |
| 2949 | status = nfs4_open_expired(sp, state); |
| 2950 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2951 | } |
| 2952 | #endif |
| 2953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2955 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2956 | * fields corresponding to attributes that were used to store the verifier. |
| 2957 | * Make sure we clobber those fields in the later setattr call |
| 2958 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2959 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2960 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2961 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2962 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2963 | __u32 attrset[3]; |
| 2964 | unsigned ret; |
| 2965 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2966 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2967 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2968 | attrset[i] = opendata->o_res.attrset[i]; |
| 2969 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2970 | attrset[i] &= ~bitmask[i]; |
| 2971 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2972 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2973 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2974 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2975 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2976 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2977 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2978 | ret |= ATTR_ATIME_SET; |
| 2979 | else |
| 2980 | ret |= ATTR_ATIME; |
| 2981 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2982 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2983 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2984 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2985 | ret |= ATTR_MTIME_SET; |
| 2986 | else |
| 2987 | ret |= ATTR_MTIME; |
| 2988 | } |
| 2989 | |
| 2990 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2991 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2992 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2993 | } |
| 2994 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2995 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 2996 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2997 | { |
| 2998 | struct nfs4_state_owner *sp = opendata->owner; |
| 2999 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3000 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3001 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3002 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3003 | struct inode *dir = d_inode(opendata->dir); |
| 3004 | unsigned long dir_verifier; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3005 | unsigned int seq; |
| 3006 | int ret; |
| 3007 | |
| 3008 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3009 | dir_verifier = nfs_save_change_attribute(dir); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3010 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 3011 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 3012 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3013 | goto out; |
| 3014 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 3015 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3016 | ret = PTR_ERR(state); |
| 3017 | if (IS_ERR(state)) |
| 3018 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 3019 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3020 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 3021 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 3022 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 3023 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3024 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3025 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3026 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3027 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3028 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3029 | alias = d_exact_alias(dentry, state->inode); |
| 3030 | if (!alias) |
| 3031 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 3032 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 3033 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3034 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3035 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3036 | } |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | switch(opendata->o_arg.claim) { |
| 3040 | default: |
| 3041 | break; |
| 3042 | case NFS4_OPEN_CLAIM_NULL: |
| 3043 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 3044 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 3045 | if (!opendata->rpc_done) |
| 3046 | break; |
| 3047 | if (opendata->o_res.delegation_type != 0) |
| 3048 | dir_verifier = nfs_save_change_attribute(dir); |
| 3049 | nfs_set_verifier(dentry, dir_verifier); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3050 | } |
| 3051 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 3052 | /* Parse layoutget results before we check for access */ |
| 3053 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 3054 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3055 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 3056 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3057 | if (ret != 0) |
| 3058 | goto out; |
| 3059 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3060 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3061 | nfs_inode_attach_open_context(ctx); |
| 3062 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3063 | nfs4_schedule_stateid_recovery(server, state); |
| 3064 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3065 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3066 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3067 | if (!opendata->cancelled) |
| 3068 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3069 | return ret; |
| 3070 | } |
| 3071 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3072 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3073 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3075 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3076 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3077 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3078 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3079 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | { |
| 3081 | struct nfs4_state_owner *sp; |
| 3082 | struct nfs4_state *state = NULL; |
| 3083 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3084 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3085 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3086 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3087 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3088 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3089 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3090 | struct iattr *sattr = c->sattr; |
| 3091 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3092 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3093 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | |
| 3095 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3097 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3098 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3100 | goto out_err; |
| 3101 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3102 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3103 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3104 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3105 | if (d_really_is_positive(dentry)) |
| 3106 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3107 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3108 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3109 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3110 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3111 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3112 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3113 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3115 | if (label) { |
| 3116 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 3117 | if (IS_ERR(olabel)) { |
| 3118 | status = PTR_ERR(olabel); |
| 3119 | goto err_opendata_put; |
| 3120 | } |
| 3121 | } |
| 3122 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3123 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3124 | if (!opendata->f_attr.mdsthreshold) { |
| 3125 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3126 | if (!opendata->f_attr.mdsthreshold) |
| 3127 | goto err_free_label; |
| 3128 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3129 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3130 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3131 | if (d_really_is_positive(dentry)) |
| 3132 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3133 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3134 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3135 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3136 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3137 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3138 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3139 | 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] | 3140 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3141 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3142 | /* |
| 3143 | * send create attributes which was not set by open |
| 3144 | * with an extra setattr. |
| 3145 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3146 | if (attrs || label) { |
| 3147 | unsigned ia_old = sattr->ia_valid; |
| 3148 | |
| 3149 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3150 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3151 | status = nfs4_do_setattr(state->inode, cred, |
| 3152 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3153 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3154 | if (status == 0) { |
| 3155 | nfs_setattr_update_inode(state->inode, sattr, |
| 3156 | opendata->o_res.f_attr); |
| 3157 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 3158 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3159 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3160 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3161 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3162 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3163 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3164 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3165 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3166 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3167 | opendata->f_attr.mdsthreshold = NULL; |
| 3168 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3169 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3170 | nfs4_label_free(olabel); |
| 3171 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3172 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3175 | err_free_label: |
| 3176 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3177 | err_opendata_put: |
| 3178 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3179 | err_put_state_owner: |
| 3180 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | return status; |
| 3183 | } |
| 3184 | |
| 3185 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3186 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3187 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3188 | int flags, |
| 3189 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3190 | struct nfs4_label *label, |
| 3191 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3193 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3194 | struct nfs4_exception exception = { |
| 3195 | .interruptible = true, |
| 3196 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3198 | struct nfs4_open_createattrs c = { |
| 3199 | .label = label, |
| 3200 | .sattr = sattr, |
| 3201 | .verf = { |
| 3202 | [0] = (__u32)jiffies, |
| 3203 | [1] = (__u32)current->pid, |
| 3204 | }, |
| 3205 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | int status; |
| 3207 | |
| 3208 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3209 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3210 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3211 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | if (status == 0) |
| 3213 | break; |
| 3214 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3215 | * book-keeping w.r.t. state-changing operations |
| 3216 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3217 | * It is actually a sign of a bug on the client or on the server. |
| 3218 | * |
| 3219 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3220 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | * have unhashed the old state_owner for us, and that we can |
| 3222 | * therefore safely retry using a new one. We should still warn |
| 3223 | * the user though... |
| 3224 | */ |
| 3225 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3226 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3227 | " returned a bad sequence-id error!\n", |
| 3228 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | exception.retry = 1; |
| 3230 | continue; |
| 3231 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3232 | /* |
| 3233 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3234 | * state before it received the OPEN_CONFIRM. |
| 3235 | * Recover by retrying the request as per the discussion |
| 3236 | * on Page 181 of RFC3530. |
| 3237 | */ |
| 3238 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3239 | exception.retry = 1; |
| 3240 | continue; |
| 3241 | } |
Robert Milkowski | 924491f | 2020-01-28 08:37:47 +0000 | [diff] [blame] | 3242 | if (status == -NFS4ERR_EXPIRED) { |
| 3243 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 3244 | exception.retry = 1; |
| 3245 | continue; |
| 3246 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3247 | if (status == -EAGAIN) { |
| 3248 | /* We must have found a delegation */ |
| 3249 | exception.retry = 1; |
| 3250 | continue; |
| 3251 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3252 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3253 | continue; |
| 3254 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | status, &exception)); |
| 3256 | } while (exception.retry); |
| 3257 | return res; |
| 3258 | } |
| 3259 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3260 | static int _nfs4_do_setattr(struct inode *inode, |
| 3261 | struct nfs_setattrargs *arg, |
| 3262 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3263 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3264 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3265 | { |
| 3266 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3267 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3268 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3269 | .rpc_argp = arg, |
| 3270 | .rpc_resp = res, |
| 3271 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3272 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3273 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3274 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3275 | bool truncate; |
| 3276 | int status; |
| 3277 | |
| 3278 | nfs_fattr_init(res->fattr); |
| 3279 | |
| 3280 | /* Servers should only apply open mode checks for file size changes */ |
| 3281 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3282 | if (!truncate) { |
| 3283 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3284 | goto zero_stateid; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3285 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3286 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3287 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3288 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3289 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3290 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3291 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3292 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3293 | l_ctx = nfs_get_lock_context(ctx); |
| 3294 | if (IS_ERR(l_ctx)) |
| 3295 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3296 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3297 | &arg->stateid, &delegation_cred); |
| 3298 | nfs_put_lock_context(l_ctx); |
| 3299 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3300 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3301 | else if (status == -EAGAIN) |
| 3302 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3303 | } else { |
| 3304 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3305 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3306 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3307 | if (delegation_cred) |
| 3308 | msg.rpc_cred = delegation_cred; |
| 3309 | |
| 3310 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3311 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3312 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3313 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3314 | renew_lease(server, timestamp); |
| 3315 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3316 | return status; |
| 3317 | } |
| 3318 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3319 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3320 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3321 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3322 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3324 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3325 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3326 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3327 | struct nfs_setattrargs arg = { |
| 3328 | .fh = NFS_FH(inode), |
| 3329 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3331 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3332 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3333 | }; |
| 3334 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3336 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3338 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3339 | struct nfs4_exception exception = { |
| 3340 | .state = state, |
| 3341 | .inode = inode, |
| 3342 | .stateid = &arg.stateid, |
| 3343 | }; |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3344 | unsigned long adjust_flags = NFS_INO_INVALID_CHANGE; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3345 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3347 | if (sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) |
| 3348 | adjust_flags |= NFS_INO_INVALID_OTHER; |
| 3349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | do { |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3351 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, olabel), |
| 3352 | inode, adjust_flags); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3353 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3354 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3355 | switch (err) { |
| 3356 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3357 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3358 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3359 | "applying open mode checks to " |
| 3360 | "a SETATTR that is not " |
| 3361 | "changing file size.\n", |
| 3362 | server->nfs_client->cl_hostname); |
| 3363 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3364 | if (state && !(state->state & FMODE_WRITE)) { |
| 3365 | err = -EBADF; |
| 3366 | if (sattr->ia_valid & ATTR_OPEN) |
| 3367 | err = -EACCES; |
| 3368 | goto out; |
| 3369 | } |
| 3370 | } |
| 3371 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3373 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | return err; |
| 3375 | } |
| 3376 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3377 | static bool |
| 3378 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3379 | { |
| 3380 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3381 | return false; |
| 3382 | |
| 3383 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3384 | } |
| 3385 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3386 | /* |
| 3387 | * Update the seqid of an open stateid |
| 3388 | */ |
| 3389 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3390 | struct nfs4_state *state) |
| 3391 | { |
| 3392 | __be32 seqid_open; |
| 3393 | u32 dst_seqid; |
| 3394 | int seq; |
| 3395 | |
| 3396 | for (;;) { |
| 3397 | if (!nfs4_valid_open_stateid(state)) |
| 3398 | break; |
| 3399 | seq = read_seqbegin(&state->seqlock); |
| 3400 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3401 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3402 | if (read_seqretry(&state->seqlock, seq)) |
| 3403 | continue; |
| 3404 | break; |
| 3405 | } |
| 3406 | seqid_open = state->open_stateid.seqid; |
| 3407 | if (read_seqretry(&state->seqlock, seq)) |
| 3408 | continue; |
| 3409 | |
| 3410 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3411 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3412 | dst->seqid = seqid_open; |
| 3413 | break; |
| 3414 | } |
| 3415 | } |
| 3416 | |
| 3417 | /* |
| 3418 | * Update the seqid of an open stateid after receiving |
| 3419 | * NFS4ERR_OLD_STATEID |
| 3420 | */ |
| 3421 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3422 | struct nfs4_state *state) |
| 3423 | { |
| 3424 | __be32 seqid_open; |
| 3425 | u32 dst_seqid; |
| 3426 | bool ret; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3427 | int seq, status = -EAGAIN; |
| 3428 | DEFINE_WAIT(wait); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3429 | |
| 3430 | for (;;) { |
| 3431 | ret = false; |
| 3432 | if (!nfs4_valid_open_stateid(state)) |
| 3433 | break; |
| 3434 | seq = read_seqbegin(&state->seqlock); |
| 3435 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3436 | if (read_seqretry(&state->seqlock, seq)) |
| 3437 | continue; |
| 3438 | break; |
| 3439 | } |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3440 | |
| 3441 | write_seqlock(&state->seqlock); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3442 | seqid_open = state->open_stateid.seqid; |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3443 | |
| 3444 | dst_seqid = be32_to_cpu(dst->seqid); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3445 | |
| 3446 | /* Did another OPEN bump the state's seqid? try again: */ |
| 3447 | if ((s32)(be32_to_cpu(seqid_open) - dst_seqid) > 0) { |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3448 | dst->seqid = seqid_open; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3449 | write_sequnlock(&state->seqlock); |
| 3450 | ret = true; |
| 3451 | break; |
| 3452 | } |
| 3453 | |
| 3454 | /* server says we're behind but we haven't seen the update yet */ |
| 3455 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 3456 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 3457 | write_sequnlock(&state->seqlock); |
| 3458 | trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); |
| 3459 | |
| 3460 | if (signal_pending(current)) |
| 3461 | status = -EINTR; |
| 3462 | else |
| 3463 | if (schedule_timeout(5*HZ) != 0) |
| 3464 | status = 0; |
| 3465 | |
| 3466 | finish_wait(&state->waitq, &wait); |
| 3467 | |
| 3468 | if (!status) |
| 3469 | continue; |
| 3470 | if (status == -EINTR) |
| 3471 | break; |
| 3472 | |
| 3473 | /* we slept the whole 5 seconds, we must have lost a seqid */ |
| 3474 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3475 | ret = true; |
| 3476 | break; |
| 3477 | } |
| 3478 | |
| 3479 | return ret; |
| 3480 | } |
| 3481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | struct nfs4_closedata { |
| 3483 | struct inode *inode; |
| 3484 | struct nfs4_state *state; |
| 3485 | struct nfs_closeargs arg; |
| 3486 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3487 | struct { |
| 3488 | struct nfs4_layoutreturn_args arg; |
| 3489 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3490 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3491 | u32 roc_barrier; |
| 3492 | bool roc; |
| 3493 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3494 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3495 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | }; |
| 3497 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3498 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3499 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3500 | struct nfs4_closedata *calldata = data; |
| 3501 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3502 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3503 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3504 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3505 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3506 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3507 | nfs4_put_open_state(calldata->state); |
| 3508 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3509 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3510 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3511 | kfree(calldata); |
| 3512 | } |
| 3513 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3514 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3516 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3519 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3520 | struct nfs4_exception exception = { |
| 3521 | .state = state, |
| 3522 | .inode = calldata->inode, |
| 3523 | .stateid = &calldata->arg.stateid, |
| 3524 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3526 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3527 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3528 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3529 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3530 | |
| 3531 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 3532 | if (pnfs_roc_done(task, &calldata->arg.lr_args, &calldata->res.lr_res, |
| 3533 | &calldata->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3534 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3535 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3536 | /* 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] | 3537 | * the state_owner. we keep this around to process errors |
| 3538 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | switch (task->tk_status) { |
| 3540 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3541 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3542 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3543 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3544 | case -NFS4ERR_ACCESS: |
| 3545 | if (calldata->arg.bitmask != NULL) { |
| 3546 | calldata->arg.bitmask = NULL; |
| 3547 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3548 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3549 | |
| 3550 | } |
| 3551 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3552 | case -NFS4ERR_OLD_STATEID: |
| 3553 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3554 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3555 | state)) |
| 3556 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3557 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3558 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3560 | case -NFS4ERR_EXPIRED: |
| 3561 | nfs4_free_revoked_stateid(server, |
| 3562 | &calldata->arg.stateid, |
| 3563 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3564 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3565 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3566 | if (calldata->arg.fmode == 0) |
| 3567 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3568 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3570 | task->tk_status = nfs4_async_handle_exception(task, |
| 3571 | server, task->tk_status, &exception); |
| 3572 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3573 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3575 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3576 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3577 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3578 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3579 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3580 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3581 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3582 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3583 | out_restart: |
| 3584 | task->tk_status = 0; |
| 3585 | rpc_restart_call_prepare(task); |
| 3586 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3589 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3591 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3592 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3593 | struct inode *inode = calldata->inode; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3594 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3595 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3596 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3597 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3598 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3599 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3600 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3601 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3602 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3603 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3604 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3605 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3606 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3607 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3608 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3609 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3610 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3611 | if (state->n_rdonly == 0) |
| 3612 | call_close |= is_rdonly; |
| 3613 | else if (is_rdonly) |
| 3614 | calldata->arg.fmode |= FMODE_READ; |
| 3615 | if (state->n_wronly == 0) |
| 3616 | call_close |= is_wronly; |
| 3617 | else if (is_wronly) |
| 3618 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3619 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3620 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3621 | } else if (is_rdwr) |
| 3622 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3623 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3624 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3625 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3626 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3627 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3628 | |
| 3629 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3630 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3631 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3632 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3633 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3634 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3635 | nfs_release_seqid(calldata->arg.seqid); |
| 3636 | goto out_wait; |
| 3637 | } |
| 3638 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3639 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3640 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3641 | calldata->arg.lr_args = NULL; |
| 3642 | calldata->res.lr_res = NULL; |
| 3643 | } |
| 3644 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3645 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3646 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3647 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3648 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3649 | /* Close-to-open cache consistency revalidation */ |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3650 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3651 | nfs4_bitmask_set(calldata->arg.bitmask_store, |
| 3652 | server->cache_consistency_bitmask, |
| 3653 | inode, server, NULL); |
| 3654 | calldata->arg.bitmask = calldata->arg.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3655 | } else |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3656 | calldata->arg.bitmask = NULL; |
| 3657 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3658 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3659 | calldata->arg.share_access = |
| 3660 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3661 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3662 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3663 | if (calldata->res.fattr == NULL) |
| 3664 | calldata->arg.bitmask = NULL; |
| 3665 | else if (calldata->arg.bitmask == NULL) |
| 3666 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3667 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3668 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3669 | &calldata->arg.seq_args, |
| 3670 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3671 | task) != 0) |
| 3672 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3673 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3674 | return; |
| 3675 | out_no_action: |
| 3676 | task->tk_action = NULL; |
| 3677 | out_wait: |
| 3678 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | } |
| 3680 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3681 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3682 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3683 | .rpc_call_done = nfs4_close_done, |
| 3684 | .rpc_release = nfs4_free_closedata, |
| 3685 | }; |
| 3686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | /* |
| 3688 | * It is possible for data to be read/written from a mem-mapped file |
| 3689 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3690 | * This means that we can't safely call nfsv4 close on a file until |
| 3691 | * the inode is cleared. This in turn means that we are not good |
| 3692 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3693 | * share state even when we are done with one of the three share |
| 3694 | * stateid's in the inode. |
| 3695 | * |
| 3696 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3697 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3698 | 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] | 3699 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3700 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3701 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3703 | struct nfs4_state_owner *sp = state->owner; |
| 3704 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3705 | struct rpc_message msg = { |
| 3706 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3707 | .rpc_cred = state->owner->so_cred, |
| 3708 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3709 | struct rpc_task_setup task_setup_data = { |
| 3710 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3711 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3712 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3713 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 3714 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3715 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3716 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3718 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3719 | &task_setup_data.rpc_client, &msg); |
| 3720 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3721 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3723 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3724 | 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] | 3725 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3727 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3728 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3729 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3731 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3732 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3733 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3734 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3735 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3736 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3737 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3738 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3739 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3740 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3741 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3742 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3743 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3744 | if (calldata->lr.roc) { |
| 3745 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3746 | calldata->res.lr_res = &calldata->lr.res; |
| 3747 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3748 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3749 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3750 | msg.rpc_argp = &calldata->arg; |
| 3751 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3752 | task_setup_data.callback_data = calldata; |
| 3753 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3754 | if (IS_ERR(task)) |
| 3755 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3756 | status = 0; |
| 3757 | if (wait) |
| 3758 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3759 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3760 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3761 | out_free_calldata: |
| 3762 | kfree(calldata); |
| 3763 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3764 | nfs4_put_open_state(state); |
| 3765 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3766 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3769 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3770 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3771 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3774 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3775 | |
| 3776 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3778 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3779 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3780 | |
| 3781 | nfs4_label_release_security(label); |
| 3782 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3783 | if (IS_ERR(state)) |
| 3784 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3785 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | } |
| 3787 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3788 | 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] | 3789 | { |
| 3790 | if (ctx->state == NULL) |
| 3791 | return; |
| 3792 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3793 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3794 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3795 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3796 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3798 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3799 | #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] | 3800 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3803 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3804 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3805 | struct nfs4_server_caps_arg args = { |
| 3806 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3807 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3808 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | struct nfs4_server_caps_res res = {}; |
| 3810 | struct rpc_message msg = { |
| 3811 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3812 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | .rpc_resp = &res, |
| 3814 | }; |
| 3815 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3816 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3818 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3819 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3820 | FATTR4_WORD0_LINK_SUPPORT | |
| 3821 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3822 | FATTR4_WORD0_ACLSUPPORT; |
| 3823 | if (minorversion) |
| 3824 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3825 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3826 | 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] | 3827 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3828 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3829 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3830 | case 0: |
| 3831 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3832 | res.attr_bitmask[2] = 0; |
| 3833 | break; |
| 3834 | case 1: |
| 3835 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3836 | break; |
| 3837 | case 2: |
| 3838 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3841 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3842 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3843 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3844 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3845 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3846 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3847 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3848 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | server->caps |= NFS_CAP_ACLS; |
| 3850 | if (res.has_links != 0) |
| 3851 | server->caps |= NFS_CAP_HARDLINKS; |
| 3852 | if (res.has_symlinks != 0) |
| 3853 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3854 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3855 | server->caps |= NFS_CAP_FILEID; |
| 3856 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3857 | server->caps |= NFS_CAP_MODE; |
| 3858 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3859 | server->caps |= NFS_CAP_NLINK; |
| 3860 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3861 | server->caps |= NFS_CAP_OWNER; |
| 3862 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3863 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3864 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3865 | server->caps |= NFS_CAP_ATIME; |
| 3866 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3867 | server->caps |= NFS_CAP_CTIME; |
| 3868 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3869 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3870 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3871 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3872 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3873 | #endif |
| 3874 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3875 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3876 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3877 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3878 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3879 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3880 | 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] | 3881 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3882 | |
| 3883 | /* Avoid a regression due to buggy server */ |
| 3884 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3885 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3886 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3887 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3890 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | return status; |
| 3894 | } |
| 3895 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3896 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3898 | struct nfs4_exception exception = { |
| 3899 | .interruptible = true, |
| 3900 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | int err; |
| 3902 | do { |
| 3903 | err = nfs4_handle_exception(server, |
| 3904 | _nfs4_server_capabilities(server, fhandle), |
| 3905 | &exception); |
| 3906 | } while (exception.retry); |
| 3907 | return err; |
| 3908 | } |
| 3909 | |
| 3910 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3911 | struct nfs_fsinfo *info) |
| 3912 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3913 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3915 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | }; |
| 3917 | struct nfs4_lookup_res res = { |
| 3918 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3919 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | .fh = fhandle, |
| 3921 | }; |
| 3922 | struct rpc_message msg = { |
| 3923 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3924 | .rpc_argp = &args, |
| 3925 | .rpc_resp = &res, |
| 3926 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3927 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3928 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3929 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3930 | /* |
| 3931 | * Process the label in the upcoming getfattr |
| 3932 | */ |
| 3933 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3934 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3935 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3936 | 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] | 3937 | } |
| 3938 | |
| 3939 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3940 | struct nfs_fsinfo *info) |
| 3941 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3942 | struct nfs4_exception exception = { |
| 3943 | .interruptible = true, |
| 3944 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | int err; |
| 3946 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3947 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3948 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3949 | switch (err) { |
| 3950 | case 0: |
| 3951 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3952 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3953 | default: |
| 3954 | err = nfs4_handle_exception(server, err, &exception); |
| 3955 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3957 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | return err; |
| 3959 | } |
| 3960 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3961 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3962 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3963 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3964 | struct rpc_auth_create_args auth_args = { |
| 3965 | .pseudoflavor = flavor, |
| 3966 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3967 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3968 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3969 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3970 | if (IS_ERR(auth)) |
| 3971 | return -EACCES; |
| 3972 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3973 | } |
| 3974 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3975 | /* |
| 3976 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3977 | * |
| 3978 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3979 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3980 | * |
| 3981 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3982 | * negative errno value. |
| 3983 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3984 | 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] | 3985 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3987 | /* Per 3530bis 15.33.5 */ |
| 3988 | static const rpc_authflavor_t flav_array[] = { |
| 3989 | RPC_AUTH_GSS_KRB5P, |
| 3990 | RPC_AUTH_GSS_KRB5I, |
| 3991 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3992 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3993 | RPC_AUTH_NULL, |
| 3994 | }; |
| 3995 | int status = -EPERM; |
| 3996 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3998 | if (server->auth_info.flavor_len > 0) { |
| 3999 | /* try each flavor specified by user */ |
| 4000 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 4001 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4002 | server->auth_info.flavors[i]); |
| 4003 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4004 | continue; |
| 4005 | break; |
| 4006 | } |
| 4007 | } else { |
| 4008 | /* no flavors specified by user, try default list */ |
| 4009 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 4010 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4011 | flav_array[i]); |
| 4012 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4013 | continue; |
| 4014 | break; |
| 4015 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4016 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4017 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4018 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 4019 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4020 | * to access the mount. It could also mean that we tried to mount |
| 4021 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 4022 | * existing mount programs don't handle -EACCES very well so it should |
| 4023 | * be mapped to -EPERM instead. |
| 4024 | */ |
| 4025 | if (status == -EACCES) |
| 4026 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4027 | return status; |
| 4028 | } |
| 4029 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4030 | /** |
| 4031 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 4032 | * @server: initialized nfs_server handle |
| 4033 | * @fhandle: we fill in the pseudo-fs root file handle |
| 4034 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4035 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4036 | * |
| 4037 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4038 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 4039 | 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] | 4040 | struct nfs_fsinfo *info, |
| 4041 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4042 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4043 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4044 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4045 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4046 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4047 | |
| 4048 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 4049 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 4050 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | if (status == 0) |
| 4053 | status = nfs4_server_capabilities(server, fhandle); |
| 4054 | if (status == 0) |
| 4055 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4056 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 4057 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4060 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 4061 | struct nfs_fsinfo *info) |
| 4062 | { |
| 4063 | int error; |
| 4064 | struct nfs_fattr *fattr = info->fattr; |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4065 | struct nfs4_label *label = fattr->label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4066 | |
| 4067 | error = nfs4_server_capabilities(server, mntfh); |
| 4068 | if (error < 0) { |
| 4069 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 4070 | return error; |
| 4071 | } |
| 4072 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4073 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4074 | if (error < 0) { |
| 4075 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4076 | goto out; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4080 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4081 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4082 | |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4083 | out: |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4084 | return error; |
| 4085 | } |
| 4086 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4087 | /* |
| 4088 | * Get locations and (maybe) other attributes of a referral. |
| 4089 | * Note that we'll actually follow the referral later when |
| 4090 | * we detect fsid mismatch in inode revalidation |
| 4091 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4092 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4093 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4094 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4095 | { |
| 4096 | int status = -ENOMEM; |
| 4097 | struct page *page = NULL; |
| 4098 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4099 | |
| 4100 | page = alloc_page(GFP_KERNEL); |
| 4101 | if (page == NULL) |
| 4102 | goto out; |
| 4103 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4104 | if (locations == NULL) |
| 4105 | goto out; |
| 4106 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4107 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4108 | if (status != 0) |
| 4109 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4110 | |
| 4111 | /* |
| 4112 | * If the fsid didn't change, this is a migration event, not a |
| 4113 | * referral. Cause us to drop into the exception handler, which |
| 4114 | * will kick off migration recovery. |
| 4115 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4116 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4117 | dprintk("%s: server did not return a different fsid for" |
| 4118 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4119 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4120 | goto out; |
| 4121 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4122 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4123 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4124 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4125 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4126 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4127 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4128 | out: |
| 4129 | if (page) |
| 4130 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4131 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4132 | return status; |
| 4133 | } |
| 4134 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4135 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4136 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4137 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4139 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | struct nfs4_getattr_arg args = { |
| 4141 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4142 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | }; |
| 4144 | struct nfs4_getattr_res res = { |
| 4145 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4146 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | .server = server, |
| 4148 | }; |
| 4149 | struct rpc_message msg = { |
| 4150 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4151 | .rpc_argp = &args, |
| 4152 | .rpc_resp = &res, |
| 4153 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4154 | unsigned short task_flags = 0; |
| 4155 | |
| 4156 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4157 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4158 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4159 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 4160 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode, 0); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4161 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4162 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4163 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4164 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | } |
| 4166 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4167 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4168 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4169 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4171 | struct nfs4_exception exception = { |
| 4172 | .interruptible = true, |
| 4173 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | int err; |
| 4175 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4176 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4177 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4178 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | &exception); |
| 4180 | } while (exception.retry); |
| 4181 | return err; |
| 4182 | } |
| 4183 | |
| 4184 | /* |
| 4185 | * The file is not closed if it is opened due to the a request to change |
| 4186 | * the size of the file. The open call will not be needed once the |
| 4187 | * VFS layer lookup-intents are implemented. |
| 4188 | * |
| 4189 | * Close is called when the inode is destroyed. |
| 4190 | * If we haven't opened the file for O_WRONLY, we |
| 4191 | * need to in the size_change case to obtain a stateid. |
| 4192 | * |
| 4193 | * Got race? |
| 4194 | * Because OPEN is always done by name in nfsv4, it is |
| 4195 | * possible that we opened a different file by the same |
| 4196 | * name. We can recognize this race condition, but we |
| 4197 | * can't do anything about it besides returning an error. |
| 4198 | * |
| 4199 | * This will be fixed with VFS changes (lookup-intent). |
| 4200 | */ |
| 4201 | static int |
| 4202 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4203 | struct iattr *sattr) |
| 4204 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4205 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4206 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4207 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4208 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | int status; |
| 4210 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4211 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4212 | sattr->ia_valid & ATTR_SIZE && |
| 4213 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4214 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4215 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4216 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4218 | /* Deal with open(O_TRUNC) */ |
| 4219 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4220 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4221 | |
| 4222 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4223 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4224 | return 0; |
| 4225 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4226 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4227 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4228 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4229 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4230 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4231 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4232 | } |
| 4233 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4234 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4235 | if (IS_ERR(label)) |
| 4236 | return PTR_ERR(label); |
| 4237 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4238 | /* Return any delegations if we're going to change ACLs */ |
| 4239 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4240 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4241 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4242 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4243 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4244 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4245 | nfs_setsecurity(inode, fattr, label); |
| 4246 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4247 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | return status; |
| 4249 | } |
| 4250 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4251 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4252 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4253 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4254 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4255 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4256 | int status; |
| 4257 | struct nfs4_lookup_arg args = { |
| 4258 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4259 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4260 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4261 | }; |
| 4262 | struct nfs4_lookup_res res = { |
| 4263 | .server = server, |
| 4264 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4265 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4266 | .fh = fhandle, |
| 4267 | }; |
| 4268 | struct rpc_message msg = { |
| 4269 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4270 | .rpc_argp = &args, |
| 4271 | .rpc_resp = &res, |
| 4272 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4273 | unsigned short task_flags = 0; |
| 4274 | |
| 4275 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4276 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4277 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4278 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4279 | args.bitmask = nfs4_bitmask(server, label); |
| 4280 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4281 | nfs_fattr_init(fattr); |
| 4282 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4283 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4284 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4285 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4286 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | dprintk("NFS reply lookup: %d\n", status); |
| 4288 | return status; |
| 4289 | } |
| 4290 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4291 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4292 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4293 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4294 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4295 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4296 | fattr->nlink = 2; |
| 4297 | } |
| 4298 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4299 | 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] | 4300 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4301 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4302 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4303 | struct nfs4_exception exception = { |
| 4304 | .interruptible = true, |
| 4305 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4306 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4307 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4308 | int err; |
| 4309 | do { |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4310 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4311 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4312 | switch (err) { |
| 4313 | case -NFS4ERR_BADNAME: |
| 4314 | err = -ENOENT; |
| 4315 | goto out; |
| 4316 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4317 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4318 | if (err == -NFS4ERR_MOVED) |
| 4319 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4320 | goto out; |
| 4321 | case -NFS4ERR_WRONGSEC: |
| 4322 | err = -EPERM; |
| 4323 | if (client != *clnt) |
| 4324 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4325 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4326 | if (IS_ERR(client)) |
| 4327 | return PTR_ERR(client); |
| 4328 | |
| 4329 | exception.retry = 1; |
| 4330 | break; |
| 4331 | default: |
| 4332 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4333 | } |
| 4334 | } while (exception.retry); |
| 4335 | |
| 4336 | out: |
| 4337 | if (err == 0) |
| 4338 | *clnt = client; |
| 4339 | else if (client != *clnt) |
| 4340 | rpc_shutdown_client(client); |
| 4341 | |
| 4342 | return err; |
| 4343 | } |
| 4344 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4345 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4346 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4347 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4349 | int status; |
| 4350 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4351 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4352 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4353 | if (client != NFS_CLIENT(dir)) { |
| 4354 | rpc_shutdown_client(client); |
| 4355 | nfs_fixup_secinfo_attributes(fattr); |
| 4356 | } |
| 4357 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4360 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4361 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4362 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4363 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4364 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4365 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4366 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4367 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4368 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4369 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4370 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4371 | } |
| 4372 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4373 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4374 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4375 | struct nfs4_label *label) |
| 4376 | { |
| 4377 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4378 | struct nfs_server *server = NFS_SERVER(inode); |
| 4379 | int status; |
| 4380 | struct nfs4_lookupp_arg args = { |
| 4381 | .bitmask = server->attr_bitmask, |
| 4382 | .fh = NFS_FH(inode), |
| 4383 | }; |
| 4384 | struct nfs4_lookupp_res res = { |
| 4385 | .server = server, |
| 4386 | .fattr = fattr, |
| 4387 | .label = label, |
| 4388 | .fh = fhandle, |
| 4389 | }; |
| 4390 | struct rpc_message msg = { |
| 4391 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4392 | .rpc_argp = &args, |
| 4393 | .rpc_resp = &res, |
| 4394 | }; |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4395 | unsigned short task_flags = 0; |
| 4396 | |
| 4397 | if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL) |
| 4398 | task_flags |= RPC_TASK_TIMEOUT; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4399 | |
| 4400 | args.bitmask = nfs4_bitmask(server, label); |
| 4401 | |
| 4402 | nfs_fattr_init(fattr); |
| 4403 | |
| 4404 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4405 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4406 | &res.seq_res, task_flags); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4407 | dprintk("NFS reply lookupp: %d\n", status); |
| 4408 | return status; |
| 4409 | } |
| 4410 | |
| 4411 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4412 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4413 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4414 | struct nfs4_exception exception = { |
| 4415 | .interruptible = true, |
| 4416 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4417 | int err; |
| 4418 | do { |
| 4419 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4420 | trace_nfs4_lookupp(inode, err); |
| 4421 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4422 | &exception); |
| 4423 | } while (exception.retry); |
| 4424 | return err; |
| 4425 | } |
| 4426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4428 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4429 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | struct nfs4_accessargs args = { |
| 4431 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4432 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4434 | struct nfs4_accessres res = { |
| 4435 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4436 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | struct rpc_message msg = { |
| 4438 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4439 | .rpc_argp = &args, |
| 4440 | .rpc_resp = &res, |
| 4441 | .rpc_cred = entry->cred, |
| 4442 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4443 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4445 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4446 | res.fattr = nfs_alloc_fattr(); |
| 4447 | if (res.fattr == NULL) |
| 4448 | return -ENOMEM; |
| 4449 | args.bitmask = server->cache_consistency_bitmask; |
| 4450 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4451 | 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] | 4452 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4453 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4454 | if (res.fattr) |
| 4455 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4457 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | return status; |
| 4459 | } |
| 4460 | |
| 4461 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4462 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4463 | struct nfs4_exception exception = { |
| 4464 | .interruptible = true, |
| 4465 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | int err; |
| 4467 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4468 | err = _nfs4_proc_access(inode, entry); |
| 4469 | trace_nfs4_access(inode, err); |
| 4470 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | &exception); |
| 4472 | } while (exception.retry); |
| 4473 | return err; |
| 4474 | } |
| 4475 | |
| 4476 | /* |
| 4477 | * TODO: For the time being, we don't try to get any attributes |
| 4478 | * along with any of the zero-copy operations READ, READDIR, |
| 4479 | * READLINK, WRITE. |
| 4480 | * |
| 4481 | * In the case of the first three, we want to put the GETATTR |
| 4482 | * after the read-type operation -- this is because it is hard |
| 4483 | * to predict the length of a GETATTR response in v4, and thus |
| 4484 | * align the READ data correctly. This means that the GETATTR |
| 4485 | * may end up partially falling into the page cache, and we should |
| 4486 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4487 | * To do this efficiently, we need to know the total length |
| 4488 | * of data received, which doesn't seem to be available outside |
| 4489 | * of the RPC layer. |
| 4490 | * |
| 4491 | * In the case of WRITE, we also want to put the GETATTR after |
| 4492 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4493 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | * |
| 4495 | * Both of these changes to the XDR layer would in fact be quite |
| 4496 | * minor, but I decided to leave them for a subsequent patch. |
| 4497 | */ |
| 4498 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4499 | unsigned int pgbase, unsigned int pglen) |
| 4500 | { |
| 4501 | struct nfs4_readlink args = { |
| 4502 | .fh = NFS_FH(inode), |
| 4503 | .pgbase = pgbase, |
| 4504 | .pglen = pglen, |
| 4505 | .pages = &page, |
| 4506 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4507 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | struct rpc_message msg = { |
| 4509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4510 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4511 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | }; |
| 4513 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4514 | 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] | 4515 | } |
| 4516 | |
| 4517 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4518 | unsigned int pgbase, unsigned int pglen) |
| 4519 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4520 | struct nfs4_exception exception = { |
| 4521 | .interruptible = true, |
| 4522 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4523 | int err; |
| 4524 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4525 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4526 | trace_nfs4_readlink(inode, err); |
| 4527 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | &exception); |
| 4529 | } while (exception.retry); |
| 4530 | return err; |
| 4531 | } |
| 4532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4534 | * 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] | 4535 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | static int |
| 4537 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4538 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4540 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4541 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4542 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | int status = 0; |
| 4545 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4546 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4547 | if (IS_ERR(ctx)) |
| 4548 | return PTR_ERR(ctx); |
| 4549 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4550 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4551 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4552 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4553 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4554 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | if (IS_ERR(state)) { |
| 4556 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4557 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4560 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4561 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | return status; |
| 4563 | } |
| 4564 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4565 | static int |
| 4566 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4568 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4569 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4571 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4573 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4574 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4575 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4577 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4578 | .rpc_argp = &args, |
| 4579 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4581 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4582 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4583 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4584 | 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] | 4585 | if (status == 0) { |
| 4586 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4587 | nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, |
| 4588 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4589 | /* Removing a directory decrements nlink in the parent */ |
| 4590 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4591 | nfs4_dec_nlink_locked(dir); |
| 4592 | spin_unlock(&dir->i_lock); |
| 4593 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | return status; |
| 4595 | } |
| 4596 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4597 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4598 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4599 | struct nfs4_exception exception = { |
| 4600 | .interruptible = true, |
| 4601 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4602 | struct inode *inode = d_inode(dentry); |
| 4603 | int err; |
| 4604 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4605 | if (inode) { |
| 4606 | if (inode->i_nlink == 1) |
| 4607 | nfs4_inode_return_delegation(inode); |
| 4608 | else |
| 4609 | nfs4_inode_make_writeable(inode); |
| 4610 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4611 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4612 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4613 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4614 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4615 | &exception); |
| 4616 | } while (exception.retry); |
| 4617 | return err; |
| 4618 | } |
| 4619 | |
| 4620 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4622 | struct nfs4_exception exception = { |
| 4623 | .interruptible = true, |
| 4624 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4628 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4629 | trace_nfs4_remove(dir, name, err); |
| 4630 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | &exception); |
| 4632 | } while (exception.retry); |
| 4633 | return err; |
| 4634 | } |
| 4635 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4636 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4637 | struct dentry *dentry, |
| 4638 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4640 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4641 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4643 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4645 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4646 | |
| 4647 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4648 | |
| 4649 | if (inode) |
| 4650 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | } |
| 4652 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4653 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4654 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4655 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4656 | &data->args.seq_args, |
| 4657 | &data->res.seq_res, |
| 4658 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4661 | 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] | 4662 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4663 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4664 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4665 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4666 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4667 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4668 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4669 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4670 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4671 | if (task->tk_status == 0) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4672 | nfs4_update_changeattr(dir, &res->cinfo, |
| 4673 | res->dir_attr->time_start, |
| 4674 | NFS_INO_INVALID_DATA); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4675 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | } |
| 4677 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4678 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4679 | struct dentry *old_dentry, |
| 4680 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4681 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4682 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4683 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4684 | struct inode *old_inode = d_inode(old_dentry); |
| 4685 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4686 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4687 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4688 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4689 | if (new_inode) |
| 4690 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4691 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4692 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4693 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4694 | } |
| 4695 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4696 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4697 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4698 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4699 | &data->args.seq_args, |
| 4700 | &data->res.seq_res, |
| 4701 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4705 | struct inode *new_dir) |
| 4706 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4707 | struct nfs_renamedata *data = task->tk_calldata; |
| 4708 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4709 | |
| 4710 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4711 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4712 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4713 | return 0; |
| 4714 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4715 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4716 | if (new_dir != old_dir) { |
| 4717 | /* Note: If we moved a directory, nlink will change */ |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4718 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4719 | res->old_fattr->time_start, |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame^] | 4720 | NFS_INO_INVALID_NLINK | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4721 | NFS_INO_INVALID_DATA); |
| 4722 | nfs4_update_changeattr(new_dir, &res->new_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4723 | res->new_fattr->time_start, |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame^] | 4724 | NFS_INO_INVALID_NLINK | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4725 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4726 | } else |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4727 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4728 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4729 | NFS_INO_INVALID_DATA); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4730 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4731 | return 1; |
| 4732 | } |
| 4733 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4734 | 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] | 4735 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4736 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4737 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | struct nfs4_link_arg arg = { |
| 4739 | .fh = NFS_FH(inode), |
| 4740 | .dir_fh = NFS_FH(dir), |
| 4741 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4742 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4744 | struct nfs4_link_res res = { |
| 4745 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4746 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4747 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | struct rpc_message msg = { |
| 4749 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4750 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4751 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4753 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4755 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4756 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4757 | goto out; |
| 4758 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4759 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4760 | if (IS_ERR(res.label)) { |
| 4761 | status = PTR_ERR(res.label); |
| 4762 | goto out; |
| 4763 | } |
| 4764 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4765 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 4766 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, res.label), inode, |
| 4767 | NFS_INO_INVALID_CHANGE); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4768 | 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] | 4769 | if (!status) { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4770 | nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, |
| 4771 | NFS_INO_INVALID_DATA); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4772 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4773 | if (!status) |
| 4774 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4775 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4776 | |
| 4777 | |
| 4778 | nfs4_label_free(res.label); |
| 4779 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4780 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4781 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | return status; |
| 4783 | } |
| 4784 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4785 | 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] | 4786 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4787 | struct nfs4_exception exception = { |
| 4788 | .interruptible = true, |
| 4789 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | int err; |
| 4791 | do { |
| 4792 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4793 | _nfs4_proc_link(inode, dir, name), |
| 4794 | &exception); |
| 4795 | } while (exception.retry); |
| 4796 | return err; |
| 4797 | } |
| 4798 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4799 | struct nfs4_createdata { |
| 4800 | struct rpc_message msg; |
| 4801 | struct nfs4_create_arg arg; |
| 4802 | struct nfs4_create_res res; |
| 4803 | struct nfs_fh fh; |
| 4804 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4805 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4806 | }; |
| 4807 | |
| 4808 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4809 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4810 | { |
| 4811 | struct nfs4_createdata *data; |
| 4812 | |
| 4813 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4814 | if (data != NULL) { |
| 4815 | struct nfs_server *server = NFS_SERVER(dir); |
| 4816 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4817 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4818 | if (IS_ERR(data->label)) |
| 4819 | goto out_free; |
| 4820 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4821 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4822 | data->msg.rpc_argp = &data->arg; |
| 4823 | data->msg.rpc_resp = &data->res; |
| 4824 | data->arg.dir_fh = NFS_FH(dir); |
| 4825 | data->arg.server = server; |
| 4826 | data->arg.name = name; |
| 4827 | data->arg.attrs = sattr; |
| 4828 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4829 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4830 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4831 | data->res.server = server; |
| 4832 | data->res.fh = &data->fh; |
| 4833 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4834 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4835 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4836 | } |
| 4837 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4838 | out_free: |
| 4839 | kfree(data); |
| 4840 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4844 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4845 | 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] | 4846 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4847 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4848 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4849 | nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, |
| 4850 | data->res.fattr->time_start, |
| 4851 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4852 | /* Creating a directory bumps nlink in the parent */ |
| 4853 | if (data->arg.ftype == NF4DIR) |
| 4854 | nfs4_inc_nlink_locked(dir); |
| 4855 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4856 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4857 | } |
| 4858 | return status; |
| 4859 | } |
| 4860 | |
| 4861 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4862 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4863 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4864 | kfree(data); |
| 4865 | } |
| 4866 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4867 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4868 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4869 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4870 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4871 | struct nfs4_createdata *data; |
| 4872 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4874 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4875 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4876 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4877 | status = -ENOMEM; |
| 4878 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4879 | if (data == NULL) |
| 4880 | goto out; |
| 4881 | |
| 4882 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4883 | data->arg.u.symlink.pages = &page; |
| 4884 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4885 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4887 | status = nfs4_do_create(dir, dentry, data); |
| 4888 | |
| 4889 | nfs4_free_createdata(data); |
| 4890 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | return status; |
| 4892 | } |
| 4893 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4894 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4895 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4897 | struct nfs4_exception exception = { |
| 4898 | .interruptible = true, |
| 4899 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4900 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4902 | |
| 4903 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4906 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4907 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4908 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | &exception); |
| 4910 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4911 | |
| 4912 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | return err; |
| 4914 | } |
| 4915 | |
| 4916 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4917 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4919 | struct nfs4_createdata *data; |
| 4920 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4922 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4923 | if (data == NULL) |
| 4924 | goto out; |
| 4925 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4926 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4927 | status = nfs4_do_create(dir, dentry, data); |
| 4928 | |
| 4929 | nfs4_free_createdata(data); |
| 4930 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4931 | return status; |
| 4932 | } |
| 4933 | |
| 4934 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4935 | struct iattr *sattr) |
| 4936 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4937 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4938 | struct nfs4_exception exception = { |
| 4939 | .interruptible = true, |
| 4940 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4941 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4943 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4944 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4945 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4946 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4947 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4949 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4950 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4951 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | &exception); |
| 4953 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4954 | nfs4_label_release_security(label); |
| 4955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4956 | return err; |
| 4957 | } |
| 4958 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4959 | static int _nfs4_proc_readdir(struct nfs_readdir_arg *nr_arg, |
| 4960 | struct nfs_readdir_res *nr_res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4962 | struct inode *dir = d_inode(nr_arg->dentry); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4963 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4964 | struct nfs4_readdir_arg args = { |
| 4965 | .fh = NFS_FH(dir), |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4966 | .pages = nr_arg->pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | .pgbase = 0, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4968 | .count = nr_arg->page_len, |
| 4969 | .plus = nr_arg->plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 | }; |
| 4971 | struct nfs4_readdir_res res; |
| 4972 | struct rpc_message msg = { |
| 4973 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4974 | .rpc_argp = &args, |
| 4975 | .rpc_resp = &res, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4976 | .rpc_cred = nr_arg->cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | }; |
| 4978 | int status; |
| 4979 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4980 | dprintk("%s: dentry = %pd2, cookie = %llu\n", __func__, |
| 4981 | nr_arg->dentry, (unsigned long long)nr_arg->cookie); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4982 | if (!(server->caps & NFS_CAP_SECURITY_LABEL)) |
| 4983 | args.bitmask = server->attr_bitmask_nl; |
| 4984 | else |
| 4985 | args.bitmask = server->attr_bitmask; |
| 4986 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4987 | 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] | 4988 | res.pgbase = args.pgbase; |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4989 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 4990 | &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4991 | if (status >= 0) { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4992 | memcpy(nr_res->verf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4993 | status += args.pgbase; |
| 4994 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4995 | |
| 4996 | nfs_invalidate_atime(dir); |
| 4997 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4998 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | return status; |
| 5000 | } |
| 5001 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5002 | static int nfs4_proc_readdir(struct nfs_readdir_arg *arg, |
| 5003 | struct nfs_readdir_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5004 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5005 | struct nfs4_exception exception = { |
| 5006 | .interruptible = true, |
| 5007 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | int err; |
| 5009 | do { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5010 | err = _nfs4_proc_readdir(arg, res); |
| 5011 | trace_nfs4_readdir(d_inode(arg->dentry), err); |
| 5012 | err = nfs4_handle_exception(NFS_SERVER(d_inode(arg->dentry)), |
| 5013 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | } while (exception.retry); |
| 5015 | return err; |
| 5016 | } |
| 5017 | |
| 5018 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5019 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5021 | struct nfs4_createdata *data; |
| 5022 | int mode = sattr->ia_mode; |
| 5023 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5024 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5025 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 5026 | if (data == NULL) |
| 5027 | goto out; |
| 5028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5030 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5032 | data->arg.ftype = NF4BLK; |
| 5033 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5034 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | } |
| 5036 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5037 | data->arg.ftype = NF4CHR; |
| 5038 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5039 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5040 | } else if (!S_ISSOCK(mode)) { |
| 5041 | status = -EINVAL; |
| 5042 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5044 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5045 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5046 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5047 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5048 | nfs4_free_createdata(data); |
| 5049 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5050 | return status; |
| 5051 | } |
| 5052 | |
| 5053 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 5054 | struct iattr *sattr, dev_t rdev) |
| 5055 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5056 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5057 | struct nfs4_exception exception = { |
| 5058 | .interruptible = true, |
| 5059 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5060 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 5062 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5063 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5064 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5065 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 5066 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5068 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 5069 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 5070 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | &exception); |
| 5072 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5073 | |
| 5074 | nfs4_label_release_security(label); |
| 5075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5076 | return err; |
| 5077 | } |
| 5078 | |
| 5079 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5080 | struct nfs_fsstat *fsstat) |
| 5081 | { |
| 5082 | struct nfs4_statfs_arg args = { |
| 5083 | .fh = fhandle, |
| 5084 | .bitmask = server->attr_bitmask, |
| 5085 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5086 | struct nfs4_statfs_res res = { |
| 5087 | .fsstat = fsstat, |
| 5088 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | struct rpc_message msg = { |
| 5090 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5091 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5092 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5093 | }; |
| 5094 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5095 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5096 | 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] | 5097 | } |
| 5098 | |
| 5099 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5100 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5101 | struct nfs4_exception exception = { |
| 5102 | .interruptible = true, |
| 5103 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5104 | int err; |
| 5105 | do { |
| 5106 | err = nfs4_handle_exception(server, |
| 5107 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5108 | &exception); |
| 5109 | } while (exception.retry); |
| 5110 | return err; |
| 5111 | } |
| 5112 | |
| 5113 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5114 | struct nfs_fsinfo *fsinfo) |
| 5115 | { |
| 5116 | struct nfs4_fsinfo_arg args = { |
| 5117 | .fh = fhandle, |
| 5118 | .bitmask = server->attr_bitmask, |
| 5119 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5120 | struct nfs4_fsinfo_res res = { |
| 5121 | .fsinfo = fsinfo, |
| 5122 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | struct rpc_message msg = { |
| 5124 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5125 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5126 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | }; |
| 5128 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5129 | 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] | 5130 | } |
| 5131 | |
| 5132 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5133 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5134 | struct nfs4_exception exception = { |
| 5135 | .interruptible = true, |
| 5136 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | int err; |
| 5138 | |
| 5139 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5140 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5141 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5142 | if (err == 0) { |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 5143 | nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5144 | break; |
| 5145 | } |
| 5146 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | } while (exception.retry); |
| 5148 | return err; |
| 5149 | } |
| 5150 | |
| 5151 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5152 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5153 | int error; |
| 5154 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5155 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5156 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5157 | if (error == 0) { |
| 5158 | /* block layout checks this! */ |
| 5159 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5160 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5161 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5162 | |
| 5163 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5167 | struct nfs_pathconf *pathconf) |
| 5168 | { |
| 5169 | struct nfs4_pathconf_arg args = { |
| 5170 | .fh = fhandle, |
| 5171 | .bitmask = server->attr_bitmask, |
| 5172 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5173 | struct nfs4_pathconf_res res = { |
| 5174 | .pathconf = pathconf, |
| 5175 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5176 | struct rpc_message msg = { |
| 5177 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5178 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5179 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5180 | }; |
| 5181 | |
| 5182 | /* None of the pathconf attributes are mandatory to implement */ |
| 5183 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5184 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5185 | return 0; |
| 5186 | } |
| 5187 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5188 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5189 | 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] | 5190 | } |
| 5191 | |
| 5192 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5193 | struct nfs_pathconf *pathconf) |
| 5194 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5195 | struct nfs4_exception exception = { |
| 5196 | .interruptible = true, |
| 5197 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | int err; |
| 5199 | |
| 5200 | do { |
| 5201 | err = nfs4_handle_exception(server, |
| 5202 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5203 | &exception); |
| 5204 | } while (exception.retry); |
| 5205 | return err; |
| 5206 | } |
| 5207 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5208 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5209 | const struct nfs_open_context *ctx, |
| 5210 | const struct nfs_lock_context *l_ctx, |
| 5211 | fmode_t fmode) |
| 5212 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5213 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5214 | } |
| 5215 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5216 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5217 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5218 | const struct nfs_open_context *ctx, |
| 5219 | const struct nfs_lock_context *l_ctx, |
| 5220 | fmode_t fmode) |
| 5221 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5222 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5223 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5224 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5225 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5226 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5227 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5228 | } |
| 5229 | |
| 5230 | static bool nfs4_error_stateid_expired(int err) |
| 5231 | { |
| 5232 | switch (err) { |
| 5233 | case -NFS4ERR_DELEG_REVOKED: |
| 5234 | case -NFS4ERR_ADMIN_REVOKED: |
| 5235 | case -NFS4ERR_BAD_STATEID: |
| 5236 | case -NFS4ERR_STALE_STATEID: |
| 5237 | case -NFS4ERR_OLD_STATEID: |
| 5238 | case -NFS4ERR_OPENMODE: |
| 5239 | case -NFS4ERR_EXPIRED: |
| 5240 | return true; |
| 5241 | } |
| 5242 | return false; |
| 5243 | } |
| 5244 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5245 | 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] | 5246 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5247 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5249 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5250 | if (task->tk_status < 0) { |
| 5251 | struct nfs4_exception exception = { |
| 5252 | .inode = hdr->inode, |
| 5253 | .state = hdr->args.context->state, |
| 5254 | .stateid = &hdr->args.stateid, |
| 5255 | }; |
| 5256 | task->tk_status = nfs4_async_handle_exception(task, |
| 5257 | server, task->tk_status, &exception); |
| 5258 | if (exception.retry) { |
| 5259 | rpc_restart_call_prepare(task); |
| 5260 | return -EAGAIN; |
| 5261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5265 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5266 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5267 | } |
| 5268 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5269 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5270 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5271 | { |
| 5272 | |
| 5273 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5274 | nfs4_stateid_is_current(&args->stateid, |
| 5275 | args->context, |
| 5276 | args->lock_context, |
| 5277 | FMODE_READ)) |
| 5278 | return false; |
| 5279 | rpc_restart_call_prepare(task); |
| 5280 | return true; |
| 5281 | } |
| 5282 | |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5283 | static bool nfs4_read_plus_not_supported(struct rpc_task *task, |
| 5284 | struct nfs_pgio_header *hdr) |
| 5285 | { |
| 5286 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
| 5287 | struct rpc_message *msg = &task->tk_msg; |
| 5288 | |
| 5289 | if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS] && |
| 5290 | server->caps & NFS_CAP_READ_PLUS && task->tk_status == -ENOTSUPP) { |
| 5291 | server->caps &= ~NFS_CAP_READ_PLUS; |
| 5292 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5293 | rpc_restart_call_prepare(task); |
| 5294 | return true; |
| 5295 | } |
| 5296 | return false; |
| 5297 | } |
| 5298 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5299 | 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] | 5300 | { |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5301 | dprintk("--> %s\n", __func__); |
| 5302 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5303 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5304 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5305 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5306 | return -EAGAIN; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5307 | if (nfs4_read_plus_not_supported(task, hdr)) |
| 5308 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5309 | if (task->tk_status > 0) |
| 5310 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5311 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5312 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5313 | } |
| 5314 | |
Anna Schumaker | 21e3140 | 2020-12-03 15:18:39 -0500 | [diff] [blame] | 5315 | #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] | 5316 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5317 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5318 | { |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5319 | /* Note: We don't use READ_PLUS with pNFS yet */ |
| 5320 | 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] | 5321 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS]; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5322 | } |
| 5323 | #else |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5324 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5325 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5326 | { |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5327 | } |
| 5328 | #endif /* CONFIG_NFS_V4_2 */ |
| 5329 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5330 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5331 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5332 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5333 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5334 | if (!hdr->pgio_done_cb) |
| 5335 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5336 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5337 | nfs42_read_plus_support(hdr, msg); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5338 | 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] | 5339 | } |
| 5340 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5341 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5342 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5343 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5344 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5345 | &hdr->args.seq_args, |
| 5346 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5347 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5348 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5349 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5350 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5351 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5352 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5353 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5354 | return -EIO; |
| 5355 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | } |
| 5357 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5358 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5359 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5361 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5362 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5363 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5364 | if (task->tk_status < 0) { |
| 5365 | struct nfs4_exception exception = { |
| 5366 | .inode = hdr->inode, |
| 5367 | .state = hdr->args.context->state, |
| 5368 | .stateid = &hdr->args.stateid, |
| 5369 | }; |
| 5370 | task->tk_status = nfs4_async_handle_exception(task, |
| 5371 | NFS_SERVER(inode), task->tk_status, |
| 5372 | &exception); |
| 5373 | if (exception.retry) { |
| 5374 | rpc_restart_call_prepare(task); |
| 5375 | return -EAGAIN; |
| 5376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5378 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5379 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5380 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5381 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5382 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | } |
| 5384 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5385 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5386 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5387 | { |
| 5388 | |
| 5389 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5390 | nfs4_stateid_is_current(&args->stateid, |
| 5391 | args->context, |
| 5392 | args->lock_context, |
| 5393 | FMODE_WRITE)) |
| 5394 | return false; |
| 5395 | rpc_restart_call_prepare(task); |
| 5396 | return true; |
| 5397 | } |
| 5398 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5399 | 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] | 5400 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5401 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5402 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5403 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5404 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5405 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5406 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5407 | } |
| 5408 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5409 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5410 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5411 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5412 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5413 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5414 | return false; |
| 5415 | /* Otherwise, request attributes if and only if we don't hold |
| 5416 | * a delegation |
| 5417 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5418 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5419 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5420 | |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5421 | static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src, |
| 5422 | struct inode *inode, struct nfs_server *server, |
| 5423 | struct nfs4_label *label) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5424 | { |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5425 | unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5426 | unsigned int i; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5427 | |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5428 | memcpy(bitmask, src, sizeof(*bitmask) * NFS4_BITMASK_SZ); |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5429 | |
Trond Myklebust | 13c0b08 | 2021-03-25 21:07:21 -0400 | [diff] [blame] | 5430 | if (cache_validity & NFS_INO_INVALID_CHANGE) |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5431 | bitmask[0] |= FATTR4_WORD0_CHANGE; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5432 | if (cache_validity & NFS_INO_INVALID_ATIME) |
| 5433 | bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5434 | if (cache_validity & NFS_INO_INVALID_OTHER) |
| 5435 | bitmask[1] |= FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame^] | 5436 | FATTR4_WORD1_OWNER_GROUP; |
| 5437 | if (cache_validity & NFS_INO_INVALID_NLINK) |
| 5438 | bitmask[1] |= FATTR4_WORD1_NUMLINKS; |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5439 | if (label && label->len && cache_validity & NFS_INO_INVALID_LABEL) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5440 | bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5441 | if (cache_validity & NFS_INO_INVALID_CTIME) |
| 5442 | bitmask[1] |= FATTR4_WORD1_TIME_METADATA; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5443 | if (cache_validity & NFS_INO_INVALID_MTIME) |
| 5444 | bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5445 | if (cache_validity & NFS_INO_INVALID_BLOCKS) |
| 5446 | bitmask[1] |= FATTR4_WORD1_SPACE_USED; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5447 | |
| 5448 | if (nfs4_have_delegation(inode, FMODE_READ) && |
| 5449 | !(cache_validity & NFS_INO_REVAL_FORCED)) |
| 5450 | bitmask[0] &= ~FATTR4_WORD0_SIZE; |
Trond Myklebust | 13c0b08 | 2021-03-25 21:07:21 -0400 | [diff] [blame] | 5451 | else if (cache_validity & NFS_INO_INVALID_SIZE) |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5452 | bitmask[0] |= FATTR4_WORD0_SIZE; |
| 5453 | |
| 5454 | for (i = 0; i < NFS4_BITMASK_SZ; i++) |
| 5455 | bitmask[i] &= server->attr_bitmask[i]; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5456 | } |
| 5457 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5458 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5459 | struct rpc_message *msg, |
| 5460 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5462 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5463 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5464 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5465 | hdr->args.bitmask = NULL; |
| 5466 | hdr->res.fattr = NULL; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5467 | } else { |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5468 | nfs4_bitmask_set(hdr->args.bitmask_store, |
| 5469 | server->cache_consistency_bitmask, |
| 5470 | hdr->inode, server, NULL); |
| 5471 | hdr->args.bitmask = hdr->args.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5472 | } |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5473 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5474 | if (!hdr->pgio_done_cb) |
| 5475 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5476 | hdr->res.server = server; |
| 5477 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5479 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Olga Kornievskaia | cd1b659 | 2020-02-12 17:32:12 -0500 | [diff] [blame] | 5480 | 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] | 5481 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5482 | } |
| 5483 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5484 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5485 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5486 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5487 | &data->args.seq_args, |
| 5488 | &data->res.seq_res, |
| 5489 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | } |
| 5491 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5492 | 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] | 5493 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5495 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5496 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5497 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5498 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5499 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5500 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5502 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | } |
| 5504 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5505 | 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] | 5506 | { |
| 5507 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5508 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5509 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5510 | } |
| 5511 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5512 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5513 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5515 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5516 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5517 | if (data->commit_done_cb == NULL) |
| 5518 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5519 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5520 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5521 | 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] | 5522 | 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] | 5523 | } |
| 5524 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5525 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5526 | struct nfs_commitres *res) |
| 5527 | { |
| 5528 | struct inode *dst_inode = file_inode(dst); |
| 5529 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5530 | struct rpc_message msg = { |
| 5531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5532 | .rpc_argp = args, |
| 5533 | .rpc_resp = res, |
| 5534 | }; |
| 5535 | |
| 5536 | args->fh = NFS_FH(dst_inode); |
| 5537 | return nfs4_call_sync(server->client, server, &msg, |
| 5538 | &args->seq_args, &res->seq_res, 1); |
| 5539 | } |
| 5540 | |
| 5541 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5542 | { |
| 5543 | struct nfs_commitargs args = { |
| 5544 | .offset = offset, |
| 5545 | .count = count, |
| 5546 | }; |
| 5547 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5548 | struct nfs4_exception exception = { }; |
| 5549 | int status; |
| 5550 | |
| 5551 | do { |
| 5552 | status = _nfs4_proc_commit(dst, &args, res); |
| 5553 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5554 | } while (exception.retry); |
| 5555 | |
| 5556 | return status; |
| 5557 | } |
| 5558 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5559 | struct nfs4_renewdata { |
| 5560 | struct nfs_client *client; |
| 5561 | unsigned long timestamp; |
| 5562 | }; |
| 5563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | /* |
| 5565 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5566 | * standalone procedure for queueing an asynchronous RENEW. |
| 5567 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5568 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5569 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5570 | struct nfs4_renewdata *data = calldata; |
| 5571 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5572 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5573 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5574 | nfs4_schedule_state_renewal(clp); |
| 5575 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5576 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5577 | } |
| 5578 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5579 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [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; |
| 5583 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5585 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5586 | switch (task->tk_status) { |
| 5587 | case 0: |
| 5588 | break; |
| 5589 | case -NFS4ERR_LEASE_MOVED: |
| 5590 | nfs4_schedule_lease_moved_recovery(clp); |
| 5591 | break; |
| 5592 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5593 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5594 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5595 | return; |
| 5596 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5597 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5598 | return; |
| 5599 | } |
| 5600 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5602 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5605 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5606 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5607 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5608 | }; |
| 5609 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5610 | 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] | 5611 | { |
| 5612 | struct rpc_message msg = { |
| 5613 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5614 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5615 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5617 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5619 | if (renew_flags == 0) |
| 5620 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5621 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5622 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5623 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5624 | if (data == NULL) { |
| 5625 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5626 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5627 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5628 | data->client = clp; |
| 5629 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5630 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5631 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5632 | } |
| 5633 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5634 | 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] | 5635 | { |
| 5636 | struct rpc_message msg = { |
| 5637 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5638 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5639 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5640 | }; |
| 5641 | unsigned long now = jiffies; |
| 5642 | int status; |
| 5643 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5644 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 | if (status < 0) |
| 5646 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5647 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | return 0; |
| 5649 | } |
| 5650 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5651 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5652 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5653 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5654 | } |
| 5655 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5656 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5657 | * 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] | 5658 | * the stack. |
| 5659 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5660 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5661 | |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5662 | int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5663 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5664 | { |
| 5665 | struct page *newpage, **spages; |
| 5666 | int rc = 0; |
| 5667 | size_t len; |
| 5668 | spages = pages; |
| 5669 | |
| 5670 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5671 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5672 | newpage = alloc_page(GFP_KERNEL); |
| 5673 | |
| 5674 | if (newpage == NULL) |
| 5675 | goto unwind; |
| 5676 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5677 | buf += len; |
| 5678 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5679 | *pages++ = newpage; |
| 5680 | rc++; |
| 5681 | } while (buflen != 0); |
| 5682 | |
| 5683 | return rc; |
| 5684 | |
| 5685 | unwind: |
| 5686 | for(; rc > 0; rc--) |
| 5687 | __free_page(spages[rc-1]); |
| 5688 | return -ENOMEM; |
| 5689 | } |
| 5690 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5691 | struct nfs4_cached_acl { |
| 5692 | int cached; |
| 5693 | size_t len; |
Gustavo A. R. Silva | 5601cda | 2020-03-09 13:24:42 -0500 | [diff] [blame] | 5694 | char data[]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5695 | }; |
| 5696 | |
| 5697 | 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] | 5698 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5699 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5700 | |
| 5701 | spin_lock(&inode->i_lock); |
| 5702 | kfree(nfsi->nfs4_acl); |
| 5703 | nfsi->nfs4_acl = acl; |
| 5704 | spin_unlock(&inode->i_lock); |
| 5705 | } |
| 5706 | |
| 5707 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5708 | { |
| 5709 | nfs4_set_cached_acl(inode, NULL); |
| 5710 | } |
| 5711 | |
| 5712 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5713 | { |
| 5714 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5715 | struct nfs4_cached_acl *acl; |
| 5716 | int ret = -ENOENT; |
| 5717 | |
| 5718 | spin_lock(&inode->i_lock); |
| 5719 | acl = nfsi->nfs4_acl; |
| 5720 | if (acl == NULL) |
| 5721 | goto out; |
| 5722 | if (buf == NULL) /* user is just asking for length */ |
| 5723 | goto out_len; |
| 5724 | if (acl->cached == 0) |
| 5725 | goto out; |
| 5726 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5727 | if (acl->len > buflen) |
| 5728 | goto out; |
| 5729 | memcpy(buf, acl->data, acl->len); |
| 5730 | out_len: |
| 5731 | ret = acl->len; |
| 5732 | out: |
| 5733 | spin_unlock(&inode->i_lock); |
| 5734 | return ret; |
| 5735 | } |
| 5736 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5737 | 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] | 5738 | { |
| 5739 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5740 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5741 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5742 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5743 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5744 | if (acl == NULL) |
| 5745 | goto out; |
| 5746 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5747 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5748 | } else { |
| 5749 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5750 | if (acl == NULL) |
| 5751 | goto out; |
| 5752 | acl->cached = 0; |
| 5753 | } |
| 5754 | acl->len = acl_len; |
| 5755 | out: |
| 5756 | nfs4_set_cached_acl(inode, acl); |
| 5757 | } |
| 5758 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5759 | /* |
| 5760 | * The getxattr API returns the required buffer length when called with a |
| 5761 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5762 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5763 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5764 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5765 | * the cache. If not so, we throw away the page, and cache the required |
| 5766 | * length. The next getxattr call will then produce another round trip to |
| 5767 | * the server, this time with the input buf of the required size. |
| 5768 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5769 | 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] | 5770 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5771 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5772 | struct nfs_getaclargs args = { |
| 5773 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5774 | .acl_len = buflen, |
| 5775 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5776 | struct nfs_getaclres res = { |
| 5777 | .acl_len = buflen, |
| 5778 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5779 | struct rpc_message msg = { |
| 5780 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5781 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5782 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5783 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5784 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5785 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5786 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5787 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5788 | if (buflen == 0) |
| 5789 | buflen = server->rsize; |
| 5790 | |
| 5791 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5792 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5793 | if (!pages) |
| 5794 | return -ENOMEM; |
| 5795 | |
| 5796 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5797 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5798 | for (i = 0; i < npages; i++) { |
| 5799 | pages[i] = alloc_page(GFP_KERNEL); |
| 5800 | if (!pages[i]) |
| 5801 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5802 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5803 | |
| 5804 | /* for decoding across pages */ |
| 5805 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5806 | if (!res.acl_scratch) |
| 5807 | goto out_free; |
| 5808 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5809 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5810 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5811 | 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] | 5812 | __func__, buf, buflen, npages, args.acl_len); |
| 5813 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5814 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5815 | if (ret) |
| 5816 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5817 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5818 | /* Handle the case where the passed-in buffer is too short */ |
| 5819 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5820 | /* Did the user only issue a request for the acl length? */ |
| 5821 | if (buf == NULL) |
| 5822 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5823 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5824 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5825 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5826 | 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] | 5827 | if (buf) { |
| 5828 | if (res.acl_len > buflen) { |
| 5829 | ret = -ERANGE; |
| 5830 | goto out_free; |
| 5831 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5832 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5833 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5834 | out_ok: |
| 5835 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5836 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5837 | for (i = 0; i < npages; i++) |
| 5838 | if (pages[i]) |
| 5839 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5840 | if (res.acl_scratch) |
| 5841 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5842 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5843 | return ret; |
| 5844 | } |
| 5845 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5846 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5847 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5848 | struct nfs4_exception exception = { |
| 5849 | .interruptible = true, |
| 5850 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5851 | ssize_t ret; |
| 5852 | do { |
| 5853 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5854 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5855 | if (ret >= 0) |
| 5856 | break; |
| 5857 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5858 | } while (exception.retry); |
| 5859 | return ret; |
| 5860 | } |
| 5861 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5862 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5863 | { |
| 5864 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5865 | int ret; |
| 5866 | |
| 5867 | if (!nfs4_server_supports_acls(server)) |
| 5868 | return -EOPNOTSUPP; |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 5869 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5870 | if (ret < 0) |
| 5871 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5872 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5873 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5874 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5875 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5876 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5877 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5878 | return ret; |
| 5879 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5880 | } |
| 5881 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5882 | 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] | 5883 | { |
| 5884 | struct nfs_server *server = NFS_SERVER(inode); |
| 5885 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5886 | struct nfs_setaclargs arg = { |
| 5887 | .fh = NFS_FH(inode), |
| 5888 | .acl_pages = pages, |
| 5889 | .acl_len = buflen, |
| 5890 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5891 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5892 | struct rpc_message msg = { |
| 5893 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5894 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5895 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5896 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5897 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5898 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5899 | |
J. Bruce Fields | 4f8be1f | 2021-01-28 17:36:38 -0500 | [diff] [blame] | 5900 | /* You can't remove system.nfs4_acl: */ |
| 5901 | if (buflen == 0) |
| 5902 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5903 | if (!nfs4_server_supports_acls(server)) |
| 5904 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5905 | if (npages > ARRAY_SIZE(pages)) |
| 5906 | return -ERANGE; |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5907 | i = nfs4_buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5908 | if (i < 0) |
| 5909 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5910 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5911 | 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] | 5912 | |
| 5913 | /* |
| 5914 | * Free each page after tx, so the only ref left is |
| 5915 | * held by the network stack |
| 5916 | */ |
| 5917 | for (; i > 0; i--) |
| 5918 | put_page(pages[i-1]); |
| 5919 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5920 | /* |
| 5921 | * Acl update can result in inode attribute update. |
| 5922 | * so mark the attribute cache invalid. |
| 5923 | */ |
| 5924 | spin_lock(&inode->i_lock); |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 5925 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 5926 | NFS_INO_INVALID_CTIME | |
| 5927 | NFS_INO_REVAL_FORCED); |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5928 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5929 | nfs_access_zap_cache(inode); |
| 5930 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5931 | return ret; |
| 5932 | } |
| 5933 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5934 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5935 | { |
| 5936 | struct nfs4_exception exception = { }; |
| 5937 | int err; |
| 5938 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5939 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5940 | trace_nfs4_set_acl(inode, err); |
| 5941 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5942 | &exception); |
| 5943 | } while (exception.retry); |
| 5944 | return err; |
| 5945 | } |
| 5946 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5947 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5948 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5949 | size_t buflen) |
| 5950 | { |
| 5951 | struct nfs_server *server = NFS_SERVER(inode); |
| 5952 | struct nfs_fattr fattr; |
| 5953 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5954 | |
| 5955 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5956 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5957 | .fh = NFS_FH(inode), |
| 5958 | .bitmask = bitmask, |
| 5959 | }; |
| 5960 | struct nfs4_getattr_res res = { |
| 5961 | .fattr = &fattr, |
| 5962 | .label = &label, |
| 5963 | .server = server, |
| 5964 | }; |
| 5965 | struct rpc_message msg = { |
| 5966 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5967 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5968 | .rpc_resp = &res, |
| 5969 | }; |
| 5970 | int ret; |
| 5971 | |
| 5972 | nfs_fattr_init(&fattr); |
| 5973 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5974 | 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] | 5975 | if (ret) |
| 5976 | return ret; |
| 5977 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5978 | return -ENOENT; |
Ondrej Mosnacek | 53cb245 | 2021-01-15 18:43:56 +0100 | [diff] [blame] | 5979 | return label.len; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5980 | } |
| 5981 | |
| 5982 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5983 | size_t buflen) |
| 5984 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5985 | struct nfs4_exception exception = { |
| 5986 | .interruptible = true, |
| 5987 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5988 | int err; |
| 5989 | |
| 5990 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5991 | return -EOPNOTSUPP; |
| 5992 | |
| 5993 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5994 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5995 | trace_nfs4_get_security_label(inode, err); |
| 5996 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5997 | &exception); |
| 5998 | } while (exception.retry); |
| 5999 | return err; |
| 6000 | } |
| 6001 | |
| 6002 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 6003 | struct nfs4_label *ilabel, |
| 6004 | struct nfs_fattr *fattr, |
| 6005 | struct nfs4_label *olabel) |
| 6006 | { |
| 6007 | |
| 6008 | struct iattr sattr = {0}; |
| 6009 | struct nfs_server *server = NFS_SERVER(inode); |
| 6010 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6011 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6012 | .fh = NFS_FH(inode), |
| 6013 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6014 | .server = server, |
| 6015 | .bitmask = bitmask, |
| 6016 | .label = ilabel, |
| 6017 | }; |
| 6018 | struct nfs_setattrres res = { |
| 6019 | .fattr = fattr, |
| 6020 | .label = olabel, |
| 6021 | .server = server, |
| 6022 | }; |
| 6023 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6024 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 6025 | .rpc_argp = &arg, |
| 6026 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6027 | }; |
| 6028 | int status; |
| 6029 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6030 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6031 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6032 | 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] | 6033 | if (status) |
| 6034 | dprintk("%s failed: %d\n", __func__, status); |
| 6035 | |
| 6036 | return status; |
| 6037 | } |
| 6038 | |
| 6039 | static int nfs4_do_set_security_label(struct inode *inode, |
| 6040 | struct nfs4_label *ilabel, |
| 6041 | struct nfs_fattr *fattr, |
| 6042 | struct nfs4_label *olabel) |
| 6043 | { |
| 6044 | struct nfs4_exception exception = { }; |
| 6045 | int err; |
| 6046 | |
| 6047 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6048 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 6049 | fattr, olabel); |
| 6050 | trace_nfs4_set_security_label(inode, err); |
| 6051 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6052 | &exception); |
| 6053 | } while (exception.retry); |
| 6054 | return err; |
| 6055 | } |
| 6056 | |
| 6057 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6058 | 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] | 6059 | { |
| 6060 | struct nfs4_label ilabel, *olabel = NULL; |
| 6061 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6062 | int status; |
| 6063 | |
| 6064 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6065 | return -EOPNOTSUPP; |
| 6066 | |
| 6067 | nfs_fattr_init(&fattr); |
| 6068 | |
| 6069 | ilabel.pi = 0; |
| 6070 | ilabel.lfs = 0; |
| 6071 | ilabel.label = (char *)buf; |
| 6072 | ilabel.len = buflen; |
| 6073 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6074 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 6075 | if (IS_ERR(olabel)) { |
| 6076 | status = -PTR_ERR(olabel); |
| 6077 | goto out; |
| 6078 | } |
| 6079 | |
| 6080 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 6081 | if (status == 0) |
| 6082 | nfs_setsecurity(inode, &fattr, olabel); |
| 6083 | |
| 6084 | nfs4_label_free(olabel); |
| 6085 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6086 | return status; |
| 6087 | } |
| 6088 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 6089 | |
| 6090 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6091 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 6092 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6093 | { |
| 6094 | __be32 verf[2]; |
| 6095 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6096 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 6097 | /* An impossible timestamp guarantees this value |
| 6098 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6099 | verf[0] = cpu_to_be32(U32_MAX); |
| 6100 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6101 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6102 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6103 | u64 ns = ktime_to_ns(nn->boot_time); |
| 6104 | |
| 6105 | verf[0] = cpu_to_be32(ns >> 32); |
| 6106 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6107 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6108 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 6109 | } |
| 6110 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6111 | static size_t |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6112 | nfs4_get_uniquifier(struct nfs_client *clp, char *buf, size_t buflen) |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6113 | { |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6114 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 6115 | struct nfs_netns_client *nn_clp = nn->nfs_client; |
| 6116 | const char *id; |
| 6117 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6118 | buf[0] = '\0'; |
| 6119 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6120 | if (nn_clp) { |
| 6121 | rcu_read_lock(); |
| 6122 | id = rcu_dereference(nn_clp->identifier); |
| 6123 | if (id) |
| 6124 | strscpy(buf, id, buflen); |
| 6125 | rcu_read_unlock(); |
| 6126 | } |
| 6127 | |
| 6128 | if (nfs4_client_id_uniquifier[0] != '\0' && buf[0] == '\0') |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6129 | strscpy(buf, nfs4_client_id_uniquifier, buflen); |
| 6130 | |
| 6131 | return strlen(buf); |
| 6132 | } |
| 6133 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6134 | static int |
| 6135 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6136 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6137 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6138 | size_t buflen; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6139 | size_t len; |
| 6140 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6141 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6142 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6143 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 6144 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6145 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6146 | len = 14 + |
| 6147 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 6148 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6149 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6150 | 1; |
| 6151 | rcu_read_unlock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6152 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6153 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6154 | if (buflen) |
| 6155 | len += buflen + 1; |
| 6156 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6157 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6158 | return -EINVAL; |
| 6159 | |
| 6160 | /* |
| 6161 | * Since this string is allocated at mount time, and held until the |
| 6162 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6163 | * about a memory-reclaim deadlock. |
| 6164 | */ |
| 6165 | str = kmalloc(len, GFP_KERNEL); |
| 6166 | if (!str) |
| 6167 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6168 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6169 | rcu_read_lock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6170 | if (buflen) |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6171 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6172 | clp->cl_rpcclient->cl_nodename, buf, |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6173 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6174 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6175 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6176 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6177 | clp->cl_rpcclient->cl_nodename, |
| 6178 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6179 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6180 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6181 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6182 | clp->cl_owner_id = str; |
| 6183 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6184 | } |
| 6185 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6186 | static int |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6187 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6188 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6189 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6190 | size_t buflen; |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6191 | size_t len; |
| 6192 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6193 | |
| 6194 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6195 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6196 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6197 | len = 10 + 10 + 1 + 10 + 1 + |
| 6198 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6199 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6200 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6201 | if (buflen) |
| 6202 | len += buflen + 1; |
| 6203 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6204 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6205 | return -EINVAL; |
| 6206 | |
| 6207 | /* |
| 6208 | * Since this string is allocated at mount time, and held until the |
| 6209 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6210 | * about a memory-reclaim deadlock. |
| 6211 | */ |
| 6212 | str = kmalloc(len, GFP_KERNEL); |
| 6213 | if (!str) |
| 6214 | return -ENOMEM; |
| 6215 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6216 | if (buflen) |
| 6217 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
| 6218 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6219 | buf, clp->cl_rpcclient->cl_nodename); |
| 6220 | else |
| 6221 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
| 6222 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6223 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6224 | clp->cl_owner_id = str; |
| 6225 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6226 | } |
| 6227 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6228 | /* |
| 6229 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6230 | * services. Advertise one based on the address family of the |
| 6231 | * clientaddr. |
| 6232 | */ |
| 6233 | static unsigned int |
| 6234 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6235 | { |
| 6236 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6237 | return scnprintf(buf, len, "tcp6"); |
| 6238 | else |
| 6239 | return scnprintf(buf, len, "tcp"); |
| 6240 | } |
| 6241 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6242 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6243 | { |
| 6244 | struct nfs4_setclientid *sc = calldata; |
| 6245 | |
| 6246 | if (task->tk_status == 0) |
| 6247 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6248 | } |
| 6249 | |
| 6250 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6251 | .rpc_call_done = nfs4_setclientid_done, |
| 6252 | }; |
| 6253 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6254 | /** |
| 6255 | * nfs4_proc_setclientid - Negotiate client ID |
| 6256 | * @clp: state data structure |
| 6257 | * @program: RPC program for NFSv4 callback service |
| 6258 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6259 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6260 | * @res: where to place the result |
| 6261 | * |
| 6262 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6263 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6264 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6265 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6266 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6267 | { |
| 6268 | nfs4_verifier sc_verifier; |
| 6269 | struct nfs4_setclientid setclientid = { |
| 6270 | .sc_verifier = &sc_verifier, |
| 6271 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6272 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6273 | }; |
| 6274 | struct rpc_message msg = { |
| 6275 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6276 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6277 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6278 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6279 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6280 | struct rpc_task_setup task_setup_data = { |
| 6281 | .rpc_client = clp->cl_rpcclient, |
| 6282 | .rpc_message = &msg, |
| 6283 | .callback_ops = &nfs4_setclientid_ops, |
| 6284 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6285 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6286 | }; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6287 | unsigned long now = jiffies; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6288 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6290 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6291 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6292 | |
| 6293 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6294 | status = nfs4_init_uniform_client_string(clp); |
| 6295 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6296 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6297 | |
| 6298 | if (status) |
| 6299 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6300 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6301 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6302 | setclientid.sc_netid_len = |
| 6303 | nfs4_init_callback_netid(clp, |
| 6304 | setclientid.sc_netid, |
| 6305 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6306 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6307 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6308 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6309 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6310 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6311 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6312 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6313 | |
| 6314 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6315 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6316 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6317 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6318 | put_rpccred(setclientid.sc_cred); |
| 6319 | } |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6320 | |
| 6321 | if (status == 0) |
| 6322 | do_renew_lease(clp, now); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6323 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6324 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6325 | dprintk("NFS reply setclientid: %d\n", status); |
| 6326 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6327 | } |
| 6328 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6329 | /** |
| 6330 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6331 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6332 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6333 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6334 | * |
| 6335 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6336 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6337 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6338 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6339 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6340 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | struct rpc_message msg = { |
| 6342 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6343 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6344 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6346 | int status; |
| 6347 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6348 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6349 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6350 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6351 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6352 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6353 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6354 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6355 | return status; |
| 6356 | } |
| 6357 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6358 | struct nfs4_delegreturndata { |
| 6359 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6360 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6361 | struct nfs_fh fh; |
| 6362 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6363 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6364 | struct { |
| 6365 | struct nfs4_layoutreturn_args arg; |
| 6366 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6367 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6368 | u32 roc_barrier; |
| 6369 | bool roc; |
| 6370 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6371 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6372 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6373 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6374 | }; |
| 6375 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6376 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6377 | { |
| 6378 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6379 | struct nfs4_exception exception = { |
| 6380 | .inode = data->inode, |
| 6381 | .stateid = &data->stateid, |
| 6382 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6383 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6384 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6385 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6386 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6387 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6388 | |
| 6389 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6390 | if (pnfs_roc_done(task, &data->args.lr_args, &data->res.lr_res, |
| 6391 | &data->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6392 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6393 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6394 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6395 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6396 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6397 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6398 | case -NFS4ERR_ADMIN_REVOKED: |
| 6399 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6400 | case -NFS4ERR_EXPIRED: |
| 6401 | nfs4_free_revoked_stateid(data->res.server, |
| 6402 | data->args.stateid, |
| 6403 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6404 | fallthrough; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6405 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6406 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 244fcd2 | 2019-12-20 10:43:37 -0500 | [diff] [blame] | 6407 | case -ETIMEDOUT: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6408 | task->tk_status = 0; |
| 6409 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6410 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6411 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6412 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6413 | if (data->args.bitmask) { |
| 6414 | data->args.bitmask = NULL; |
| 6415 | data->res.fattr = NULL; |
| 6416 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6417 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6418 | case -NFS4ERR_ACCESS: |
| 6419 | if (data->args.bitmask) { |
| 6420 | data->args.bitmask = NULL; |
| 6421 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6422 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6423 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6424 | fallthrough; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6425 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6426 | task->tk_status = nfs4_async_handle_exception(task, |
| 6427 | data->res.server, task->tk_status, |
| 6428 | &exception); |
| 6429 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6430 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6431 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6432 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6433 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6434 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6435 | out_restart: |
| 6436 | task->tk_status = 0; |
| 6437 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6438 | } |
| 6439 | |
| 6440 | static void nfs4_delegreturn_release(void *calldata) |
| 6441 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6442 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6443 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6444 | |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6445 | if (data->lr.roc) |
| 6446 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6447 | data->res.lr_ret); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6448 | if (inode) { |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6449 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6450 | nfs_iput_and_deactive(inode); |
| 6451 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6452 | kfree(calldata); |
| 6453 | } |
| 6454 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6455 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6456 | { |
| 6457 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6458 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6459 | |
| 6460 | d_data = (struct nfs4_delegreturndata *)data; |
| 6461 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6462 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6463 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6464 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6465 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6466 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6467 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6468 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6469 | d_data->args.lr_args = NULL; |
| 6470 | d_data->res.lr_res = NULL; |
| 6471 | } |
| 6472 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6473 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6474 | &d_data->args.seq_args, |
| 6475 | &d_data->res.seq_res, |
| 6476 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6477 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6478 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6479 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6480 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6481 | .rpc_call_done = nfs4_delegreturn_done, |
| 6482 | .rpc_release = nfs4_delegreturn_release, |
| 6483 | }; |
| 6484 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6485 | 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] | 6486 | { |
| 6487 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6488 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6489 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6490 | struct rpc_message msg = { |
| 6491 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6492 | .rpc_cred = cred, |
| 6493 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6494 | struct rpc_task_setup task_setup_data = { |
| 6495 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6496 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6497 | .callback_ops = &nfs4_delegreturn_ops, |
Trond Myklebust | f304a80 | 2020-05-11 10:42:04 -0400 | [diff] [blame] | 6498 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6499 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6500 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6501 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6502 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6503 | if (data == NULL) |
| 6504 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6505 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6506 | |
| 6507 | nfs4_state_protect(server->nfs_client, |
| 6508 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6509 | &task_setup_data.rpc_client, &msg); |
| 6510 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6511 | data->args.fhandle = &data->fh; |
| 6512 | data->args.stateid = &data->stateid; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 6513 | nfs4_bitmask_set(data->args.bitmask_store, |
| 6514 | server->cache_consistency_bitmask, inode, server, |
| 6515 | NULL); |
| 6516 | data->args.bitmask = data->args.bitmask_store; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6517 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6518 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6519 | data->res.fattr = &data->fattr; |
| 6520 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6521 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6522 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6523 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6524 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6525 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6526 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6527 | if (data->inode || issync) { |
| 6528 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, |
| 6529 | cred); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6530 | if (data->lr.roc) { |
| 6531 | data->args.lr_args = &data->lr.arg; |
| 6532 | data->res.lr_res = &data->lr.res; |
| 6533 | } |
| 6534 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6535 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6536 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6537 | msg.rpc_argp = &data->args; |
| 6538 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6539 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6540 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6541 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6542 | if (!issync) |
| 6543 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6544 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6545 | if (status != 0) |
| 6546 | goto out; |
| 6547 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6548 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6549 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6550 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6551 | } |
| 6552 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6553 | 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] | 6554 | { |
| 6555 | struct nfs_server *server = NFS_SERVER(inode); |
| 6556 | struct nfs4_exception exception = { }; |
| 6557 | int err; |
| 6558 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6559 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6560 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6561 | switch (err) { |
| 6562 | case -NFS4ERR_STALE_STATEID: |
| 6563 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6564 | case 0: |
| 6565 | return 0; |
| 6566 | } |
| 6567 | err = nfs4_handle_exception(server, err, &exception); |
| 6568 | } while (exception.retry); |
| 6569 | return err; |
| 6570 | } |
| 6571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6572 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6573 | { |
| 6574 | struct inode *inode = state->inode; |
| 6575 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6576 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6577 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6578 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6579 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6580 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6581 | struct nfs_lockt_res res = { |
| 6582 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6583 | }; |
| 6584 | struct rpc_message msg = { |
| 6585 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6586 | .rpc_argp = &arg, |
| 6587 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6588 | .rpc_cred = state->owner->so_cred, |
| 6589 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6590 | struct nfs4_lock_state *lsp; |
| 6591 | int status; |
| 6592 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6593 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6594 | status = nfs4_set_lock_state(state, request); |
| 6595 | if (status != 0) |
| 6596 | goto out; |
| 6597 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6598 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6599 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6600 | 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] | 6601 | switch (status) { |
| 6602 | case 0: |
| 6603 | request->fl_type = F_UNLCK; |
| 6604 | break; |
| 6605 | case -NFS4ERR_DENIED: |
| 6606 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6607 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6608 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6609 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6610 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6611 | return status; |
| 6612 | } |
| 6613 | |
| 6614 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6615 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6616 | struct nfs4_exception exception = { |
| 6617 | .interruptible = true, |
| 6618 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6619 | int err; |
| 6620 | |
| 6621 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6622 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6623 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6624 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6625 | &exception); |
| 6626 | } while (exception.retry); |
| 6627 | return err; |
| 6628 | } |
| 6629 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6630 | /* |
| 6631 | * Update the seqid of a lock stateid after receiving |
| 6632 | * NFS4ERR_OLD_STATEID |
| 6633 | */ |
| 6634 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6635 | struct nfs4_lock_state *lsp) |
| 6636 | { |
| 6637 | struct nfs4_state *state = lsp->ls_state; |
| 6638 | bool ret = false; |
| 6639 | |
| 6640 | spin_lock(&state->state_lock); |
| 6641 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6642 | goto out; |
| 6643 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6644 | nfs4_stateid_seqid_inc(dst); |
| 6645 | else |
| 6646 | dst->seqid = lsp->ls_stateid.seqid; |
| 6647 | ret = true; |
| 6648 | out: |
| 6649 | spin_unlock(&state->state_lock); |
| 6650 | return ret; |
| 6651 | } |
| 6652 | |
| 6653 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6654 | struct nfs4_lock_state *lsp) |
| 6655 | { |
| 6656 | struct nfs4_state *state = lsp->ls_state; |
| 6657 | bool ret; |
| 6658 | |
| 6659 | spin_lock(&state->state_lock); |
| 6660 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6661 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6662 | spin_unlock(&state->state_lock); |
| 6663 | return ret; |
| 6664 | } |
| 6665 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6666 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6667 | struct nfs_locku_args arg; |
| 6668 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6669 | struct nfs4_lock_state *lsp; |
| 6670 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6671 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6672 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6673 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6674 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6675 | }; |
| 6676 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6677 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6678 | struct nfs_open_context *ctx, |
| 6679 | struct nfs4_lock_state *lsp, |
| 6680 | struct nfs_seqid *seqid) |
| 6681 | { |
| 6682 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6683 | struct nfs4_state *state = lsp->ls_state; |
| 6684 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6685 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6686 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6687 | if (p == NULL) |
| 6688 | return NULL; |
| 6689 | p->arg.fh = NFS_FH(inode); |
| 6690 | p->arg.fl = &p->fl; |
| 6691 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6692 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6693 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6694 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6695 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6696 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6697 | locks_init_lock(&p->fl); |
| 6698 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6699 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6700 | spin_lock(&state->state_lock); |
| 6701 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6702 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6703 | return p; |
| 6704 | } |
| 6705 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6706 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6707 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6708 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6709 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6710 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6711 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6712 | put_nfs_open_context(calldata->ctx); |
| 6713 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6714 | } |
| 6715 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6716 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6717 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6718 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6719 | struct nfs4_exception exception = { |
| 6720 | .inode = calldata->lsp->ls_state->inode, |
| 6721 | .stateid = &calldata->arg.stateid, |
| 6722 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6723 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6724 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6725 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6726 | switch (task->tk_status) { |
| 6727 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6728 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6729 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6730 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6731 | &calldata->res.stateid)) |
| 6732 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6733 | fallthrough; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6734 | case -NFS4ERR_ADMIN_REVOKED: |
| 6735 | case -NFS4ERR_EXPIRED: |
| 6736 | nfs4_free_revoked_stateid(calldata->server, |
| 6737 | &calldata->arg.stateid, |
| 6738 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6739 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6740 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6741 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6742 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6743 | calldata->lsp)) |
| 6744 | rpc_restart_call_prepare(task); |
| 6745 | break; |
| 6746 | case -NFS4ERR_OLD_STATEID: |
| 6747 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6748 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6749 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6750 | break; |
| 6751 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6752 | task->tk_status = nfs4_async_handle_exception(task, |
| 6753 | calldata->server, task->tk_status, |
| 6754 | &exception); |
| 6755 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6756 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6757 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6758 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6759 | } |
| 6760 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6761 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6762 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6763 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6764 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6765 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6766 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6767 | return; |
| 6768 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6769 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6770 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6771 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6772 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6773 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6774 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6775 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6776 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6777 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6778 | &calldata->res.seq_res, |
| 6779 | task) != 0) |
| 6780 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6781 | return; |
| 6782 | out_no_action: |
| 6783 | task->tk_action = NULL; |
| 6784 | out_wait: |
| 6785 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6786 | } |
| 6787 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6788 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6789 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6790 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6791 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6792 | }; |
| 6793 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6794 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6795 | struct nfs_open_context *ctx, |
| 6796 | struct nfs4_lock_state *lsp, |
| 6797 | struct nfs_seqid *seqid) |
| 6798 | { |
| 6799 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6800 | struct rpc_message msg = { |
| 6801 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6802 | .rpc_cred = ctx->cred, |
| 6803 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6804 | struct rpc_task_setup task_setup_data = { |
| 6805 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6806 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6807 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6808 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6809 | .flags = RPC_TASK_ASYNC, |
| 6810 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6811 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6812 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6813 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6814 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6815 | /* Ensure this is an unlock - when canceling a lock, the |
| 6816 | * canceled lock is passed in, and it won't be an unlock. |
| 6817 | */ |
| 6818 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6819 | if (fl->fl_flags & FL_CLOSE) |
| 6820 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6821 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6822 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6823 | if (data == NULL) { |
| 6824 | nfs_free_seqid(seqid); |
| 6825 | return ERR_PTR(-ENOMEM); |
| 6826 | } |
| 6827 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6828 | 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] | 6829 | msg.rpc_argp = &data->arg; |
| 6830 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6831 | task_setup_data.callback_data = data; |
| 6832 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6833 | } |
| 6834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6835 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6836 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6837 | struct inode *inode = state->inode; |
| 6838 | struct nfs4_state_owner *sp = state->owner; |
| 6839 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6840 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6841 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6842 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6843 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6844 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6845 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6846 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6847 | status = nfs4_set_lock_state(state, request); |
| 6848 | /* Unlock _before_ we do the RPC call */ |
| 6849 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6850 | /* Exclude nfs_delegation_claim_locks() */ |
| 6851 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6852 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6853 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6854 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6855 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6856 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6857 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6858 | } |
| 6859 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6860 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6861 | if (status != 0) |
| 6862 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6863 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6864 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6865 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6866 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6867 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6868 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6869 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6870 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6871 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6872 | 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] | 6873 | status = PTR_ERR(task); |
| 6874 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6875 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6876 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6877 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6878 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6879 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6880 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6881 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6882 | } |
| 6883 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6884 | struct nfs4_lockdata { |
| 6885 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6886 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6887 | struct nfs4_lock_state *lsp; |
| 6888 | struct nfs_open_context *ctx; |
| 6889 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6890 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6891 | int rpc_status; |
| 6892 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6893 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6894 | }; |
| 6895 | |
| 6896 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6897 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6898 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6899 | { |
| 6900 | struct nfs4_lockdata *p; |
| 6901 | struct inode *inode = lsp->ls_state->inode; |
| 6902 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6903 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6904 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6905 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6906 | if (p == NULL) |
| 6907 | return NULL; |
| 6908 | |
| 6909 | p->arg.fh = NFS_FH(inode); |
| 6910 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6911 | 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] | 6912 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6913 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6914 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6915 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6916 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6917 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6918 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6919 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6920 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6921 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6922 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6923 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6924 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6925 | locks_init_lock(&p->fl); |
| 6926 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6927 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6928 | out_free_seqid: |
| 6929 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6930 | out_free: |
| 6931 | kfree(p); |
| 6932 | return NULL; |
| 6933 | } |
| 6934 | |
| 6935 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6936 | { |
| 6937 | struct nfs4_lockdata *data = calldata; |
| 6938 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6939 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6940 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6941 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6942 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6943 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6944 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6945 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6946 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6947 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6948 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6949 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6950 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6951 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6952 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6953 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6954 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6955 | &data->lsp->ls_stateid); |
| 6956 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6957 | if (!nfs4_valid_open_stateid(state)) { |
| 6958 | data->rpc_status = -EBADF; |
| 6959 | task->tk_action = NULL; |
| 6960 | goto out_release_open_seqid; |
| 6961 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6962 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6963 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6964 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6965 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6966 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6967 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6968 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6969 | nfs_release_seqid(data->arg.open_seqid); |
| 6970 | out_release_lock_seqid: |
| 6971 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6972 | out_wait: |
| 6973 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6974 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6975 | } |
| 6976 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6977 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6978 | { |
| 6979 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6980 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6981 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6982 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6983 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6984 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6985 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6986 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6987 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6988 | switch (task->tk_status) { |
| 6989 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6990 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6991 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6992 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6993 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6994 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6995 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6996 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6997 | if (data->arg.new_lock_owner != 0) { |
| 6998 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6999 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 7000 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7001 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 7002 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7003 | break; |
| 7004 | case -NFS4ERR_BAD_STATEID: |
| 7005 | case -NFS4ERR_OLD_STATEID: |
| 7006 | case -NFS4ERR_STALE_STATEID: |
| 7007 | case -NFS4ERR_EXPIRED: |
| 7008 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7009 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7010 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7011 | goto out_restart; |
| 7012 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7013 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7014 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7015 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7016 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7017 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7018 | return; |
| 7019 | out_restart: |
| 7020 | if (!data->cancelled) |
| 7021 | rpc_restart_call_prepare(task); |
| 7022 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7023 | } |
| 7024 | |
| 7025 | static void nfs4_lock_release(void *calldata) |
| 7026 | { |
| 7027 | struct nfs4_lockdata *data = calldata; |
| 7028 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7029 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7030 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7031 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7032 | struct rpc_task *task; |
| 7033 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 7034 | data->arg.lock_seqid); |
| 7035 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7036 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7037 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7038 | } else |
| 7039 | nfs_free_seqid(data->arg.lock_seqid); |
| 7040 | nfs4_put_lock_state(data->lsp); |
| 7041 | put_nfs_open_context(data->ctx); |
| 7042 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7043 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7044 | } |
| 7045 | |
| 7046 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 7047 | .rpc_call_prepare = nfs4_lock_prepare, |
| 7048 | .rpc_call_done = nfs4_lock_done, |
| 7049 | .rpc_release = nfs4_lock_release, |
| 7050 | }; |
| 7051 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7052 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 7053 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7054 | switch (error) { |
| 7055 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 7056 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7057 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7058 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7059 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 7060 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7061 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7062 | break; |
| 7063 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7064 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7065 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 7066 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7067 | } |
| 7068 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7069 | 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] | 7070 | { |
| 7071 | struct nfs4_lockdata *data; |
| 7072 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7073 | struct rpc_message msg = { |
| 7074 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 7075 | .rpc_cred = state->owner->so_cred, |
| 7076 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7077 | struct rpc_task_setup task_setup_data = { |
| 7078 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7079 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7080 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 7081 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 7082 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7083 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7084 | int ret; |
| 7085 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7086 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7087 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7088 | fl->fl_u.nfs4_fl.owner, |
| 7089 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7090 | if (data == NULL) |
| 7091 | return -ENOMEM; |
| 7092 | if (IS_SETLKW(cmd)) |
| 7093 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7094 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 7095 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 7096 | msg.rpc_argp = &data->arg; |
| 7097 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7098 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7099 | if (recovery_type > NFS_LOCK_NEW) { |
| 7100 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 7101 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7102 | } else |
| 7103 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7104 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 7105 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7106 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 7107 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7108 | if (ret == 0) { |
| 7109 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7110 | if (ret) |
| 7111 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 7112 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7113 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 7114 | data->cancelled = true; |
Dave Wysochanski | 3d1a90a | 2020-12-11 05:12:51 -0500 | [diff] [blame] | 7115 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 7116 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7117 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7118 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7119 | } |
| 7120 | |
| 7121 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 7122 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7123 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7124 | struct nfs4_exception exception = { |
| 7125 | .inode = state->inode, |
| 7126 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7127 | int err; |
| 7128 | |
| 7129 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7130 | /* Cache the lock if possible... */ |
| 7131 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7132 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7133 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 7134 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7135 | break; |
| 7136 | nfs4_handle_exception(server, err, &exception); |
| 7137 | } while (exception.retry); |
| 7138 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7139 | } |
| 7140 | |
| 7141 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7142 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7143 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7144 | struct nfs4_exception exception = { |
| 7145 | .inode = state->inode, |
| 7146 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7147 | int err; |
| 7148 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 7149 | err = nfs4_set_lock_state(state, request); |
| 7150 | if (err != 0) |
| 7151 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 7152 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 7153 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 7154 | return 0; |
| 7155 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7156 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7157 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7158 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7159 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7160 | switch (err) { |
| 7161 | default: |
| 7162 | goto out; |
| 7163 | case -NFS4ERR_GRACE: |
| 7164 | case -NFS4ERR_DELAY: |
| 7165 | nfs4_handle_exception(server, err, &exception); |
| 7166 | err = 0; |
| 7167 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7168 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7169 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7170 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7171 | } |
| 7172 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7173 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7174 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7175 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7176 | struct nfs4_lock_state *lsp; |
| 7177 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7178 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7179 | status = nfs4_set_lock_state(state, request); |
| 7180 | if (status != 0) |
| 7181 | return status; |
| 7182 | lsp = request->fl_u.nfs4_fl.owner; |
| 7183 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7184 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7185 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7186 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7187 | } |
| 7188 | #endif |
| 7189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7190 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7191 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7192 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7193 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7194 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7195 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7196 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7197 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7198 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7199 | if (status < 0) |
| 7200 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7201 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7202 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7203 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7204 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7205 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7206 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7207 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7208 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7209 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7210 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7211 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7212 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7213 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7214 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7215 | out: |
| 7216 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7217 | return status; |
| 7218 | } |
| 7219 | |
| 7220 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7221 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7222 | struct nfs4_exception exception = { |
| 7223 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7224 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7225 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7226 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7227 | int err; |
| 7228 | |
| 7229 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7230 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7231 | if (err == -NFS4ERR_DENIED) |
| 7232 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7233 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7234 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7235 | } while (exception.retry); |
| 7236 | return err; |
| 7237 | } |
| 7238 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7239 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7240 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7241 | |
| 7242 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7243 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7244 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7245 | { |
| 7246 | int status = -ERESTARTSYS; |
| 7247 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7248 | |
| 7249 | while(!signalled()) { |
| 7250 | status = nfs4_proc_setlk(state, cmd, request); |
| 7251 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7252 | break; |
| 7253 | freezable_schedule_timeout_interruptible(timeout); |
| 7254 | timeout *= 2; |
| 7255 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7256 | status = -ERESTARTSYS; |
| 7257 | } |
| 7258 | return status; |
| 7259 | } |
| 7260 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7261 | #ifdef CONFIG_NFS_V4_1 |
| 7262 | struct nfs4_lock_waiter { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7263 | struct inode *inode; |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7264 | struct nfs_lowner owner; |
| 7265 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7266 | }; |
| 7267 | |
| 7268 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7269 | 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] | 7270 | { |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7271 | struct nfs4_lock_waiter *waiter = |
| 7272 | container_of(wait, struct nfs4_lock_waiter, wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7273 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7274 | /* NULL key means to wake up everyone */ |
| 7275 | if (key) { |
| 7276 | struct cb_notify_lock_args *cbnl = key; |
| 7277 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7278 | *wowner = &waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7279 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7280 | /* Only wake if the callback was for the same owner. */ |
| 7281 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7282 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7283 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7284 | /* Make sure it's for the right inode */ |
| 7285 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7286 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7287 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7288 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7289 | return woken_wake_function(wait, mode, flags, key); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7290 | } |
| 7291 | |
| 7292 | static int |
| 7293 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7294 | { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7295 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7296 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7297 | struct nfs_client *clp = server->nfs_client; |
| 7298 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7299 | struct nfs4_lock_waiter waiter = { |
| 7300 | .inode = state->inode, |
| 7301 | .owner = { .clientid = clp->cl_clientid, |
| 7302 | .id = lsp->ls_seqid.owner_id, |
| 7303 | .s_dev = server->s_dev }, |
| 7304 | }; |
| 7305 | int status; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7306 | |
| 7307 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7308 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7309 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7310 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7311 | init_wait(&waiter.wait); |
| 7312 | waiter.wait.func = nfs4_wake_lock_waiter; |
| 7313 | add_wait_queue(q, &waiter.wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7314 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7315 | do { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7316 | status = nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7317 | if (status != -EAGAIN || IS_SETLK(cmd)) |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7318 | break; |
| 7319 | |
| 7320 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7321 | freezer_do_not_count(); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7322 | wait_woken(&waiter.wait, TASK_INTERRUPTIBLE, |
| 7323 | NFS4_LOCK_MAXTIMEOUT); |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7324 | freezer_count(); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7325 | } while (!signalled()); |
| 7326 | |
| 7327 | remove_wait_queue(q, &waiter.wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7328 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7329 | return status; |
| 7330 | } |
| 7331 | #else /* !CONFIG_NFS_V4_1 */ |
| 7332 | static inline int |
| 7333 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7334 | { |
| 7335 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7336 | } |
| 7337 | #endif |
| 7338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7339 | static int |
| 7340 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7341 | { |
| 7342 | struct nfs_open_context *ctx; |
| 7343 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7344 | int status; |
| 7345 | |
| 7346 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7347 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7348 | state = ctx->state; |
| 7349 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7350 | if (IS_GETLK(cmd)) { |
| 7351 | if (state != NULL) |
| 7352 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7353 | return 0; |
| 7354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7355 | |
| 7356 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7357 | return -EINVAL; |
| 7358 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7359 | if (request->fl_type == F_UNLCK) { |
| 7360 | if (state != NULL) |
| 7361 | return nfs4_proc_unlck(state, cmd, request); |
| 7362 | return 0; |
| 7363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7364 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7365 | if (state == NULL) |
| 7366 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7367 | |
| 7368 | if ((request->fl_flags & FL_POSIX) && |
| 7369 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7370 | return -ENOLCK; |
| 7371 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7372 | /* |
| 7373 | * Don't rely on the VFS having checked the file open mode, |
| 7374 | * since it won't do this for flock() locks. |
| 7375 | */ |
| 7376 | switch (request->fl_type) { |
| 7377 | case F_RDLCK: |
| 7378 | if (!(filp->f_mode & FMODE_READ)) |
| 7379 | return -EBADF; |
| 7380 | break; |
| 7381 | case F_WRLCK: |
| 7382 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7383 | return -EBADF; |
| 7384 | } |
| 7385 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7386 | status = nfs4_set_lock_state(state, request); |
| 7387 | if (status != 0) |
| 7388 | return status; |
| 7389 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7390 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7391 | } |
| 7392 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7393 | 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] | 7394 | { |
| 7395 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7396 | int err; |
| 7397 | |
| 7398 | err = nfs4_set_lock_state(state, fl); |
| 7399 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7400 | return err; |
Olga Kornievskaia | 3d7a952 | 2020-08-20 18:52:43 -0400 | [diff] [blame] | 7401 | do { |
| 7402 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
| 7403 | if (err != -NFS4ERR_DELAY) |
| 7404 | break; |
| 7405 | ssleep(1); |
| 7406 | } while (err == -NFS4ERR_DELAY); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7407 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7408 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7409 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7410 | struct nfs_release_lockowner_data { |
| 7411 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7412 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7413 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7414 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7415 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7416 | }; |
| 7417 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7418 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7419 | { |
| 7420 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7421 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7422 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7423 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7424 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7425 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7426 | } |
| 7427 | |
| 7428 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7429 | { |
| 7430 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7431 | struct nfs_server *server = data->server; |
| 7432 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7433 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7434 | |
| 7435 | switch (task->tk_status) { |
| 7436 | case 0: |
| 7437 | renew_lease(server, data->timestamp); |
| 7438 | break; |
| 7439 | case -NFS4ERR_STALE_CLIENTID: |
| 7440 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7441 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7442 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7443 | case -NFS4ERR_LEASE_MOVED: |
| 7444 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7445 | if (nfs4_async_handle_error(task, server, |
| 7446 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7447 | rpc_restart_call_prepare(task); |
| 7448 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7449 | } |
| 7450 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7451 | static void nfs4_release_lockowner_release(void *calldata) |
| 7452 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7453 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7454 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7455 | kfree(calldata); |
| 7456 | } |
| 7457 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7458 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7459 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7460 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7461 | .rpc_release = nfs4_release_lockowner_release, |
| 7462 | }; |
| 7463 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7464 | static void |
| 7465 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7466 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7467 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7468 | struct rpc_message msg = { |
| 7469 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7470 | }; |
| 7471 | |
| 7472 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7473 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7474 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7475 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7476 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7477 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7478 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7479 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7480 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7481 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7482 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7483 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7484 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7485 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7486 | 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] | 7487 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7488 | } |
| 7489 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7490 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7491 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7492 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7493 | struct user_namespace *mnt_userns, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7494 | struct dentry *unused, struct inode *inode, |
| 7495 | const char *key, const void *buf, |
| 7496 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7497 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7498 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7499 | } |
| 7500 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7501 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7502 | struct dentry *unused, struct inode *inode, |
| 7503 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7504 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7505 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7506 | } |
| 7507 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7508 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7509 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7510 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7511 | } |
| 7512 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7513 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7514 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7515 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7516 | struct user_namespace *mnt_userns, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7517 | struct dentry *unused, struct inode *inode, |
| 7518 | const char *key, const void *buf, |
| 7519 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7520 | { |
| 7521 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7522 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7523 | |
| 7524 | return -EOPNOTSUPP; |
| 7525 | } |
| 7526 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7527 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7528 | struct dentry *unused, struct inode *inode, |
| 7529 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7530 | { |
| 7531 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7532 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7533 | return -EOPNOTSUPP; |
| 7534 | } |
| 7535 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7536 | static ssize_t |
| 7537 | 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] | 7538 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7539 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7540 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7541 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7542 | len = security_inode_listsecurity(inode, list, list_len); |
Chengguang Xu | 82c596e | 2020-06-17 09:09:39 +0800 | [diff] [blame] | 7543 | if (len >= 0 && list_len && len > list_len) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7544 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7545 | } |
| 7546 | return len; |
| 7547 | } |
| 7548 | |
| 7549 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7550 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7551 | .get = nfs4_xattr_get_nfs4_label, |
| 7552 | .set = nfs4_xattr_set_nfs4_label, |
| 7553 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7554 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7555 | #else |
| 7556 | |
| 7557 | static ssize_t |
| 7558 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7559 | { |
| 7560 | return 0; |
| 7561 | } |
| 7562 | |
| 7563 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7564 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7565 | #ifdef CONFIG_NFS_V4_2 |
| 7566 | static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7567 | struct user_namespace *mnt_userns, |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7568 | struct dentry *unused, struct inode *inode, |
| 7569 | const char *key, const void *buf, |
| 7570 | size_t buflen, int flags) |
| 7571 | { |
| 7572 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7573 | int ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7574 | |
| 7575 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7576 | return -EOPNOTSUPP; |
| 7577 | |
| 7578 | /* |
| 7579 | * There is no mapping from the MAY_* flags to the NFS_ACCESS_XA* |
| 7580 | * flags right now. Handling of xattr operations use the normal |
| 7581 | * file read/write permissions. |
| 7582 | * |
| 7583 | * Just in case the server has other ideas (which RFC 8276 allows), |
| 7584 | * do a cached access check for the XA* flags to possibly avoid |
| 7585 | * doing an RPC and getting EACCES back. |
| 7586 | */ |
| 7587 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7588 | if (!(cache.mask & NFS_ACCESS_XAWRITE)) |
| 7589 | return -EACCES; |
| 7590 | } |
| 7591 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7592 | if (buf == NULL) { |
| 7593 | ret = nfs42_proc_removexattr(inode, key); |
| 7594 | if (!ret) |
| 7595 | nfs4_xattr_cache_remove(inode, key); |
| 7596 | } else { |
| 7597 | ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags); |
| 7598 | if (!ret) |
| 7599 | nfs4_xattr_cache_add(inode, key, buf, NULL, buflen); |
| 7600 | } |
| 7601 | |
| 7602 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler, |
| 7606 | struct dentry *unused, struct inode *inode, |
| 7607 | const char *key, void *buf, size_t buflen) |
| 7608 | { |
| 7609 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7610 | ssize_t ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7611 | |
| 7612 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7613 | return -EOPNOTSUPP; |
| 7614 | |
| 7615 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7616 | if (!(cache.mask & NFS_ACCESS_XAREAD)) |
| 7617 | return -EACCES; |
| 7618 | } |
| 7619 | |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 7620 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7621 | if (ret) |
| 7622 | return ret; |
| 7623 | |
| 7624 | ret = nfs4_xattr_cache_get(inode, key, buf, buflen); |
| 7625 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7626 | return ret; |
| 7627 | |
| 7628 | ret = nfs42_proc_getxattr(inode, key, buf, buflen); |
| 7629 | |
| 7630 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7631 | } |
| 7632 | |
| 7633 | static ssize_t |
| 7634 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7635 | { |
| 7636 | u64 cookie; |
| 7637 | bool eof; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7638 | ssize_t ret, size; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7639 | char *buf; |
| 7640 | size_t buflen; |
| 7641 | struct nfs_access_entry cache; |
| 7642 | |
| 7643 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7644 | return 0; |
| 7645 | |
| 7646 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7647 | if (!(cache.mask & NFS_ACCESS_XALIST)) |
| 7648 | return 0; |
| 7649 | } |
| 7650 | |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 7651 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7652 | if (ret) |
| 7653 | return ret; |
| 7654 | |
| 7655 | ret = nfs4_xattr_cache_list(inode, list, list_len); |
| 7656 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7657 | return ret; |
| 7658 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7659 | cookie = 0; |
| 7660 | eof = false; |
| 7661 | buflen = list_len ? list_len : XATTR_LIST_MAX; |
| 7662 | buf = list_len ? list : NULL; |
| 7663 | size = 0; |
| 7664 | |
| 7665 | while (!eof) { |
| 7666 | ret = nfs42_proc_listxattrs(inode, buf, buflen, |
| 7667 | &cookie, &eof); |
| 7668 | if (ret < 0) |
| 7669 | return ret; |
| 7670 | |
| 7671 | if (list_len) { |
| 7672 | buf += ret; |
| 7673 | buflen -= ret; |
| 7674 | } |
| 7675 | size += ret; |
| 7676 | } |
| 7677 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7678 | if (list_len) |
| 7679 | nfs4_xattr_cache_set_list(inode, list, size); |
| 7680 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7681 | return size; |
| 7682 | } |
| 7683 | |
| 7684 | #else |
| 7685 | |
| 7686 | static ssize_t |
| 7687 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7688 | { |
| 7689 | return 0; |
| 7690 | } |
| 7691 | #endif /* CONFIG_NFS_V4_2 */ |
| 7692 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7693 | /* |
| 7694 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7695 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7696 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7697 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7698 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7699 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7700 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7701 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7702 | return; |
| 7703 | |
| 7704 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7705 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7706 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7707 | fattr->nlink = 2; |
| 7708 | } |
| 7709 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7710 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7711 | const struct qstr *name, |
| 7712 | struct nfs4_fs_locations *fs_locations, |
| 7713 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7714 | { |
| 7715 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7716 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7717 | struct nfs4_fs_locations_arg args = { |
| 7718 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7719 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7720 | .page = page, |
| 7721 | .bitmask = bitmask, |
| 7722 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7723 | struct nfs4_fs_locations_res res = { |
| 7724 | .fs_locations = fs_locations, |
| 7725 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7726 | struct rpc_message msg = { |
| 7727 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7728 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7729 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7730 | }; |
| 7731 | int status; |
| 7732 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7733 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7734 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7735 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7736 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7737 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7738 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7739 | * is not supported */ |
| 7740 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7741 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7742 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7743 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7744 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7745 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7746 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7747 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7748 | 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] | 7749 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7750 | return status; |
| 7751 | } |
| 7752 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7753 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7754 | const struct qstr *name, |
| 7755 | struct nfs4_fs_locations *fs_locations, |
| 7756 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7757 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7758 | struct nfs4_exception exception = { |
| 7759 | .interruptible = true, |
| 7760 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7761 | int err; |
| 7762 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7763 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7764 | fs_locations, page); |
| 7765 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7766 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7767 | &exception); |
| 7768 | } while (exception.retry); |
| 7769 | return err; |
| 7770 | } |
| 7771 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7772 | /* |
| 7773 | * This operation also signals the server that this client is |
| 7774 | * performing migration recovery. The server can stop returning |
| 7775 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7776 | * appended to this compound to identify the client ID which is |
| 7777 | * performing recovery. |
| 7778 | */ |
| 7779 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7780 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7781 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7782 | { |
| 7783 | struct nfs_server *server = NFS_SERVER(inode); |
| 7784 | struct rpc_clnt *clnt = server->client; |
| 7785 | u32 bitmask[2] = { |
| 7786 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7787 | }; |
| 7788 | struct nfs4_fs_locations_arg args = { |
| 7789 | .clientid = server->nfs_client->cl_clientid, |
| 7790 | .fh = NFS_FH(inode), |
| 7791 | .page = page, |
| 7792 | .bitmask = bitmask, |
| 7793 | .migration = 1, /* skip LOOKUP */ |
| 7794 | .renew = 1, /* append RENEW */ |
| 7795 | }; |
| 7796 | struct nfs4_fs_locations_res res = { |
| 7797 | .fs_locations = locations, |
| 7798 | .migration = 1, |
| 7799 | .renew = 1, |
| 7800 | }; |
| 7801 | struct rpc_message msg = { |
| 7802 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7803 | .rpc_argp = &args, |
| 7804 | .rpc_resp = &res, |
| 7805 | .rpc_cred = cred, |
| 7806 | }; |
| 7807 | unsigned long now = jiffies; |
| 7808 | int status; |
| 7809 | |
| 7810 | nfs_fattr_init(&locations->fattr); |
| 7811 | locations->server = server; |
| 7812 | locations->nlocations = 0; |
| 7813 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7814 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7815 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7816 | &args.seq_args, &res.seq_res); |
| 7817 | if (status) |
| 7818 | return status; |
| 7819 | |
| 7820 | renew_lease(server, now); |
| 7821 | return 0; |
| 7822 | } |
| 7823 | |
| 7824 | #ifdef CONFIG_NFS_V4_1 |
| 7825 | |
| 7826 | /* |
| 7827 | * This operation also signals the server that this client is |
| 7828 | * performing migration recovery. The server can stop asserting |
| 7829 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7830 | * performing this operation is identified in the SEQUENCE |
| 7831 | * operation in this compound. |
| 7832 | * |
| 7833 | * When the client supports GETATTR(fs_locations_info), it can |
| 7834 | * be plumbed in here. |
| 7835 | */ |
| 7836 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7837 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7838 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7839 | { |
| 7840 | struct nfs_server *server = NFS_SERVER(inode); |
| 7841 | struct rpc_clnt *clnt = server->client; |
| 7842 | u32 bitmask[2] = { |
| 7843 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7844 | }; |
| 7845 | struct nfs4_fs_locations_arg args = { |
| 7846 | .fh = NFS_FH(inode), |
| 7847 | .page = page, |
| 7848 | .bitmask = bitmask, |
| 7849 | .migration = 1, /* skip LOOKUP */ |
| 7850 | }; |
| 7851 | struct nfs4_fs_locations_res res = { |
| 7852 | .fs_locations = locations, |
| 7853 | .migration = 1, |
| 7854 | }; |
| 7855 | struct rpc_message msg = { |
| 7856 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7857 | .rpc_argp = &args, |
| 7858 | .rpc_resp = &res, |
| 7859 | .rpc_cred = cred, |
| 7860 | }; |
| 7861 | int status; |
| 7862 | |
| 7863 | nfs_fattr_init(&locations->fattr); |
| 7864 | locations->server = server; |
| 7865 | locations->nlocations = 0; |
| 7866 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7867 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7868 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7869 | &args.seq_args, &res.seq_res); |
| 7870 | if (status == NFS4_OK && |
| 7871 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7872 | status = -NFS4ERR_LEASE_MOVED; |
| 7873 | return status; |
| 7874 | } |
| 7875 | |
| 7876 | #endif /* CONFIG_NFS_V4_1 */ |
| 7877 | |
| 7878 | /** |
| 7879 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7880 | * @inode: inode on FSID that is migrating |
| 7881 | * @locations: result of query |
| 7882 | * @page: buffer |
| 7883 | * @cred: credential to use for this operation |
| 7884 | * |
| 7885 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7886 | * operation failed, or a negative errno if a local error occurred. |
| 7887 | * |
| 7888 | * On success, "locations" is filled in, but if the server has |
| 7889 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7890 | * asserted. |
| 7891 | * |
| 7892 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7893 | * from this client that require migration recovery. |
| 7894 | */ |
| 7895 | int nfs4_proc_get_locations(struct inode *inode, |
| 7896 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7897 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7898 | { |
| 7899 | struct nfs_server *server = NFS_SERVER(inode); |
| 7900 | struct nfs_client *clp = server->nfs_client; |
| 7901 | const struct nfs4_mig_recovery_ops *ops = |
| 7902 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7903 | struct nfs4_exception exception = { |
| 7904 | .interruptible = true, |
| 7905 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7906 | int status; |
| 7907 | |
| 7908 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7909 | (unsigned long long)server->fsid.major, |
| 7910 | (unsigned long long)server->fsid.minor, |
| 7911 | clp->cl_hostname); |
| 7912 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7913 | |
| 7914 | do { |
| 7915 | status = ops->get_locations(inode, locations, page, cred); |
| 7916 | if (status != -NFS4ERR_DELAY) |
| 7917 | break; |
| 7918 | nfs4_handle_exception(server, status, &exception); |
| 7919 | } while (exception.retry); |
| 7920 | return status; |
| 7921 | } |
| 7922 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7923 | /* |
| 7924 | * This operation also signals the server that this client is |
| 7925 | * performing "lease moved" recovery. The server can stop |
| 7926 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7927 | * is appended to this compound to identify the client ID which is |
| 7928 | * performing recovery. |
| 7929 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7930 | 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] | 7931 | { |
| 7932 | struct nfs_server *server = NFS_SERVER(inode); |
| 7933 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7934 | struct rpc_clnt *clnt = server->client; |
| 7935 | struct nfs4_fsid_present_arg args = { |
| 7936 | .fh = NFS_FH(inode), |
| 7937 | .clientid = clp->cl_clientid, |
| 7938 | .renew = 1, /* append RENEW */ |
| 7939 | }; |
| 7940 | struct nfs4_fsid_present_res res = { |
| 7941 | .renew = 1, |
| 7942 | }; |
| 7943 | struct rpc_message msg = { |
| 7944 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7945 | .rpc_argp = &args, |
| 7946 | .rpc_resp = &res, |
| 7947 | .rpc_cred = cred, |
| 7948 | }; |
| 7949 | unsigned long now = jiffies; |
| 7950 | int status; |
| 7951 | |
| 7952 | res.fh = nfs_alloc_fhandle(); |
| 7953 | if (res.fh == NULL) |
| 7954 | return -ENOMEM; |
| 7955 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7956 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7957 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7958 | &args.seq_args, &res.seq_res); |
| 7959 | nfs_free_fhandle(res.fh); |
| 7960 | if (status) |
| 7961 | return status; |
| 7962 | |
| 7963 | do_renew_lease(clp, now); |
| 7964 | return 0; |
| 7965 | } |
| 7966 | |
| 7967 | #ifdef CONFIG_NFS_V4_1 |
| 7968 | |
| 7969 | /* |
| 7970 | * This operation also signals the server that this client is |
| 7971 | * performing "lease moved" recovery. The server can stop asserting |
| 7972 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7973 | * this operation is identified in the SEQUENCE operation in this |
| 7974 | * compound. |
| 7975 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7976 | 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] | 7977 | { |
| 7978 | struct nfs_server *server = NFS_SERVER(inode); |
| 7979 | struct rpc_clnt *clnt = server->client; |
| 7980 | struct nfs4_fsid_present_arg args = { |
| 7981 | .fh = NFS_FH(inode), |
| 7982 | }; |
| 7983 | struct nfs4_fsid_present_res res = { |
| 7984 | }; |
| 7985 | struct rpc_message msg = { |
| 7986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7987 | .rpc_argp = &args, |
| 7988 | .rpc_resp = &res, |
| 7989 | .rpc_cred = cred, |
| 7990 | }; |
| 7991 | int status; |
| 7992 | |
| 7993 | res.fh = nfs_alloc_fhandle(); |
| 7994 | if (res.fh == NULL) |
| 7995 | return -ENOMEM; |
| 7996 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7997 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7998 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7999 | &args.seq_args, &res.seq_res); |
| 8000 | nfs_free_fhandle(res.fh); |
| 8001 | if (status == NFS4_OK && |
| 8002 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 8003 | status = -NFS4ERR_LEASE_MOVED; |
| 8004 | return status; |
| 8005 | } |
| 8006 | |
| 8007 | #endif /* CONFIG_NFS_V4_1 */ |
| 8008 | |
| 8009 | /** |
| 8010 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 8011 | * @inode: inode on FSID to check |
| 8012 | * @cred: credential to use for this operation |
| 8013 | * |
| 8014 | * Server indicates whether the FSID is present, moved, or not |
| 8015 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 8016 | * condition for this client ID. |
| 8017 | * |
| 8018 | * Returns NFS4_OK if the FSID is present on this server, |
| 8019 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 8020 | * NFS4ERR code if some error occurred on the server, or a |
| 8021 | * negative errno if a local failure occurred. |
| 8022 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8023 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8024 | { |
| 8025 | struct nfs_server *server = NFS_SERVER(inode); |
| 8026 | struct nfs_client *clp = server->nfs_client; |
| 8027 | const struct nfs4_mig_recovery_ops *ops = |
| 8028 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8029 | struct nfs4_exception exception = { |
| 8030 | .interruptible = true, |
| 8031 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8032 | int status; |
| 8033 | |
| 8034 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 8035 | (unsigned long long)server->fsid.major, |
| 8036 | (unsigned long long)server->fsid.minor, |
| 8037 | clp->cl_hostname); |
| 8038 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 8039 | |
| 8040 | do { |
| 8041 | status = ops->fsid_present(inode, cred); |
| 8042 | if (status != -NFS4ERR_DELAY) |
| 8043 | break; |
| 8044 | nfs4_handle_exception(server, status, &exception); |
| 8045 | } while (exception.retry); |
| 8046 | return status; |
| 8047 | } |
| 8048 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 8049 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8050 | * If 'use_integrity' is true and the state managment nfs_client |
| 8051 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 8052 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 8053 | * Considerations sections. Otherwise, just use the user cred with the |
| 8054 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 8055 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8056 | 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] | 8057 | { |
| 8058 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8059 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 8060 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8061 | struct nfs4_secinfo_arg args = { |
| 8062 | .dir_fh = NFS_FH(dir), |
| 8063 | .name = name, |
| 8064 | }; |
| 8065 | struct nfs4_secinfo_res res = { |
| 8066 | .flavors = flavors, |
| 8067 | }; |
| 8068 | struct rpc_message msg = { |
| 8069 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 8070 | .rpc_argp = &args, |
| 8071 | .rpc_resp = &res, |
| 8072 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8073 | struct nfs4_call_sync_data data = { |
| 8074 | .seq_server = NFS_SERVER(dir), |
| 8075 | .seq_args = &args.seq_args, |
| 8076 | .seq_res = &res.seq_res, |
| 8077 | }; |
| 8078 | struct rpc_task_setup task_setup = { |
| 8079 | .rpc_client = clnt, |
| 8080 | .rpc_message = &msg, |
| 8081 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 8082 | .callback_data = &data, |
| 8083 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 8084 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8085 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8086 | |
| 8087 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8088 | clnt = clp->cl_rpcclient; |
| 8089 | task_setup.rpc_client = clnt; |
| 8090 | |
| 8091 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8092 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8093 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8094 | |
| 8095 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8096 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8097 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 8098 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 8099 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8100 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8101 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8102 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8103 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8104 | return status; |
| 8105 | } |
| 8106 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 8107 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 8108 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8109 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8110 | struct nfs4_exception exception = { |
| 8111 | .interruptible = true, |
| 8112 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8113 | int err; |
| 8114 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8115 | err = -NFS4ERR_WRONGSEC; |
| 8116 | |
| 8117 | /* try to use integrity protection with machine cred */ |
| 8118 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 8119 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 8120 | |
| 8121 | /* |
| 8122 | * if unable to use integrity protection, or SECINFO with |
| 8123 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8124 | * disallowed by spec, but exists in deployed servers) use |
| 8125 | * the current filesystem's rpc_client and the user cred. |
| 8126 | */ |
| 8127 | if (err == -NFS4ERR_WRONGSEC) |
| 8128 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 8129 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 8130 | trace_nfs4_secinfo(dir, name, err); |
| 8131 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8132 | &exception); |
| 8133 | } while (exception.retry); |
| 8134 | return err; |
| 8135 | } |
| 8136 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8137 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8138 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8139 | * Check the exchange flags returned by the server for invalid flags, having |
| 8140 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 8141 | * DS flags set. |
| 8142 | */ |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8143 | static int nfs4_check_cl_exchange_flags(u32 flags, u32 version) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8144 | { |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8145 | if (version >= 2 && (flags & ~EXCHGID4_2_FLAG_MASK_R)) |
| 8146 | goto out_inval; |
| 8147 | else if (version < 2 && (flags & ~EXCHGID4_FLAG_MASK_R)) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8148 | goto out_inval; |
| 8149 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 8150 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 8151 | goto out_inval; |
| 8152 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 8153 | goto out_inval; |
| 8154 | return NFS_OK; |
| 8155 | out_inval: |
| 8156 | return -NFS4ERR_INVAL; |
| 8157 | } |
| 8158 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8159 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 8160 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 8161 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8162 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 8163 | if (a->server_scope_sz != b->server_scope_sz) |
| 8164 | return false; |
| 8165 | 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] | 8166 | } |
| 8167 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8168 | static void |
| 8169 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 8170 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8171 | 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] | 8172 | 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] | 8173 | struct nfs_client *clp = args->client; |
| 8174 | |
| 8175 | switch (task->tk_status) { |
| 8176 | case -NFS4ERR_BADSESSION: |
| 8177 | case -NFS4ERR_DEADSESSION: |
| 8178 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8179 | task->tk_status); |
| 8180 | } |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8181 | if (args->dir == NFS4_CDFC4_FORE_OR_BOTH && |
| 8182 | res->dir != NFS4_CDFS4_BOTH) { |
| 8183 | rpc_task_close_connection(task); |
| 8184 | if (args->retries++ < MAX_BIND_CONN_TO_SESSION_RETRIES) |
| 8185 | rpc_restart_call(task); |
| 8186 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8187 | } |
| 8188 | |
| 8189 | 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] | 8190 | .rpc_call_done = nfs4_bind_one_conn_to_session_done, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8191 | }; |
| 8192 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8193 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8194 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8195 | * |
| 8196 | * The 4.1 client currently uses the same TCP connection for the |
| 8197 | * fore and backchannel. |
| 8198 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8199 | static |
| 8200 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 8201 | struct rpc_xprt *xprt, |
| 8202 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8203 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8204 | { |
| 8205 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8206 | struct nfs41_bind_conn_to_session_args args = { |
| 8207 | .client = clp, |
| 8208 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8209 | .retries = 0, |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8210 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8211 | struct nfs41_bind_conn_to_session_res res; |
| 8212 | struct rpc_message msg = { |
| 8213 | .rpc_proc = |
| 8214 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8215 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8216 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 8217 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8218 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8219 | struct rpc_task_setup task_setup_data = { |
| 8220 | .rpc_client = clnt, |
| 8221 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8222 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8223 | .rpc_message = &msg, |
| 8224 | .flags = RPC_TASK_TIMEOUT, |
| 8225 | }; |
| 8226 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8227 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8228 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 8229 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 8230 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8231 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8232 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 8233 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 8234 | args.dir = NFS4_CDFC4_FORE; |
| 8235 | |
| 8236 | task = rpc_run_task(&task_setup_data); |
| 8237 | if (!IS_ERR(task)) { |
| 8238 | status = task->tk_status; |
| 8239 | rpc_put_task(task); |
| 8240 | } else |
| 8241 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8242 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8243 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8244 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8245 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 8246 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8247 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8248 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8249 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8250 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 8251 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8252 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8253 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8254 | 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] | 8255 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 8256 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8257 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8258 | } |
| 8259 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8260 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8261 | return status; |
| 8262 | } |
| 8263 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8264 | struct rpc_bind_conn_calldata { |
| 8265 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8266 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8267 | }; |
| 8268 | |
| 8269 | static int |
| 8270 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 8271 | struct rpc_xprt *xprt, |
| 8272 | void *calldata) |
| 8273 | { |
| 8274 | struct rpc_bind_conn_calldata *p = calldata; |
| 8275 | |
| 8276 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 8277 | } |
| 8278 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8279 | 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] | 8280 | { |
| 8281 | struct rpc_bind_conn_calldata data = { |
| 8282 | .clp = clp, |
| 8283 | .cred = cred, |
| 8284 | }; |
| 8285 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 8286 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 8287 | } |
| 8288 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8289 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8290 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 8291 | * 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] | 8292 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8293 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 8294 | .how = SP4_MACH_CRED, |
| 8295 | .enforce.u.words = { |
| 8296 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8297 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8298 | 1 << (OP_CREATE_SESSION - 32) | |
| 8299 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8300 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8301 | }, |
| 8302 | .allow.u.words = { |
| 8303 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8304 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8305 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8306 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8307 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8308 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8309 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8310 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8311 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8312 | 1 << (OP_FREE_STATEID - 32) | |
| 8313 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8314 | } |
| 8315 | }; |
| 8316 | |
| 8317 | /* |
| 8318 | * Select the state protection mode for client `clp' given the server results |
| 8319 | * from exchange_id in `sp'. |
| 8320 | * |
| 8321 | * Returns 0 on success, negative errno otherwise. |
| 8322 | */ |
| 8323 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8324 | struct nfs41_state_protection *sp) |
| 8325 | { |
| 8326 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8327 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8328 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8329 | 1 << (OP_CREATE_SESSION - 32) | |
| 8330 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8331 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8332 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8333 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8334 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8335 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8336 | |
| 8337 | if (sp->how == SP4_MACH_CRED) { |
| 8338 | /* Print state protect result */ |
| 8339 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8340 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8341 | if (test_bit(i, sp->enforce.u.longs)) |
| 8342 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8343 | if (test_bit(i, sp->allow.u.longs)) |
| 8344 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8345 | } |
| 8346 | |
| 8347 | /* make sure nothing is on enforce list that isn't supported */ |
| 8348 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8349 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8350 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8351 | ret = -EINVAL; |
| 8352 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8353 | } |
| 8354 | } |
| 8355 | |
| 8356 | /* |
| 8357 | * Minimal mode - state operations are allowed to use machine |
| 8358 | * credential. Note this already happens by default, so the |
| 8359 | * client doesn't have to do anything more than the negotiation. |
| 8360 | * |
| 8361 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8362 | * we're already using the machine cred for exchange_id |
| 8363 | * and will never use a different cred. |
| 8364 | */ |
| 8365 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8366 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8367 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8368 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8369 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8370 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8371 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8372 | } else { |
| 8373 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8374 | ret = -EINVAL; |
| 8375 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8376 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8377 | |
| 8378 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8379 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8380 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8381 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8382 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8383 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8384 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8385 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8386 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8387 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8388 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8389 | } |
| 8390 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8391 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8392 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8393 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8394 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8395 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8396 | |
| 8397 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8398 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8399 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8400 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8401 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8402 | |
| 8403 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8404 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8405 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8406 | } |
| 8407 | |
| 8408 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8409 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8410 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8411 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8412 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8413 | out: |
| 8414 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8415 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8416 | } |
| 8417 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8418 | struct nfs41_exchange_id_data { |
| 8419 | struct nfs41_exchange_id_res res; |
| 8420 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8421 | }; |
| 8422 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8423 | static void nfs4_exchange_id_release(void *data) |
| 8424 | { |
| 8425 | struct nfs41_exchange_id_data *cdata = |
| 8426 | (struct nfs41_exchange_id_data *)data; |
| 8427 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8428 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8429 | kfree(cdata->res.impl_id); |
| 8430 | kfree(cdata->res.server_scope); |
| 8431 | kfree(cdata->res.server_owner); |
| 8432 | kfree(cdata); |
| 8433 | } |
| 8434 | |
| 8435 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8436 | .rpc_release = nfs4_exchange_id_release, |
| 8437 | }; |
| 8438 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8439 | /* |
| 8440 | * _nfs4_proc_exchange_id() |
| 8441 | * |
| 8442 | * Wrapper for EXCHANGE_ID operation. |
| 8443 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8444 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8445 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8446 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8447 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8448 | struct rpc_message msg = { |
| 8449 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8450 | .rpc_cred = cred, |
| 8451 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8452 | struct rpc_task_setup task_setup_data = { |
| 8453 | .rpc_client = clp->cl_rpcclient, |
| 8454 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8455 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8456 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8457 | }; |
| 8458 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8459 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8460 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8461 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8462 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8463 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8464 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8465 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8466 | if (!calldata) |
| 8467 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8468 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8469 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8470 | |
| 8471 | status = nfs4_init_uniform_client_string(clp); |
| 8472 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8473 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8474 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8475 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8476 | GFP_NOFS); |
| 8477 | status = -ENOMEM; |
| 8478 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8479 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8480 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8481 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8482 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8483 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8484 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8485 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8486 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8487 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8488 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8489 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8490 | switch (sp4_how) { |
| 8491 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8492 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8493 | break; |
| 8494 | |
| 8495 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8496 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8497 | break; |
| 8498 | |
| 8499 | default: |
| 8500 | /* unsupported! */ |
| 8501 | WARN_ON_ONCE(1); |
| 8502 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8503 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8504 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8505 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8506 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8507 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8508 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8509 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8510 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8511 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8512 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8513 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8514 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8515 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8516 | #endif |
| 8517 | msg.rpc_argp = &calldata->args; |
| 8518 | msg.rpc_resp = &calldata->res; |
| 8519 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8520 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8521 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8522 | |
| 8523 | out_impl_id: |
| 8524 | kfree(calldata->res.impl_id); |
| 8525 | out_server_scope: |
| 8526 | kfree(calldata->res.server_scope); |
| 8527 | out_server_owner: |
| 8528 | kfree(calldata->res.server_owner); |
| 8529 | out_calldata: |
| 8530 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8531 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8532 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8533 | return ERR_PTR(status); |
| 8534 | } |
| 8535 | |
| 8536 | /* |
| 8537 | * _nfs4_proc_exchange_id() |
| 8538 | * |
| 8539 | * Wrapper for EXCHANGE_ID operation. |
| 8540 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8541 | 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] | 8542 | u32 sp4_how) |
| 8543 | { |
| 8544 | struct rpc_task *task; |
| 8545 | struct nfs41_exchange_id_args *argp; |
| 8546 | struct nfs41_exchange_id_res *resp; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8547 | unsigned long now = jiffies; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8548 | int status; |
| 8549 | |
| 8550 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8551 | if (IS_ERR(task)) |
| 8552 | return PTR_ERR(task); |
| 8553 | |
| 8554 | argp = task->tk_msg.rpc_argp; |
| 8555 | resp = task->tk_msg.rpc_resp; |
| 8556 | status = task->tk_status; |
| 8557 | if (status != 0) |
| 8558 | goto out; |
| 8559 | |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8560 | status = nfs4_check_cl_exchange_flags(resp->flags, |
| 8561 | clp->cl_mvops->minor_version); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8562 | if (status != 0) |
| 8563 | goto out; |
| 8564 | |
| 8565 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8566 | if (status != 0) |
| 8567 | goto out; |
| 8568 | |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8569 | do_renew_lease(clp, now); |
| 8570 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8571 | clp->cl_clientid = resp->clientid; |
| 8572 | clp->cl_exchange_flags = resp->flags; |
| 8573 | clp->cl_seqid = resp->seqid; |
| 8574 | /* Client ID is not confirmed */ |
| 8575 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8576 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8577 | &clp->cl_session->session_state); |
| 8578 | |
| 8579 | if (clp->cl_serverscope != NULL && |
| 8580 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8581 | resp->server_scope)) { |
| 8582 | dprintk("%s: server_scope mismatch detected\n", |
| 8583 | __func__); |
| 8584 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8585 | } |
| 8586 | |
| 8587 | swap(clp->cl_serverowner, resp->server_owner); |
| 8588 | swap(clp->cl_serverscope, resp->server_scope); |
| 8589 | swap(clp->cl_implid, resp->impl_id); |
| 8590 | |
| 8591 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8592 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8593 | sizeof(clp->cl_confirm.data)); |
| 8594 | out: |
| 8595 | trace_nfs4_exchange_id(clp, status); |
| 8596 | rpc_put_task(task); |
| 8597 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8598 | } |
| 8599 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8600 | /* |
| 8601 | * nfs4_proc_exchange_id() |
| 8602 | * |
| 8603 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8604 | * |
| 8605 | * Since the clientid has expired, all compounds using sessions |
| 8606 | * associated with the stale clientid will be returning |
| 8607 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8608 | * be in some phase of session reset. |
| 8609 | * |
| 8610 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8611 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8612 | 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] | 8613 | { |
| 8614 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8615 | int status; |
| 8616 | |
| 8617 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8618 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8619 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8620 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8621 | if (!status) |
| 8622 | return 0; |
| 8623 | } |
| 8624 | |
| 8625 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8626 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8627 | } |
| 8628 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8629 | /** |
| 8630 | * nfs4_test_session_trunk |
| 8631 | * |
| 8632 | * This is an add_xprt_test() test function called from |
| 8633 | * rpc_clnt_setup_test_and_add_xprt. |
| 8634 | * |
| 8635 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8636 | * and is dereferrenced in nfs4_exchange_id_release |
| 8637 | * |
| 8638 | * Upon success, add the new transport to the rpc_clnt |
| 8639 | * |
| 8640 | * @clnt: struct rpc_clnt to get new transport |
| 8641 | * @xprt: the rpc_xprt to test |
| 8642 | * @data: call data for _nfs4_proc_exchange_id. |
| 8643 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8644 | 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] | 8645 | void *data) |
| 8646 | { |
| 8647 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8648 | struct rpc_task *task; |
| 8649 | int status; |
| 8650 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8651 | u32 sp4_how; |
| 8652 | |
| 8653 | dprintk("--> %s try %s\n", __func__, |
| 8654 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8655 | |
| 8656 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8657 | |
| 8658 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8659 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8660 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8661 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8662 | |
| 8663 | status = task->tk_status; |
| 8664 | if (status == 0) |
| 8665 | status = nfs4_detect_session_trunking(adata->clp, |
| 8666 | task->tk_msg.rpc_resp, xprt); |
| 8667 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8668 | if (status == 0) |
| 8669 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8670 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8671 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8672 | } |
| 8673 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8674 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8675 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8676 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8677 | { |
| 8678 | struct rpc_message msg = { |
| 8679 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8680 | .rpc_argp = clp, |
| 8681 | .rpc_cred = cred, |
| 8682 | }; |
| 8683 | int status; |
| 8684 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8685 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8686 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8687 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8688 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8689 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8690 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8691 | return status; |
| 8692 | } |
| 8693 | |
| 8694 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8695 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8696 | { |
| 8697 | unsigned int loop; |
| 8698 | int ret; |
| 8699 | |
| 8700 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8701 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8702 | switch (ret) { |
| 8703 | case -NFS4ERR_DELAY: |
| 8704 | case -NFS4ERR_CLIENTID_BUSY: |
| 8705 | ssleep(1); |
| 8706 | break; |
| 8707 | default: |
| 8708 | return ret; |
| 8709 | } |
| 8710 | } |
| 8711 | return 0; |
| 8712 | } |
| 8713 | |
| 8714 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8715 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8716 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8717 | int ret = 0; |
| 8718 | |
| 8719 | if (clp->cl_mvops->minor_version < 1) |
| 8720 | goto out; |
| 8721 | if (clp->cl_exchange_flags == 0) |
| 8722 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8723 | if (clp->cl_preserve_clid) |
| 8724 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8725 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8726 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8727 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8728 | switch (ret) { |
| 8729 | case 0: |
| 8730 | case -NFS4ERR_STALE_CLIENTID: |
| 8731 | clp->cl_exchange_flags = 0; |
| 8732 | } |
| 8733 | out: |
| 8734 | return ret; |
| 8735 | } |
| 8736 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8737 | #endif /* CONFIG_NFS_V4_1 */ |
| 8738 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8739 | struct nfs4_get_lease_time_data { |
| 8740 | struct nfs4_get_lease_time_args *args; |
| 8741 | struct nfs4_get_lease_time_res *res; |
| 8742 | struct nfs_client *clp; |
| 8743 | }; |
| 8744 | |
| 8745 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8746 | void *calldata) |
| 8747 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8748 | struct nfs4_get_lease_time_data *data = |
| 8749 | (struct nfs4_get_lease_time_data *)calldata; |
| 8750 | |
| 8751 | dprintk("--> %s\n", __func__); |
| 8752 | /* just setup sequence, do not trigger session recovery |
| 8753 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8754 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8755 | &data->args->la_seq_args, |
| 8756 | &data->res->lr_seq_res, |
| 8757 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8758 | dprintk("<-- %s\n", __func__); |
| 8759 | } |
| 8760 | |
| 8761 | /* |
| 8762 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8763 | * from sequence operation or clientid errors. |
| 8764 | */ |
| 8765 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8766 | { |
| 8767 | struct nfs4_get_lease_time_data *data = |
| 8768 | (struct nfs4_get_lease_time_data *)calldata; |
| 8769 | |
| 8770 | dprintk("--> %s\n", __func__); |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8771 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8772 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8773 | switch (task->tk_status) { |
| 8774 | case -NFS4ERR_DELAY: |
| 8775 | case -NFS4ERR_GRACE: |
| 8776 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8777 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8778 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 8779 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8780 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8781 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8782 | return; |
| 8783 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8784 | dprintk("<-- %s\n", __func__); |
| 8785 | } |
| 8786 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8787 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8788 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8789 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8790 | }; |
| 8791 | |
| 8792 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8793 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8794 | struct nfs4_get_lease_time_args args; |
| 8795 | struct nfs4_get_lease_time_res res = { |
| 8796 | .lr_fsinfo = fsinfo, |
| 8797 | }; |
| 8798 | struct nfs4_get_lease_time_data data = { |
| 8799 | .args = &args, |
| 8800 | .res = &res, |
| 8801 | .clp = clp, |
| 8802 | }; |
| 8803 | struct rpc_message msg = { |
| 8804 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8805 | .rpc_argp = &args, |
| 8806 | .rpc_resp = &res, |
| 8807 | }; |
| 8808 | struct rpc_task_setup task_setup = { |
| 8809 | .rpc_client = clp->cl_rpcclient, |
| 8810 | .rpc_message = &msg, |
| 8811 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8812 | .callback_data = &data, |
| 8813 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8814 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8815 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8816 | 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] | 8817 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8818 | } |
| 8819 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8820 | #ifdef CONFIG_NFS_V4_1 |
| 8821 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8822 | /* |
| 8823 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8824 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8825 | * use them. |
| 8826 | * |
| 8827 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8828 | * always set csa_cachethis to FALSE because the current implementation |
| 8829 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8830 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8831 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8832 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8833 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8834 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8835 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8836 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8837 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8838 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8839 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8840 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8841 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8842 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8843 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8844 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8845 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8846 | |
| 8847 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8848 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8849 | __func__, |
| 8850 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8851 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8852 | |
| 8853 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8854 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8855 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8856 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8857 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8858 | 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] | 8859 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8860 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8861 | |
| 8862 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8863 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8864 | __func__, |
| 8865 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8866 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8867 | args->bc_attrs.max_reqs); |
| 8868 | } |
| 8869 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8870 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8871 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8872 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8873 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8874 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8875 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8876 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8877 | return -EINVAL; |
| 8878 | /* |
| 8879 | * Our requested max_ops is the minimum we need; we're not |
| 8880 | * prepared to break up compounds into smaller pieces than that. |
| 8881 | * So, no point even trying to continue if the server won't |
| 8882 | * cooperate: |
| 8883 | */ |
| 8884 | if (rcvd->max_ops < sent->max_ops) |
| 8885 | return -EINVAL; |
| 8886 | if (rcvd->max_reqs == 0) |
| 8887 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8888 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8889 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8890 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8891 | } |
| 8892 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8893 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8894 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8895 | { |
| 8896 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8897 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8898 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8899 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8900 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8901 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8902 | return -EINVAL; |
| 8903 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8904 | return -EINVAL; |
| 8905 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8906 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8907 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8908 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8909 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8910 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8911 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8912 | return 0; |
| 8913 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8914 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8915 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8916 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8917 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8918 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8919 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8920 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8921 | if (ret) |
| 8922 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8923 | return nfs4_verify_back_channel_attrs(args, res); |
| 8924 | } |
| 8925 | |
| 8926 | static void nfs4_update_session(struct nfs4_session *session, |
| 8927 | struct nfs41_create_session_res *res) |
| 8928 | { |
| 8929 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8930 | /* Mark client id and session as being confirmed */ |
| 8931 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8932 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8933 | session->flags = res->flags; |
| 8934 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8935 | if (res->flags & SESSION4_BACK_CHAN) |
| 8936 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8937 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8938 | } |
| 8939 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8940 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8941 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8942 | { |
| 8943 | struct nfs4_session *session = clp->cl_session; |
| 8944 | struct nfs41_create_session_args args = { |
| 8945 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8946 | .clientid = clp->cl_clientid, |
| 8947 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8948 | .cb_program = NFS4_CALLBACK, |
| 8949 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8950 | struct nfs41_create_session_res res; |
| 8951 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8952 | struct rpc_message msg = { |
| 8953 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8954 | .rpc_argp = &args, |
| 8955 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8956 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8957 | }; |
| 8958 | int status; |
| 8959 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8960 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8961 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8962 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8963 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8964 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8965 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8966 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8967 | switch (status) { |
| 8968 | case -NFS4ERR_STALE_CLIENTID: |
| 8969 | case -NFS4ERR_DELAY: |
| 8970 | case -ETIMEDOUT: |
| 8971 | case -EACCES: |
| 8972 | case -EAGAIN: |
| 8973 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 8974 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8975 | |
| 8976 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8977 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8978 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8979 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8980 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8981 | if (status) |
| 8982 | goto out; |
| 8983 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8984 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8985 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8986 | return status; |
| 8987 | } |
| 8988 | |
| 8989 | /* |
| 8990 | * Issues a CREATE_SESSION operation to the server. |
| 8991 | * It is the responsibility of the caller to verify the session is |
| 8992 | * expired before calling this routine. |
| 8993 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8994 | 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] | 8995 | { |
| 8996 | int status; |
| 8997 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8998 | struct nfs4_session *session = clp->cl_session; |
| 8999 | |
| 9000 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 9001 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9002 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9003 | if (status) |
| 9004 | goto out; |
| 9005 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 9006 | /* Init or reset the session slot tables */ |
| 9007 | status = nfs4_setup_session_slot_tables(session); |
| 9008 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9009 | if (status) |
| 9010 | goto out; |
| 9011 | |
| 9012 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 9013 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 9014 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9015 | out: |
| 9016 | dprintk("<-- %s\n", __func__); |
| 9017 | return status; |
| 9018 | } |
| 9019 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9020 | /* |
| 9021 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 9022 | * The caller must serialize access to this routine. |
| 9023 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9024 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9025 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9026 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9027 | struct rpc_message msg = { |
| 9028 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 9029 | .rpc_argp = session, |
| 9030 | .rpc_cred = cred, |
| 9031 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9032 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9033 | |
| 9034 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 9035 | |
| 9036 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 9037 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 9038 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9039 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9040 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9041 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9042 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9043 | |
| 9044 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 9045 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9046 | "Session has been destroyed regardless...\n", status); |
| 9047 | |
| 9048 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 9049 | return status; |
| 9050 | } |
| 9051 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 9052 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9053 | * Renew the cl_session lease. |
| 9054 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9055 | struct nfs4_sequence_data { |
| 9056 | struct nfs_client *clp; |
| 9057 | struct nfs4_sequence_args args; |
| 9058 | struct nfs4_sequence_res res; |
| 9059 | }; |
| 9060 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9061 | static void nfs41_sequence_release(void *data) |
| 9062 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9063 | struct nfs4_sequence_data *calldata = data; |
| 9064 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9065 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9066 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9067 | nfs4_schedule_state_renewal(clp); |
| 9068 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9069 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9070 | } |
| 9071 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9072 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9073 | { |
| 9074 | switch(task->tk_status) { |
| 9075 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9076 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 9077 | return -EAGAIN; |
| 9078 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9079 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9080 | } |
| 9081 | return 0; |
| 9082 | } |
| 9083 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9084 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9085 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9086 | struct nfs4_sequence_data *calldata = data; |
| 9087 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9088 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9089 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 9090 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9091 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9092 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9093 | if (task->tk_status < 0) { |
| 9094 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9095 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9096 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9097 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9098 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 9099 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9100 | return; |
| 9101 | } |
| 9102 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9103 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9104 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9105 | dprintk("<-- %s\n", __func__); |
| 9106 | } |
| 9107 | |
| 9108 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 9109 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9110 | struct nfs4_sequence_data *calldata = data; |
| 9111 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9112 | struct nfs4_sequence_args *args; |
| 9113 | struct nfs4_sequence_res *res; |
| 9114 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9115 | args = task->tk_msg.rpc_argp; |
| 9116 | res = task->tk_msg.rpc_resp; |
| 9117 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9118 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9119 | } |
| 9120 | |
| 9121 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 9122 | .rpc_call_done = nfs41_sequence_call_done, |
| 9123 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9124 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9125 | }; |
| 9126 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9127 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9128 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9129 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9130 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9131 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9132 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9133 | struct rpc_message msg = { |
| 9134 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 9135 | .rpc_cred = cred, |
| 9136 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9137 | struct rpc_task_setup task_setup_data = { |
| 9138 | .rpc_client = clp->cl_rpcclient, |
| 9139 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9140 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 9141 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9142 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9143 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9144 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9145 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9146 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9147 | goto out_err; |
| 9148 | |
| 9149 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 9150 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9151 | if (calldata == NULL) |
| 9152 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9153 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9154 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9155 | msg.rpc_argp = &calldata->args; |
| 9156 | msg.rpc_resp = &calldata->res; |
| 9157 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9158 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9159 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9160 | ret = rpc_run_task(&task_setup_data); |
| 9161 | if (IS_ERR(ret)) |
| 9162 | goto out_err; |
| 9163 | return ret; |
| 9164 | out_put_clp: |
| 9165 | nfs_put_client(clp); |
| 9166 | out_err: |
| 9167 | nfs41_release_slot(slot); |
| 9168 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9169 | } |
| 9170 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9171 | 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] | 9172 | { |
| 9173 | struct rpc_task *task; |
| 9174 | int ret = 0; |
| 9175 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 9176 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 9177 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9178 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9179 | if (IS_ERR(task)) |
| 9180 | ret = PTR_ERR(task); |
| 9181 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 9182 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9183 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9184 | return ret; |
| 9185 | } |
| 9186 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9187 | 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] | 9188 | { |
| 9189 | struct rpc_task *task; |
| 9190 | int ret; |
| 9191 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9192 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9193 | if (IS_ERR(task)) { |
| 9194 | ret = PTR_ERR(task); |
| 9195 | goto out; |
| 9196 | } |
| 9197 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 9198 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9199 | ret = task->tk_status; |
| 9200 | rpc_put_task(task); |
| 9201 | out: |
| 9202 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9203 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9204 | } |
| 9205 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9206 | struct nfs4_reclaim_complete_data { |
| 9207 | struct nfs_client *clp; |
| 9208 | struct nfs41_reclaim_complete_args arg; |
| 9209 | struct nfs41_reclaim_complete_res res; |
| 9210 | }; |
| 9211 | |
| 9212 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 9213 | { |
| 9214 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9215 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9216 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9217 | &calldata->arg.seq_args, |
| 9218 | &calldata->res.seq_res, |
| 9219 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9220 | } |
| 9221 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9222 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9223 | { |
| 9224 | switch(task->tk_status) { |
| 9225 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 9226 | wake_up_all(&clp->cl_lock_waitq); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9227 | fallthrough; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9228 | case -NFS4ERR_COMPLETE_ALREADY: |
| 9229 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 9230 | break; |
| 9231 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9232 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9233 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 9234 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9235 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9236 | case -NFS4ERR_BADSESSION: |
| 9237 | case -NFS4ERR_DEADSESSION: |
| 9238 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9239 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9240 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9241 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9242 | } |
| 9243 | return 0; |
| 9244 | } |
| 9245 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9246 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 9247 | { |
| 9248 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9249 | struct nfs_client *clp = calldata->clp; |
| 9250 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 9251 | |
| 9252 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9253 | if (!nfs41_sequence_done(task, res)) |
| 9254 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9255 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9256 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9257 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 9258 | rpc_restart_call_prepare(task); |
| 9259 | return; |
| 9260 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9261 | dprintk("<-- %s\n", __func__); |
| 9262 | } |
| 9263 | |
| 9264 | static void nfs4_free_reclaim_complete_data(void *data) |
| 9265 | { |
| 9266 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9267 | |
| 9268 | kfree(calldata); |
| 9269 | } |
| 9270 | |
| 9271 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 9272 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 9273 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 9274 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 9275 | }; |
| 9276 | |
| 9277 | /* |
| 9278 | * Issue a global reclaim complete. |
| 9279 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9280 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9281 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9282 | { |
| 9283 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9284 | struct rpc_message msg = { |
| 9285 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9286 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9287 | }; |
| 9288 | struct rpc_task_setup task_setup_data = { |
| 9289 | .rpc_client = clp->cl_rpcclient, |
| 9290 | .rpc_message = &msg, |
| 9291 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9292 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9293 | }; |
| 9294 | int status = -ENOMEM; |
| 9295 | |
| 9296 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 9297 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9298 | if (calldata == NULL) |
| 9299 | goto out; |
| 9300 | calldata->clp = clp; |
| 9301 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9302 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9303 | 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] | 9304 | msg.rpc_argp = &calldata->arg; |
| 9305 | msg.rpc_resp = &calldata->res; |
| 9306 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9307 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9308 | out: |
| 9309 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9310 | return status; |
| 9311 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9312 | |
| 9313 | static void |
| 9314 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9315 | { |
| 9316 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9317 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9318 | |
| 9319 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9320 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9321 | &lgp->res.seq_res, task); |
| 9322 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9323 | } |
| 9324 | |
| 9325 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9326 | { |
| 9327 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9328 | |
| 9329 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9330 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9331 | dprintk("<-- %s\n", __func__); |
| 9332 | } |
| 9333 | |
| 9334 | static int |
| 9335 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9336 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9337 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9338 | struct inode *inode = lgp->args.inode; |
| 9339 | struct nfs_server *server = NFS_SERVER(inode); |
| 9340 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9341 | int nfs4err = task->tk_status; |
| 9342 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9343 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9344 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9345 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9346 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9347 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9348 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9349 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9350 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9351 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9352 | |
| 9353 | /* |
| 9354 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9355 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9356 | * retry go inband. |
| 9357 | */ |
| 9358 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9359 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9360 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9361 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9362 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9363 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9364 | */ |
| 9365 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9366 | status = -EOVERFLOW; |
| 9367 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9368 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9369 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9370 | * (or clients) writing to the same RAID stripe except when |
| 9371 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9372 | * |
| 9373 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9374 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9375 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9376 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9377 | if (lgp->args.minlength == 0) { |
| 9378 | status = -EOVERFLOW; |
| 9379 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9380 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9381 | status = -EBUSY; |
| 9382 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9383 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9384 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9385 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9386 | case -NFS4ERR_DELEG_REVOKED: |
| 9387 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9388 | case -NFS4ERR_EXPIRED: |
| 9389 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9390 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9391 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9392 | lo = NFS_I(inode)->layout; |
| 9393 | /* If the open stateid was bad, then recover it. */ |
| 9394 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9395 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9396 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9397 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9398 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9399 | break; |
| 9400 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9401 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9402 | /* |
| 9403 | * Mark the bad layout state as invalid, then retry |
| 9404 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9405 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9406 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9407 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9408 | pnfs_free_lseg_list(&head); |
| 9409 | status = -EAGAIN; |
| 9410 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9411 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9412 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9413 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9414 | if (!status) { |
| 9415 | if (exception->retry) |
| 9416 | status = -EAGAIN; |
| 9417 | else |
| 9418 | status = err; |
| 9419 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9420 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9421 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9422 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9423 | } |
| 9424 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9425 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9426 | { |
| 9427 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9428 | return nfs_page_array_len(0, max_resp_sz); |
| 9429 | } |
| 9430 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9431 | static void nfs4_layoutget_release(void *calldata) |
| 9432 | { |
| 9433 | struct nfs4_layoutget *lgp = calldata; |
| 9434 | |
| 9435 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9436 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9437 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9438 | dprintk("<-- %s\n", __func__); |
| 9439 | } |
| 9440 | |
| 9441 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9442 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9443 | .rpc_call_done = nfs4_layoutget_done, |
| 9444 | .rpc_release = nfs4_layoutget_release, |
| 9445 | }; |
| 9446 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9447 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9448 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9449 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9450 | struct inode *inode = lgp->args.inode; |
| 9451 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9452 | struct rpc_task *task; |
| 9453 | struct rpc_message msg = { |
| 9454 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9455 | .rpc_argp = &lgp->args, |
| 9456 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9457 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9458 | }; |
| 9459 | struct rpc_task_setup task_setup_data = { |
| 9460 | .rpc_client = server->client, |
| 9461 | .rpc_message = &msg, |
| 9462 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9463 | .callback_data = lgp, |
Trond Myklebust | 63ec2b6 | 2020-02-07 19:40:14 -0500 | [diff] [blame] | 9464 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9465 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9466 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9467 | struct nfs4_exception exception = { |
| 9468 | .inode = inode, |
| 9469 | .timeout = *timeout, |
| 9470 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9471 | int status = 0; |
| 9472 | |
| 9473 | dprintk("--> %s\n", __func__); |
| 9474 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 9475 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 9476 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 9477 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9478 | 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] | 9479 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9480 | task = rpc_run_task(&task_setup_data); |
Xiyu Yang | 6e47666 | 2020-04-25 21:04:40 +0800 | [diff] [blame] | 9481 | |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9482 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9483 | if (status != 0) |
| 9484 | goto out; |
| 9485 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9486 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9487 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9488 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9489 | } else if (lgp->res.layoutp->len == 0) { |
| 9490 | status = -EAGAIN; |
| 9491 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9492 | } else |
| 9493 | lseg = pnfs_layout_process(lgp); |
| 9494 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9495 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9496 | &lgp->args.range, |
| 9497 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9498 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9499 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9500 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9501 | rpc_put_task(task); |
| 9502 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9503 | if (status) |
| 9504 | return ERR_PTR(status); |
| 9505 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9506 | } |
| 9507 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9508 | static void |
| 9509 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9510 | { |
| 9511 | struct nfs4_layoutreturn *lrp = calldata; |
| 9512 | |
| 9513 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9514 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9515 | &lrp->args.seq_args, |
| 9516 | &lrp->res.seq_res, |
| 9517 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9518 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9519 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9520 | } |
| 9521 | |
| 9522 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9523 | { |
| 9524 | struct nfs4_layoutreturn *lrp = calldata; |
| 9525 | struct nfs_server *server; |
| 9526 | |
| 9527 | dprintk("--> %s\n", __func__); |
| 9528 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9529 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9530 | return; |
| 9531 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9532 | /* |
| 9533 | * Was there an RPC level error? Assume the call succeeded, |
| 9534 | * and that we need to release the layout |
| 9535 | */ |
| 9536 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9537 | lrp->res.lrs_present = 0; |
| 9538 | return; |
| 9539 | } |
| 9540 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9541 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9542 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9543 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9544 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9545 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9546 | lrp->args.inode)) |
| 9547 | goto out_restart; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9548 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9549 | default: |
| 9550 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9551 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9552 | case 0: |
| 9553 | break; |
| 9554 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9555 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9556 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9557 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9558 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9559 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9560 | return; |
| 9561 | out_restart: |
| 9562 | task->tk_status = 0; |
| 9563 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9564 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9565 | } |
| 9566 | |
| 9567 | static void nfs4_layoutreturn_release(void *calldata) |
| 9568 | { |
| 9569 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9570 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9571 | |
| 9572 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9573 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9574 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9575 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9576 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9577 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9578 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9579 | nfs_iput_and_deactive(lrp->inode); |
Trond Myklebust | 44ea8df | 2020-04-02 15:37:02 -0400 | [diff] [blame] | 9580 | put_cred(lrp->cred); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9581 | kfree(calldata); |
| 9582 | dprintk("<-- %s\n", __func__); |
| 9583 | } |
| 9584 | |
| 9585 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9586 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9587 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9588 | .rpc_release = nfs4_layoutreturn_release, |
| 9589 | }; |
| 9590 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9591 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9592 | { |
| 9593 | struct rpc_task *task; |
| 9594 | struct rpc_message msg = { |
| 9595 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9596 | .rpc_argp = &lrp->args, |
| 9597 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9598 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9599 | }; |
| 9600 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9601 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9602 | .rpc_message = &msg, |
| 9603 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9604 | .callback_data = lrp, |
| 9605 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9606 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9607 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9608 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9609 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9610 | &task_setup_data.rpc_client, &msg); |
| 9611 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9612 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9613 | if (!sync) { |
| 9614 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 9615 | if (!lrp->inode) { |
| 9616 | nfs4_layoutreturn_release(lrp); |
| 9617 | return -EAGAIN; |
| 9618 | } |
| 9619 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9620 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9621 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9622 | task = rpc_run_task(&task_setup_data); |
| 9623 | if (IS_ERR(task)) |
| 9624 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9625 | if (sync) |
| 9626 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9627 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9628 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9629 | rpc_put_task(task); |
| 9630 | return status; |
| 9631 | } |
| 9632 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9633 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9634 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9635 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9636 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9637 | { |
| 9638 | struct nfs4_getdeviceinfo_args args = { |
| 9639 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9640 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9641 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9642 | }; |
| 9643 | struct nfs4_getdeviceinfo_res res = { |
| 9644 | .pdev = pdev, |
| 9645 | }; |
| 9646 | struct rpc_message msg = { |
| 9647 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9648 | .rpc_argp = &args, |
| 9649 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9650 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9651 | }; |
| 9652 | int status; |
| 9653 | |
| 9654 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9655 | 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] | 9656 | if (res.notification & ~args.notify_types) |
| 9657 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9658 | if (res.notification != args.notify_types) |
| 9659 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9660 | |
Trond Myklebust | cac1d3a | 2020-12-16 16:31:26 -0500 | [diff] [blame] | 9661 | trace_nfs4_getdeviceinfo(server, &pdev->dev_id, status); |
| 9662 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9663 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9664 | |
| 9665 | return status; |
| 9666 | } |
| 9667 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9668 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9669 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9670 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9671 | { |
| 9672 | struct nfs4_exception exception = { }; |
| 9673 | int err; |
| 9674 | |
| 9675 | do { |
| 9676 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9677 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9678 | &exception); |
| 9679 | } while (exception.retry); |
| 9680 | return err; |
| 9681 | } |
| 9682 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9683 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9684 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9685 | { |
| 9686 | struct nfs4_layoutcommit_data *data = calldata; |
| 9687 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9688 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9689 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9690 | &data->args.seq_args, |
| 9691 | &data->res.seq_res, |
| 9692 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9693 | } |
| 9694 | |
| 9695 | static void |
| 9696 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9697 | { |
| 9698 | struct nfs4_layoutcommit_data *data = calldata; |
| 9699 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9700 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9701 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9702 | return; |
| 9703 | |
| 9704 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9705 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9706 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9707 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9708 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9709 | task->tk_status = 0; |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame] | 9710 | break; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9711 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9712 | break; |
| 9713 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9714 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9715 | rpc_restart_call_prepare(task); |
| 9716 | return; |
| 9717 | } |
| 9718 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9719 | } |
| 9720 | |
| 9721 | static void nfs4_layoutcommit_release(void *calldata) |
| 9722 | { |
| 9723 | struct nfs4_layoutcommit_data *data = calldata; |
| 9724 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9725 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9726 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9727 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9728 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9729 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9730 | kfree(data); |
| 9731 | } |
| 9732 | |
| 9733 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9734 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9735 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9736 | .rpc_release = nfs4_layoutcommit_release, |
| 9737 | }; |
| 9738 | |
| 9739 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9740 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9741 | { |
| 9742 | struct rpc_message msg = { |
| 9743 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9744 | .rpc_argp = &data->args, |
| 9745 | .rpc_resp = &data->res, |
| 9746 | .rpc_cred = data->cred, |
| 9747 | }; |
| 9748 | struct rpc_task_setup task_setup_data = { |
| 9749 | .task = &data->task, |
| 9750 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9751 | .rpc_message = &msg, |
| 9752 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9753 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9754 | }; |
| 9755 | struct rpc_task *task; |
| 9756 | int status = 0; |
| 9757 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9758 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9759 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9760 | data->args.lastbytewritten, |
| 9761 | data->args.inode->i_ino); |
| 9762 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9763 | if (!sync) { |
| 9764 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9765 | if (data->inode == NULL) { |
| 9766 | nfs4_layoutcommit_release(data); |
| 9767 | return -EAGAIN; |
| 9768 | } |
| 9769 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9770 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9771 | 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] | 9772 | task = rpc_run_task(&task_setup_data); |
| 9773 | if (IS_ERR(task)) |
| 9774 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9775 | if (sync) |
| 9776 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9777 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9778 | dprintk("%s: status %d\n", __func__, status); |
| 9779 | rpc_put_task(task); |
| 9780 | return status; |
| 9781 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9782 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9783 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9784 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9785 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9786 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9787 | static int |
| 9788 | _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] | 9789 | struct nfs_fsinfo *info, |
| 9790 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9791 | { |
| 9792 | struct nfs41_secinfo_no_name_args args = { |
| 9793 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9794 | }; |
| 9795 | struct nfs4_secinfo_res res = { |
| 9796 | .flavors = flavors, |
| 9797 | }; |
| 9798 | struct rpc_message msg = { |
| 9799 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9800 | .rpc_argp = &args, |
| 9801 | .rpc_resp = &res, |
| 9802 | }; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9803 | struct nfs4_call_sync_data data = { |
| 9804 | .seq_server = server, |
| 9805 | .seq_args = &args.seq_args, |
| 9806 | .seq_res = &res.seq_res, |
| 9807 | }; |
| 9808 | struct rpc_task_setup task_setup = { |
| 9809 | .rpc_client = server->client, |
| 9810 | .rpc_message = &msg, |
| 9811 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9812 | .callback_data = &data, |
| 9813 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9814 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9815 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9816 | int status; |
| 9817 | |
| 9818 | if (use_integrity) { |
Colin Ian King | 48bb6ec | 2020-06-10 00:22:57 +0100 | [diff] [blame] | 9819 | task_setup.rpc_client = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9820 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9821 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9822 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9823 | } |
| 9824 | |
| 9825 | dprintk("--> %s\n", __func__); |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9826 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9827 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9828 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9829 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9830 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9831 | |
| 9832 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9833 | } |
| 9834 | |
| 9835 | static int |
| 9836 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9837 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9838 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9839 | struct nfs4_exception exception = { |
| 9840 | .interruptible = true, |
| 9841 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9842 | int err; |
| 9843 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9844 | /* first try using integrity protection */ |
| 9845 | err = -NFS4ERR_WRONGSEC; |
| 9846 | |
| 9847 | /* try to use integrity protection with machine cred */ |
| 9848 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9849 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9850 | flavors, true); |
| 9851 | |
| 9852 | /* |
| 9853 | * if unable to use integrity protection, or SECINFO with |
| 9854 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9855 | * disallowed by spec, but exists in deployed servers) use |
| 9856 | * the current filesystem's rpc_client and the user cred. |
| 9857 | */ |
| 9858 | if (err == -NFS4ERR_WRONGSEC) |
| 9859 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9860 | flavors, false); |
| 9861 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9862 | switch (err) { |
| 9863 | case 0: |
| 9864 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9865 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9866 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9867 | default: |
| 9868 | err = nfs4_handle_exception(server, err, &exception); |
| 9869 | } |
| 9870 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9871 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9872 | return err; |
| 9873 | } |
| 9874 | |
| 9875 | static int |
| 9876 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9877 | struct nfs_fsinfo *info) |
| 9878 | { |
| 9879 | int err; |
| 9880 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9881 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9882 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9883 | struct nfs4_secinfo4 *secinfo; |
| 9884 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9885 | |
| 9886 | page = alloc_page(GFP_KERNEL); |
| 9887 | if (!page) { |
| 9888 | err = -ENOMEM; |
| 9889 | goto out; |
| 9890 | } |
| 9891 | |
| 9892 | flavors = page_address(page); |
| 9893 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9894 | |
| 9895 | /* |
| 9896 | * Fall back on "guess and check" method if |
| 9897 | * the server doesn't support SECINFO_NO_NAME |
| 9898 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9899 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9900 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9901 | goto out_freepage; |
| 9902 | } |
| 9903 | if (err) |
| 9904 | goto out_freepage; |
| 9905 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9906 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9907 | secinfo = &flavors->flavors[i]; |
| 9908 | |
| 9909 | switch (secinfo->flavor) { |
| 9910 | case RPC_AUTH_NULL: |
| 9911 | case RPC_AUTH_UNIX: |
| 9912 | case RPC_AUTH_GSS: |
| 9913 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9914 | &secinfo->flavor_info); |
| 9915 | break; |
| 9916 | default: |
| 9917 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9918 | break; |
| 9919 | } |
| 9920 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9921 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9922 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9923 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9924 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9925 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9926 | info, flavor); |
| 9927 | if (!err) |
| 9928 | break; |
| 9929 | } |
| 9930 | } |
| 9931 | |
| 9932 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9933 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9934 | |
| 9935 | out_freepage: |
| 9936 | put_page(page); |
| 9937 | if (err == -EACCES) |
| 9938 | return -EPERM; |
| 9939 | out: |
| 9940 | return err; |
| 9941 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9942 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9943 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9944 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9945 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9946 | { |
| 9947 | int status; |
| 9948 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9949 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9950 | }; |
| 9951 | struct nfs41_test_stateid_res res; |
| 9952 | struct rpc_message msg = { |
| 9953 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9954 | .rpc_argp = &args, |
| 9955 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9956 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9957 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9958 | struct rpc_clnt *rpc_client = server->client; |
| 9959 | |
| 9960 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9961 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9962 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9963 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9964 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9965 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9966 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9967 | if (status != NFS_OK) { |
| 9968 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9969 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9970 | } |
| 9971 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9972 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9973 | } |
| 9974 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9975 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9976 | int err, struct nfs4_exception *exception) |
| 9977 | { |
| 9978 | exception->retry = 0; |
| 9979 | switch(err) { |
| 9980 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9981 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9982 | nfs4_handle_exception(server, err, exception); |
| 9983 | break; |
| 9984 | case -NFS4ERR_BADSESSION: |
| 9985 | case -NFS4ERR_BADSLOT: |
| 9986 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9987 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9988 | case -NFS4ERR_DEADSESSION: |
| 9989 | nfs4_do_handle_exception(server, err, exception); |
| 9990 | } |
| 9991 | } |
| 9992 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9993 | /** |
| 9994 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9995 | * |
| 9996 | * @server: server / transport on which to perform the operation |
| 9997 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9998 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9999 | * |
| 10000 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 10001 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 10002 | * failed or the state ID is not currently valid. |
| 10003 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10004 | static int nfs41_test_stateid(struct nfs_server *server, |
| 10005 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10006 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10007 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 10008 | struct nfs4_exception exception = { |
| 10009 | .interruptible = true, |
| 10010 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10011 | int err; |
| 10012 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10013 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10014 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10015 | } while (exception.retry); |
| 10016 | return err; |
| 10017 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10018 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10019 | struct nfs_free_stateid_data { |
| 10020 | struct nfs_server *server; |
| 10021 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10022 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10023 | }; |
| 10024 | |
| 10025 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 10026 | { |
| 10027 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 10028 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10029 | &data->args.seq_args, |
| 10030 | &data->res.seq_res, |
| 10031 | task); |
| 10032 | } |
| 10033 | |
| 10034 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 10035 | { |
| 10036 | struct nfs_free_stateid_data *data = calldata; |
| 10037 | |
| 10038 | nfs41_sequence_done(task, &data->res.seq_res); |
| 10039 | |
| 10040 | switch (task->tk_status) { |
| 10041 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 10042 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10043 | rpc_restart_call_prepare(task); |
| 10044 | } |
| 10045 | } |
| 10046 | |
| 10047 | static void nfs41_free_stateid_release(void *calldata) |
| 10048 | { |
| 10049 | kfree(calldata); |
| 10050 | } |
| 10051 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10052 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10053 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 10054 | .rpc_call_done = nfs41_free_stateid_done, |
| 10055 | .rpc_release = nfs41_free_stateid_release, |
| 10056 | }; |
| 10057 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10058 | /** |
| 10059 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 10060 | * |
| 10061 | * @server: server / transport on which to perform the operation |
| 10062 | * @stateid: state ID to release |
| 10063 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 10064 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10065 | * |
| 10066 | * Note: this function is always asynchronous. |
| 10067 | */ |
| 10068 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10069 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10070 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10071 | bool privileged) |
| 10072 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10073 | struct rpc_message msg = { |
| 10074 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10075 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10076 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10077 | struct rpc_task_setup task_setup = { |
| 10078 | .rpc_client = server->client, |
| 10079 | .rpc_message = &msg, |
| 10080 | .callback_ops = &nfs41_free_stateid_ops, |
| 10081 | .flags = RPC_TASK_ASYNC, |
| 10082 | }; |
| 10083 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10084 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10085 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10086 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 10087 | &task_setup.rpc_client, &msg); |
| 10088 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10089 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10090 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 10091 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10092 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10093 | data->server = server; |
| 10094 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 10095 | |
| 10096 | task_setup.callback_data = data; |
| 10097 | |
| 10098 | msg.rpc_argp = &data->args; |
| 10099 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10100 | 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] | 10101 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10102 | if (IS_ERR(task)) |
| 10103 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10104 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10105 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10106 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10107 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 10108 | static void |
| 10109 | 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] | 10110 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10111 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10112 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10113 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10114 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10115 | } |
| 10116 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10117 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 10118 | const nfs4_stateid *s2) |
| 10119 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 10120 | if (s1->type != s2->type) |
| 10121 | return false; |
| 10122 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10123 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10124 | return false; |
| 10125 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10126 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10127 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10128 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 10129 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10130 | } |
| 10131 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 10132 | #endif /* CONFIG_NFS_V4_1 */ |
| 10133 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10134 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 10135 | const nfs4_stateid *s2) |
| 10136 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10137 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10138 | } |
| 10139 | |
| 10140 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10141 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10142 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10143 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10144 | .recover_open = nfs4_open_reclaim, |
| 10145 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10146 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10147 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10148 | }; |
| 10149 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10150 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10151 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10152 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 10153 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 10154 | .recover_open = nfs4_open_reclaim, |
| 10155 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10156 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 10157 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10158 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10159 | }; |
| 10160 | #endif /* CONFIG_NFS_V4_1 */ |
| 10161 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10162 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10163 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10164 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 10165 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10166 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10167 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10168 | }; |
| 10169 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10170 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10171 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10172 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 10173 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 10174 | .recover_open = nfs41_open_expired, |
| 10175 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10176 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10177 | }; |
| 10178 | #endif /* CONFIG_NFS_V4_1 */ |
| 10179 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10180 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10181 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10182 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10183 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10184 | }; |
| 10185 | |
| 10186 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10187 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10188 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10189 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10190 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10191 | }; |
| 10192 | #endif |
| 10193 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10194 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10195 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10196 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10197 | }; |
| 10198 | |
| 10199 | #if defined(CONFIG_NFS_V4_1) |
| 10200 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10201 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10202 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10203 | }; |
| 10204 | #endif /* CONFIG_NFS_V4_1 */ |
| 10205 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10206 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 10207 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10208 | .init_caps = NFS_CAP_READDIRPLUS |
| 10209 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10210 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10211 | .init_client = nfs40_init_client, |
| 10212 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10213 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10214 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10215 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10216 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10217 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10218 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10219 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 10220 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 10221 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10222 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10223 | }; |
| 10224 | |
| 10225 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10226 | static struct nfs_seqid * |
| 10227 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 10228 | { |
| 10229 | return NULL; |
| 10230 | } |
| 10231 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10232 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 10233 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10234 | .init_caps = NFS_CAP_READDIRPLUS |
| 10235 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 10236 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 10237 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10238 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 10239 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10240 | .init_client = nfs41_init_client, |
| 10241 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10242 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10243 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10244 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10245 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10246 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10247 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10248 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10249 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10250 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10251 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10252 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10253 | }; |
| 10254 | #endif |
| 10255 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10256 | #if defined(CONFIG_NFS_V4_2) |
| 10257 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 10258 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10259 | .init_caps = NFS_CAP_READDIRPLUS |
| 10260 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10261 | | NFS_CAP_POSIX_LOCK |
| 10262 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 10263 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10264 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 10265 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 10266 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 10267 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 10268 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 10269 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 10270 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 10271 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 10272 | | NFS_CAP_CLONE |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 10273 | | NFS_CAP_LAYOUTERROR |
| 10274 | | NFS_CAP_READ_PLUS, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10275 | .init_client = nfs41_init_client, |
| 10276 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10277 | .match_stateid = nfs41_match_stateid, |
| 10278 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10279 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10280 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10281 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10282 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10283 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10284 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10285 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10286 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 10287 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10288 | }; |
| 10289 | #endif |
| 10290 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10291 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 10292 | [0] = &nfs_v4_0_minor_ops, |
| 10293 | #if defined(CONFIG_NFS_V4_1) |
| 10294 | [1] = &nfs_v4_1_minor_ops, |
| 10295 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10296 | #if defined(CONFIG_NFS_V4_2) |
| 10297 | [2] = &nfs_v4_2_minor_ops, |
| 10298 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10299 | }; |
| 10300 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 10301 | 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] | 10302 | { |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10303 | ssize_t error, error2, error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10304 | |
| 10305 | error = generic_listxattr(dentry, list, size); |
| 10306 | if (error < 0) |
| 10307 | return error; |
| 10308 | if (list) { |
| 10309 | list += error; |
| 10310 | size -= error; |
| 10311 | } |
| 10312 | |
| 10313 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10314 | if (error2 < 0) |
| 10315 | return error2; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10316 | |
| 10317 | if (list) { |
| 10318 | list += error2; |
| 10319 | size -= error2; |
| 10320 | } |
| 10321 | |
| 10322 | error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); |
| 10323 | if (error3 < 0) |
| 10324 | return error3; |
| 10325 | |
| 10326 | return error + error2 + error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10327 | } |
| 10328 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10329 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10330 | .create = nfs_create, |
| 10331 | .lookup = nfs_lookup, |
| 10332 | .atomic_open = nfs_atomic_open, |
| 10333 | .link = nfs_link, |
| 10334 | .unlink = nfs_unlink, |
| 10335 | .symlink = nfs_symlink, |
| 10336 | .mkdir = nfs_mkdir, |
| 10337 | .rmdir = nfs_rmdir, |
| 10338 | .mknod = nfs_mknod, |
| 10339 | .rename = nfs_rename, |
| 10340 | .permission = nfs_permission, |
| 10341 | .getattr = nfs_getattr, |
| 10342 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10343 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10344 | }; |
| 10345 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10346 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10347 | .permission = nfs_permission, |
| 10348 | .getattr = nfs_getattr, |
| 10349 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10350 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10351 | }; |
| 10352 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10353 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10354 | .version = 4, /* protocol version */ |
| 10355 | .dentry_ops = &nfs4_dentry_operations, |
| 10356 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10357 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10358 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10359 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10360 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10361 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10362 | .getattr = nfs4_proc_getattr, |
| 10363 | .setattr = nfs4_proc_setattr, |
| 10364 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10365 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10366 | .access = nfs4_proc_access, |
| 10367 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10368 | .create = nfs4_proc_create, |
| 10369 | .remove = nfs4_proc_remove, |
| 10370 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10371 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10372 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10373 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10374 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10375 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10376 | .link = nfs4_proc_link, |
| 10377 | .symlink = nfs4_proc_symlink, |
| 10378 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10379 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10380 | .readdir = nfs4_proc_readdir, |
| 10381 | .mknod = nfs4_proc_mknod, |
| 10382 | .statfs = nfs4_proc_statfs, |
| 10383 | .fsinfo = nfs4_proc_fsinfo, |
| 10384 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10385 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10386 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10387 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10388 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10389 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10390 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10391 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10392 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10393 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10394 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10395 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10396 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10397 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10398 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10399 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10400 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10401 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10402 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10403 | .create_server = nfs4_create_server, |
| 10404 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10405 | }; |
| 10406 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10407 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10408 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10409 | .list = nfs4_xattr_list_nfs4_acl, |
| 10410 | .get = nfs4_xattr_get_nfs4_acl, |
| 10411 | .set = nfs4_xattr_set_nfs4_acl, |
| 10412 | }; |
| 10413 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10414 | #ifdef CONFIG_NFS_V4_2 |
| 10415 | static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { |
| 10416 | .prefix = XATTR_USER_PREFIX, |
| 10417 | .get = nfs4_xattr_get_nfs4_user, |
| 10418 | .set = nfs4_xattr_set_nfs4_user, |
| 10419 | }; |
| 10420 | #endif |
| 10421 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10422 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10423 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10424 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10425 | &nfs4_xattr_nfs4_label_handler, |
| 10426 | #endif |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10427 | #ifdef CONFIG_NFS_V4_2 |
| 10428 | &nfs4_xattr_nfs4_user_handler, |
| 10429 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10430 | NULL |
| 10431 | }; |
| 10432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10433 | /* |
| 10434 | * Local variables: |
| 10435 | * c-basic-offset: 8 |
| 10436 | * End: |
| 10437 | */ |