Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 56 | #include <linux/freezer.h> |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 57 | #include <linux/iversion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 66 | #include "sysfs.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 67 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 68 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 69 | #include "fscache.h" |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 70 | #include "nfs42.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 72 | #include "nfs4trace.h" |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 75 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 76 | #define NFS4_BITMASK_SZ 3 |
| 77 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 78 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 80 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 81 | /* file attributes which can be mapped to nfs attributes */ |
| 82 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 83 | | ATTR_UID \ |
| 84 | | ATTR_GID \ |
| 85 | | ATTR_SIZE \ |
| 86 | | ATTR_ATIME \ |
| 87 | | ATTR_MTIME \ |
| 88 | | ATTR_CTIME \ |
| 89 | | ATTR_ATIME_SET \ |
| 90 | | ATTR_MTIME_SET) |
| 91 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 92 | struct nfs4_opendata; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 93 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 95 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 96 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 97 | struct nfs_fattr *fattr, struct inode *inode); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 98 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 99 | struct nfs_fattr *fattr, struct iattr *sattr, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 100 | struct nfs_open_context *ctx, struct nfs4_label *ilabel); |
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 |
Trond Myklebust | 7f08a33 | 2021-03-26 09:50:19 -0400 | [diff] [blame] | 267 | | FATTR4_WORD2_CHANGE_ATTR_TYPE |
Frank van der Linden | b78ef84 | 2020-06-23 22:38:55 +0000 | [diff] [blame] | 268 | | FATTR4_WORD2_XATTR_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | }; |
| 270 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 271 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 272 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 273 | | FATTR4_WORD0_SIZE |
| 274 | | FATTR4_WORD0_FSID |
| 275 | | FATTR4_WORD0_FILEID |
| 276 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 277 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 278 | | FATTR4_WORD1_OWNER_GROUP |
| 279 | | FATTR4_WORD1_RAWDEV |
| 280 | | FATTR4_WORD1_SPACE_USED |
| 281 | | FATTR4_WORD1_TIME_ACCESS |
| 282 | | FATTR4_WORD1_TIME_METADATA |
| 283 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 284 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 285 | }; |
| 286 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 287 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 288 | struct inode *inode, unsigned long flags) |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 289 | { |
| 290 | unsigned long cache_validity; |
| 291 | |
| 292 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 293 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 294 | return; |
| 295 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 296 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity) | flags; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 297 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 298 | /* Remove the attributes over which we have full control */ |
| 299 | dst[1] &= ~FATTR4_WORD1_RAWDEV; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 300 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 301 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 302 | |
| 303 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 304 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 305 | |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 306 | if (!(cache_validity & NFS_INO_INVALID_MODE)) |
| 307 | dst[1] &= ~FATTR4_WORD1_MODE; |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 308 | if (!(cache_validity & NFS_INO_INVALID_OTHER)) |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 309 | dst[1] &= ~(FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 312 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | struct nfs4_readdir_arg *readdir) |
| 314 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 315 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 316 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 319 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | readdir->cookie = 0; |
| 325 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 326 | if (cookie == 2) |
| 327 | return; |
| 328 | |
| 329 | /* |
| 330 | * NFSv4 servers do not return entries for '.' and '..' |
| 331 | * Therefore, we fake these entries here. We let '.' |
| 332 | * have cookie 0 and '..' have cookie 1. Note that |
| 333 | * when talking to the server, we always send cookie 0 |
| 334 | * instead of 1 or 2. |
| 335 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 336 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | if (cookie == 0) { |
| 339 | *p++ = xdr_one; /* next */ |
| 340 | *p++ = xdr_zero; /* cookie, first word */ |
| 341 | *p++ = xdr_one; /* cookie, second word */ |
| 342 | *p++ = xdr_one; /* entry len */ |
| 343 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 344 | p++; |
| 345 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 346 | *p++ = htonl(attrs); /* bitmap */ |
| 347 | *p++ = htonl(12); /* attribute buffer length */ |
| 348 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 349 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | *p++ = xdr_one; /* next */ |
| 353 | *p++ = xdr_zero; /* cookie, first word */ |
| 354 | *p++ = xdr_two; /* cookie, second word */ |
| 355 | *p++ = xdr_two; /* entry len */ |
| 356 | memcpy(p, "..\0\0", 4); /* entry */ |
| 357 | p++; |
| 358 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 359 | *p++ = htonl(attrs); /* bitmap */ |
| 360 | *p++ = htonl(12); /* attribute buffer length */ |
| 361 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 362 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
| 364 | readdir->pgbase = (char *)p - (char *)start; |
| 365 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 366 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 369 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 370 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 371 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 372 | { |
| 373 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 374 | |
| 375 | ops->test_and_free_expired(server, stateid, cred); |
| 376 | } |
| 377 | |
| 378 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 379 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 380 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 381 | { |
| 382 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 383 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 384 | } |
| 385 | |
| 386 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 387 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 388 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 389 | { |
| 390 | nfs4_stateid tmp; |
| 391 | |
| 392 | nfs4_stateid_copy(&tmp, stateid); |
| 393 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 394 | } |
| 395 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 396 | static long nfs4_update_delay(long *timeout) |
| 397 | { |
| 398 | long ret; |
| 399 | if (!timeout) |
| 400 | return NFS4_POLL_RETRY_MAX; |
| 401 | if (*timeout <= 0) |
| 402 | *timeout = NFS4_POLL_RETRY_MIN; |
| 403 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 404 | *timeout = NFS4_POLL_RETRY_MAX; |
| 405 | ret = *timeout; |
| 406 | *timeout <<= 1; |
| 407 | return ret; |
| 408 | } |
| 409 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 410 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 411 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 412 | might_sleep(); |
| 413 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 414 | freezable_schedule_timeout_killable_unsafe( |
| 415 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 416 | if (!__fatal_signal_pending(current)) |
| 417 | return 0; |
| 418 | return -EINTR; |
| 419 | } |
| 420 | |
| 421 | static int nfs4_delay_interruptible(long *timeout) |
| 422 | { |
| 423 | might_sleep(); |
| 424 | |
He Zhe | 59679d9 | 2020-07-06 17:52:24 +0800 | [diff] [blame] | 425 | freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 426 | if (!signal_pending(current)) |
| 427 | return 0; |
| 428 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 429 | } |
| 430 | |
| 431 | static int nfs4_delay(long *timeout, bool interruptible) |
| 432 | { |
| 433 | if (interruptible) |
| 434 | return nfs4_delay_interruptible(timeout); |
| 435 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 438 | static const nfs4_stateid * |
| 439 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 440 | { |
| 441 | if (!stateid) |
| 442 | return NULL; |
| 443 | switch (stateid->type) { |
| 444 | case NFS4_OPEN_STATEID_TYPE: |
| 445 | case NFS4_LOCK_STATEID_TYPE: |
| 446 | case NFS4_DELEGATION_STATEID_TYPE: |
| 447 | return stateid; |
| 448 | default: |
| 449 | break; |
| 450 | } |
| 451 | return NULL; |
| 452 | } |
| 453 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 454 | /* This is the error handling routine for processes that are allowed |
| 455 | * to sleep. |
| 456 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 457 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 458 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 459 | { |
| 460 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 461 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 462 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 463 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 464 | int ret = errorcode; |
| 465 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 466 | exception->delay = 0; |
| 467 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 468 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 469 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 470 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 471 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 472 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 473 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 474 | switch(errorcode) { |
| 475 | case 0: |
| 476 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 477 | case -NFS4ERR_BADHANDLE: |
| 478 | case -ESTALE: |
| 479 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 480 | pnfs_destroy_layout(NFS_I(inode)); |
| 481 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 482 | case -NFS4ERR_DELEG_REVOKED: |
| 483 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 484 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 485 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame] | 486 | case -NFS4ERR_PARTNER_NO_AUTH: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 487 | if (inode != NULL && stateid != NULL) { |
| 488 | nfs_inode_find_state_and_recover(inode, |
| 489 | stateid); |
| 490 | goto wait_on_recovery; |
| 491 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 492 | fallthrough; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 493 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 494 | if (inode) { |
| 495 | int err; |
| 496 | |
| 497 | err = nfs_async_inode_return_delegation(inode, |
| 498 | stateid); |
| 499 | if (err == 0) |
| 500 | goto wait_on_recovery; |
| 501 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 502 | exception->retry = 1; |
| 503 | break; |
| 504 | } |
| 505 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 506 | if (state == NULL) |
| 507 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 508 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 509 | if (ret < 0) |
| 510 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 511 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 512 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 513 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 514 | nfs4_schedule_lease_recovery(clp); |
| 515 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 516 | case -NFS4ERR_MOVED: |
| 517 | ret = nfs4_schedule_migration_recovery(server); |
| 518 | if (ret < 0) |
| 519 | break; |
| 520 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 521 | case -NFS4ERR_LEASE_MOVED: |
| 522 | nfs4_schedule_lease_moved_recovery(clp); |
| 523 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 524 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 525 | case -NFS4ERR_BADSESSION: |
| 526 | case -NFS4ERR_BADSLOT: |
| 527 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 528 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 529 | case -NFS4ERR_DEADSESSION: |
| 530 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 531 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 532 | /* Handled in nfs41_sequence_process() */ |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 533 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 534 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 535 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 536 | if (exception->timeout > HZ) { |
| 537 | /* We have retried a decent amount, time to |
| 538 | * fail |
| 539 | */ |
| 540 | ret = -EBUSY; |
| 541 | break; |
| 542 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 543 | fallthrough; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 544 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 545 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 546 | fallthrough; |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 547 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 548 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 549 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 550 | exception->delay = 1; |
| 551 | return 0; |
| 552 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 553 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 554 | case -NFS4ERR_OLD_STATEID: |
| 555 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 556 | break; |
| 557 | case -NFS4ERR_BADOWNER: |
| 558 | /* The following works around a Linux server bug! */ |
| 559 | case -NFS4ERR_BADNAME: |
| 560 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 561 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 562 | exception->retry = 1; |
| 563 | printk(KERN_WARNING "NFS: v4 server %s " |
| 564 | "does not accept raw " |
| 565 | "uid/gids. " |
| 566 | "Reenabling the idmapper.\n", |
| 567 | server->nfs_client->cl_hostname); |
| 568 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 569 | } |
| 570 | /* We failed to handle the error */ |
| 571 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 572 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 573 | exception->recovering = 1; |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | /* This is the error handling routine for processes that are allowed |
| 578 | * to sleep. |
| 579 | */ |
| 580 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 581 | { |
| 582 | struct nfs_client *clp = server->nfs_client; |
| 583 | int ret; |
| 584 | |
| 585 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 586 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 587 | ret = nfs4_delay(&exception->timeout, |
| 588 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 589 | goto out_retry; |
| 590 | } |
| 591 | if (exception->recovering) { |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 592 | if (exception->task_is_privileged) |
| 593 | return -EDEADLOCK; |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 594 | ret = nfs4_wait_clnt_recover(clp); |
| 595 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 596 | return -EIO; |
| 597 | goto out_retry; |
| 598 | } |
| 599 | return ret; |
| 600 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 601 | if (ret == 0) |
| 602 | exception->retry = 1; |
| 603 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 604 | } |
| 605 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 606 | static int |
| 607 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 608 | int errorcode, struct nfs4_exception *exception) |
| 609 | { |
| 610 | struct nfs_client *clp = server->nfs_client; |
| 611 | int ret; |
| 612 | |
| 613 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 614 | if (exception->delay) { |
| 615 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 616 | goto out_retry; |
| 617 | } |
| 618 | if (exception->recovering) { |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 619 | if (exception->task_is_privileged) |
| 620 | return -EDEADLOCK; |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 621 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 622 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 623 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 624 | goto out_retry; |
| 625 | } |
| 626 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 627 | ret = -EIO; |
| 628 | return ret; |
| 629 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 630 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 631 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 632 | /* |
| 633 | * For NFS4ERR_MOVED, the client transport will need to |
| 634 | * be recomputed after migration recovery has completed. |
| 635 | */ |
| 636 | if (errorcode == -NFS4ERR_MOVED) |
| 637 | rpc_task_release_transport(task); |
| 638 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 639 | return ret; |
| 640 | } |
| 641 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 642 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 643 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 644 | struct nfs4_state *state, long *timeout) |
| 645 | { |
| 646 | struct nfs4_exception exception = { |
| 647 | .state = state, |
| 648 | }; |
| 649 | |
| 650 | if (task->tk_status >= 0) |
| 651 | return 0; |
| 652 | if (timeout) |
| 653 | exception.timeout = *timeout; |
| 654 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 655 | task->tk_status, |
| 656 | &exception); |
| 657 | if (exception.delay && timeout) |
| 658 | *timeout = exception.timeout; |
| 659 | if (exception.retry) |
| 660 | return -EAGAIN; |
| 661 | return 0; |
| 662 | } |
| 663 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 664 | /* |
| 665 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 666 | * or 'false' otherwise. |
| 667 | */ |
| 668 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 669 | { |
| 670 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 671 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 672 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 673 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 674 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | spin_lock(&clp->cl_lock); |
| 677 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 678 | clp->cl_last_renewal = timestamp; |
| 679 | spin_unlock(&clp->cl_lock); |
| 680 | } |
| 681 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 682 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 683 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 684 | struct nfs_client *clp = server->nfs_client; |
| 685 | |
| 686 | if (!nfs4_has_session(clp)) |
| 687 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 688 | } |
| 689 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 690 | struct nfs4_call_sync_data { |
| 691 | const struct nfs_server *seq_server; |
| 692 | struct nfs4_sequence_args *seq_args; |
| 693 | struct nfs4_sequence_res *seq_res; |
| 694 | }; |
| 695 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 696 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 697 | struct nfs4_sequence_res *res, int cache_reply, |
| 698 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 699 | { |
| 700 | args->sa_slot = NULL; |
| 701 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 702 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 703 | |
| 704 | res->sr_slot = NULL; |
| 705 | } |
| 706 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 707 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 708 | { |
| 709 | struct nfs4_slot *slot = res->sr_slot; |
| 710 | struct nfs4_slot_table *tbl; |
| 711 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 712 | tbl = slot->table; |
| 713 | spin_lock(&tbl->slot_tbl_lock); |
| 714 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 715 | nfs4_free_slot(tbl, slot); |
| 716 | spin_unlock(&tbl->slot_tbl_lock); |
| 717 | |
| 718 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static int nfs40_sequence_done(struct rpc_task *task, |
| 722 | struct nfs4_sequence_res *res) |
| 723 | { |
| 724 | if (res->sr_slot != NULL) |
| 725 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 726 | return 1; |
| 727 | } |
| 728 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 729 | #if defined(CONFIG_NFS_V4_1) |
| 730 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 731 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 732 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 733 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 734 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 735 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 736 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 737 | if (!slot) |
| 738 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 739 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 740 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 741 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 742 | /* Bump the slot sequence number */ |
| 743 | if (slot->seq_done) |
| 744 | slot->seq_nr++; |
| 745 | slot->seq_done = 0; |
| 746 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 747 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 748 | /* Be nice to the server: try to ensure that the last transmitted |
| 749 | * value for highest_user_slotid <= target_highest_slotid |
| 750 | */ |
| 751 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 752 | send_new_highest_used_slotid = true; |
| 753 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 754 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 755 | send_new_highest_used_slotid = false; |
| 756 | goto out_unlock; |
| 757 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 758 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 759 | |
| 760 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 761 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 762 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 763 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 764 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 765 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 766 | if (waitqueue_active(&tbl->slot_waitq)) |
| 767 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 768 | } |
| 769 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 770 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 771 | { |
| 772 | nfs41_release_slot(res->sr_slot); |
| 773 | res->sr_slot = NULL; |
| 774 | } |
| 775 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 776 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 777 | u32 seqnr) |
| 778 | { |
| 779 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 780 | slot->seq_nr_highest_sent = seqnr; |
| 781 | } |
| 782 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 783 | u32 seqnr) |
| 784 | { |
| 785 | slot->seq_nr_highest_sent = seqnr; |
| 786 | slot->seq_nr_last_acked = seqnr; |
| 787 | } |
| 788 | |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 789 | static void nfs4_probe_sequence(struct nfs_client *client, const struct cred *cred, |
| 790 | struct nfs4_slot *slot) |
| 791 | { |
| 792 | struct rpc_task *task = _nfs41_proc_sequence(client, cred, slot, true); |
| 793 | if (!IS_ERR(task)) |
| 794 | rpc_put_task_async(task); |
| 795 | } |
| 796 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 797 | static int nfs41_sequence_process(struct rpc_task *task, |
| 798 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 799 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 800 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 801 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 802 | struct nfs_client *clp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 803 | int status; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 804 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 805 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 806 | if (slot == NULL) |
| 807 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 808 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 809 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 810 | goto out; |
| 811 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 812 | session = slot->table->session; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 813 | clp = session->clp; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 814 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 815 | trace_nfs4_sequence_done(session, res); |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 816 | |
| 817 | status = res->sr_status; |
| 818 | if (task->tk_status == -NFS4ERR_DEADSESSION) |
| 819 | status = -NFS4ERR_DEADSESSION; |
| 820 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 821 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 822 | switch (status) { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 823 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 824 | /* Mark this sequence number as having been acked */ |
| 825 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 826 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 827 | slot->seq_done = 1; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 828 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 829 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 830 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 831 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 832 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 833 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 834 | case 1: |
| 835 | /* |
| 836 | * sr_status remains 1 if an RPC level error occurred. |
| 837 | * The server may or may not have processed the sequence |
| 838 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 839 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 840 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 841 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 842 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 843 | case -NFS4ERR_DELAY: |
| 844 | /* The server detected a resend of the RPC call and |
| 845 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 846 | * of RFC5661. |
| 847 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 848 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 849 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 850 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 851 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 852 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 853 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 854 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 855 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 856 | /* |
| 857 | * The server thinks we tried to replay a request. |
| 858 | * Retry the call after bumping the sequence ID. |
| 859 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 860 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 861 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 862 | case -NFS4ERR_BADSLOT: |
| 863 | /* |
| 864 | * The slot id we used was probably retired. Try again |
| 865 | * using a different slot id. |
| 866 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 867 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 868 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 869 | goto retry_nowait; |
| 870 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 871 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 872 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 873 | * Were one or more calls using this slot interrupted? |
| 874 | * If the server never received the request, then our |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 875 | * transmitted slot sequence number may be too high. However, |
| 876 | * if the server did receive the request then it might |
| 877 | * accidentally give us a reply with a mismatched operation. |
| 878 | * We can sort this out by sending a lone sequence operation |
| 879 | * to the server on the same slot. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 880 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 881 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 882 | slot->seq_nr--; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 883 | if (task->tk_msg.rpc_proc != &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE]) { |
| 884 | nfs4_probe_sequence(clp, task->tk_msg.rpc_cred, slot); |
| 885 | res->sr_slot = NULL; |
| 886 | } |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 887 | goto retry_nowait; |
| 888 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 889 | /* |
| 890 | * RFC5661: |
| 891 | * A retry might be sent while the original request is |
| 892 | * still in progress on the replier. The replier SHOULD |
| 893 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 894 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 895 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 896 | * |
| 897 | * Restart the search after a delay. |
| 898 | */ |
| 899 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 900 | goto out_retry; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 901 | case -NFS4ERR_BADSESSION: |
| 902 | case -NFS4ERR_DEADSESSION: |
| 903 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 904 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 905 | default: |
| 906 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 907 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 908 | } |
| 909 | out: |
| 910 | /* The session may be reset by one of the error handlers. */ |
| 911 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 912 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 913 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 914 | session_recover: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 915 | nfs4_schedule_session_recovery(session, status); |
| 916 | dprintk("%s ERROR: %d Reset session\n", __func__, status); |
| 917 | nfs41_sequence_free_slot(res); |
| 918 | goto out; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 919 | retry_new_seq: |
| 920 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 921 | retry_nowait: |
| 922 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 923 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 924 | task->tk_status = 0; |
| 925 | ret = 0; |
| 926 | } |
| 927 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 928 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 929 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 930 | goto out; |
| 931 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 932 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 933 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 934 | |
| 935 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 936 | { |
| 937 | if (!nfs41_sequence_process(task, res)) |
| 938 | return 0; |
| 939 | if (res->sr_slot != NULL) |
| 940 | nfs41_sequence_free_slot(res); |
| 941 | return 1; |
| 942 | |
| 943 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 944 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 945 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 946 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 947 | { |
| 948 | if (res->sr_slot == NULL) |
| 949 | return 1; |
| 950 | if (res->sr_slot->table->session != NULL) |
| 951 | return nfs41_sequence_process(task, res); |
| 952 | return nfs40_sequence_done(task, res); |
| 953 | } |
| 954 | |
| 955 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 956 | { |
| 957 | if (res->sr_slot != NULL) { |
| 958 | if (res->sr_slot->table->session != NULL) |
| 959 | nfs41_sequence_free_slot(res); |
| 960 | else |
| 961 | nfs40_sequence_free_slot(res); |
| 962 | } |
| 963 | } |
| 964 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 965 | 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] | 966 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 967 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 968 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 969 | if (!res->sr_slot->table->session) |
| 970 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 971 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 972 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 973 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 974 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 975 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 976 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 977 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 978 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 979 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 980 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 981 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 982 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 983 | } |
| 984 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 985 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 986 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 987 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 988 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 989 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 990 | } |
| 991 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 992 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 993 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 994 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 995 | }; |
| 996 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 997 | #else /* !CONFIG_NFS_V4_1 */ |
| 998 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 999 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 1000 | { |
| 1001 | return nfs40_sequence_done(task, res); |
| 1002 | } |
| 1003 | |
| 1004 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1005 | { |
| 1006 | if (res->sr_slot != NULL) |
| 1007 | nfs40_sequence_free_slot(res); |
| 1008 | } |
| 1009 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1010 | int nfs4_sequence_done(struct rpc_task *task, |
| 1011 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1012 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1013 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1014 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1015 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1016 | |
| 1017 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1018 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1019 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 1020 | { |
| 1021 | res->sr_timestamp = jiffies; |
| 1022 | res->sr_status_flags = 0; |
| 1023 | res->sr_status = 1; |
| 1024 | } |
| 1025 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1026 | static |
| 1027 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 1028 | struct nfs4_sequence_res *res, |
| 1029 | struct nfs4_slot *slot) |
| 1030 | { |
| 1031 | if (!slot) |
| 1032 | return; |
| 1033 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 1034 | args->sa_slot = slot; |
| 1035 | |
| 1036 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1040 | struct nfs4_sequence_args *args, |
| 1041 | struct nfs4_sequence_res *res, |
| 1042 | struct rpc_task *task) |
| 1043 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1044 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1045 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1046 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1047 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1048 | /* slot already allocated? */ |
| 1049 | if (res->sr_slot != NULL) |
| 1050 | goto out_start; |
| 1051 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1052 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1053 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1054 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1055 | spin_lock(&tbl->slot_tbl_lock); |
| 1056 | /* The state manager will wait until the slot table is empty */ |
| 1057 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1058 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1059 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1060 | slot = nfs4_alloc_slot(tbl); |
| 1061 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1062 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1063 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1064 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1065 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1066 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1067 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1068 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1069 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1070 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1071 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1072 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1073 | rpc_call_start(task); |
| 1074 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1075 | out_sleep_timeout: |
| 1076 | /* Try again in 1/4 second */ |
| 1077 | if (args->sa_privileged) |
| 1078 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1079 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1080 | else |
| 1081 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1082 | NULL, jiffies + (HZ >> 2)); |
| 1083 | spin_unlock(&tbl->slot_tbl_lock); |
| 1084 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1085 | out_sleep: |
| 1086 | if (args->sa_privileged) |
| 1087 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1088 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1089 | else |
| 1090 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1091 | spin_unlock(&tbl->slot_tbl_lock); |
| 1092 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1093 | } |
| 1094 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1095 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1096 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1097 | { |
| 1098 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1099 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1100 | data->seq_args, data->seq_res, task); |
| 1101 | } |
| 1102 | |
| 1103 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1104 | { |
| 1105 | struct nfs4_call_sync_data *data = calldata; |
| 1106 | nfs4_sequence_done(task, data->seq_res); |
| 1107 | } |
| 1108 | |
| 1109 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1110 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1111 | .rpc_call_done = nfs40_call_sync_done, |
| 1112 | }; |
| 1113 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1114 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1115 | { |
| 1116 | int ret; |
| 1117 | struct rpc_task *task; |
| 1118 | |
| 1119 | task = rpc_run_task(task_setup); |
| 1120 | if (IS_ERR(task)) |
| 1121 | return PTR_ERR(task); |
| 1122 | |
| 1123 | ret = task->tk_status; |
| 1124 | rpc_put_task(task); |
| 1125 | return ret; |
| 1126 | } |
| 1127 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1128 | static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
| 1129 | struct nfs_server *server, |
| 1130 | struct rpc_message *msg, |
| 1131 | struct nfs4_sequence_args *args, |
| 1132 | struct nfs4_sequence_res *res, |
| 1133 | unsigned short task_flags) |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1134 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1135 | struct nfs_client *clp = server->nfs_client; |
| 1136 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1137 | .seq_server = server, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1138 | .seq_args = args, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1139 | .seq_res = res, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1140 | }; |
| 1141 | struct rpc_task_setup task_setup = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1142 | .rpc_client = clnt, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1143 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1144 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1145 | .callback_data = &data, |
| 1146 | .flags = task_flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1147 | }; |
| 1148 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1149 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1150 | } |
| 1151 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1152 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 1153 | struct nfs_server *server, |
| 1154 | struct rpc_message *msg, |
| 1155 | struct nfs4_sequence_args *args, |
| 1156 | struct nfs4_sequence_res *res) |
| 1157 | { |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 1158 | unsigned short task_flags = 0; |
| 1159 | |
| 1160 | if (server->nfs_client->cl_minorversion) |
| 1161 | task_flags = RPC_TASK_MOVEABLE; |
| 1162 | return nfs4_do_call_sync(clnt, server, msg, args, res, task_flags); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1166 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1167 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1168 | struct rpc_message *msg, |
| 1169 | struct nfs4_sequence_args *args, |
| 1170 | struct nfs4_sequence_res *res, |
| 1171 | int cache_reply) |
| 1172 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1173 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1174 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1177 | static void |
| 1178 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1179 | { |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 1180 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 1181 | NFS_INO_INVALID_CTIME | |
| 1182 | NFS_INO_INVALID_NLINK); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1183 | inc_nlink(inode); |
| 1184 | } |
| 1185 | |
| 1186 | static void |
Trond Myklebust | 1301e42 | 2021-04-01 14:57:56 -0400 | [diff] [blame] | 1187 | nfs4_inc_nlink(struct inode *inode) |
| 1188 | { |
| 1189 | spin_lock(&inode->i_lock); |
| 1190 | nfs4_inc_nlink_locked(inode); |
| 1191 | spin_unlock(&inode->i_lock); |
| 1192 | } |
| 1193 | |
| 1194 | static void |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1195 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1196 | { |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 1197 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 1198 | NFS_INO_INVALID_CTIME | |
| 1199 | NFS_INO_INVALID_NLINK); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1200 | drop_nlink(inode); |
| 1201 | } |
| 1202 | |
| 1203 | static void |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1204 | nfs4_update_changeattr_locked(struct inode *inode, |
| 1205 | struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1206 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1208 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1209 | u64 change_attr = inode_peek_iversion_raw(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 1211 | cache_validity |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME; |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1212 | if (S_ISDIR(inode->i_mode)) |
| 1213 | cache_validity |= NFS_INO_INVALID_DATA; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1214 | |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1215 | switch (NFS_SERVER(inode)->change_attr_type) { |
| 1216 | case NFS4_CHANGE_TYPE_IS_UNDEFINED: |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1217 | if (cinfo->after == change_attr) |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1218 | goto out; |
| 1219 | break; |
| 1220 | default: |
| 1221 | if ((s64)(change_attr - cinfo->after) >= 0) |
| 1222 | goto out; |
| 1223 | } |
| 1224 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1225 | inode_set_iversion_raw(inode, cinfo->after); |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1226 | if (!cinfo->atomic || cinfo->before != change_attr) { |
| 1227 | if (S_ISDIR(inode->i_mode)) |
| 1228 | nfs_force_lookup_revalidate(inode); |
| 1229 | |
| 1230 | if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) |
| 1231 | cache_validity |= |
| 1232 | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL | |
| 1233 | NFS_INO_INVALID_SIZE | NFS_INO_INVALID_OTHER | |
| 1234 | NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_NLINK | |
| 1235 | NFS_INO_INVALID_MODE | NFS_INO_INVALID_XATTR | |
| 1236 | NFS_INO_REVAL_PAGECACHE; |
| 1237 | nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); |
| 1238 | } |
| 1239 | nfsi->attrtimeo_timestamp = jiffies; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1240 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1241 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1242 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1243 | out: |
| 1244 | nfs_set_cache_invalid(inode, cache_validity); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1245 | } |
| 1246 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1247 | void |
| 1248 | nfs4_update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1249 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1250 | { |
| 1251 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1252 | nfs4_update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | spin_unlock(&dir->i_lock); |
| 1254 | } |
| 1255 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1256 | struct nfs4_open_createattrs { |
| 1257 | struct nfs4_label *label; |
| 1258 | struct iattr *sattr; |
| 1259 | const __u32 verf[2]; |
| 1260 | }; |
| 1261 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1262 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1263 | int err, struct nfs4_exception *exception) |
| 1264 | { |
| 1265 | if (err != -EINVAL) |
| 1266 | return false; |
| 1267 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1268 | return false; |
| 1269 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1270 | exception->retry = 1; |
| 1271 | return true; |
| 1272 | } |
| 1273 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1274 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1275 | { |
| 1276 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1277 | } |
| 1278 | |
| 1279 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1280 | { |
| 1281 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1282 | |
| 1283 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1284 | } |
| 1285 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1286 | static u32 |
| 1287 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1288 | fmode_t fmode, int openflags) |
| 1289 | { |
| 1290 | u32 res = 0; |
| 1291 | |
| 1292 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1293 | case FMODE_READ: |
| 1294 | res = NFS4_SHARE_ACCESS_READ; |
| 1295 | break; |
| 1296 | case FMODE_WRITE: |
| 1297 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1298 | break; |
| 1299 | case FMODE_READ|FMODE_WRITE: |
| 1300 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1301 | } |
| 1302 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1303 | goto out; |
| 1304 | /* Want no delegation if we're using O_DIRECT */ |
| 1305 | if (openflags & O_DIRECT) |
| 1306 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1307 | out: |
| 1308 | return res; |
| 1309 | } |
| 1310 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1311 | static enum open_claim_type4 |
| 1312 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1313 | enum open_claim_type4 claim) |
| 1314 | { |
| 1315 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1316 | return claim; |
| 1317 | switch (claim) { |
| 1318 | default: |
| 1319 | return claim; |
| 1320 | case NFS4_OPEN_CLAIM_FH: |
| 1321 | return NFS4_OPEN_CLAIM_NULL; |
| 1322 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1323 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1324 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1325 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1326 | } |
| 1327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | |
| 1329 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1330 | { |
| 1331 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1332 | p->o_res.seqid = p->o_arg.seqid; |
| 1333 | p->c_res.seqid = p->c_arg.seqid; |
| 1334 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1335 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1336 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1337 | 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] | 1338 | } |
| 1339 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1340 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1341 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1342 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1343 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1344 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1345 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1346 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1347 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1348 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1349 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1350 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1351 | struct nfs4_opendata *p; |
| 1352 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1353 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1354 | if (p == NULL) |
| 1355 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1356 | |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1357 | p->f_attr.label = nfs4_label_alloc(server, gfp_mask); |
| 1358 | if (IS_ERR(p->f_attr.label)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1359 | goto err_free_p; |
| 1360 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1361 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1362 | if (IS_ERR(p->a_label)) |
| 1363 | goto err_free_f; |
| 1364 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1365 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1366 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1367 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1368 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1369 | nfs_sb_active(dentry->d_sb); |
| 1370 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1371 | p->dir = parent; |
| 1372 | p->owner = sp; |
| 1373 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1374 | p->o_arg.open_flags = flags; |
| 1375 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1376 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1377 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1378 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1379 | if (flags & O_CREAT) { |
| 1380 | p->o_arg.umask = current_umask(); |
| 1381 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1382 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1383 | p->o_arg.u.attrs = &p->attrs; |
| 1384 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1385 | |
| 1386 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1387 | sizeof(p->o_arg.u.verifier.data)); |
| 1388 | } |
| 1389 | } |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 1390 | /* ask server to check for all possible rights as results |
| 1391 | * are cached */ |
| 1392 | switch (p->o_arg.claim) { |
| 1393 | default: |
| 1394 | break; |
| 1395 | case NFS4_OPEN_CLAIM_NULL: |
| 1396 | case NFS4_OPEN_CLAIM_FH: |
| 1397 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1398 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE | |
| 1399 | NFS4_ACCESS_EXECUTE; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1400 | #ifdef CONFIG_NFS_V4_2 |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 1401 | if (!(server->caps & NFS_CAP_XATTR)) |
| 1402 | break; |
| 1403 | p->o_arg.access |= NFS4_ACCESS_XAREAD | NFS4_ACCESS_XAWRITE | |
| 1404 | NFS4_ACCESS_XALIST; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1405 | #endif |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1406 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1407 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1408 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1409 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1410 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1411 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1412 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1413 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1414 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1415 | case NFS4_OPEN_CLAIM_NULL: |
| 1416 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1417 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1418 | p->o_arg.fh = NFS_FH(dir); |
| 1419 | break; |
| 1420 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1421 | case NFS4_OPEN_CLAIM_FH: |
| 1422 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1423 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1424 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1425 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1426 | p->c_arg.fh = &p->o_res.fh; |
| 1427 | p->c_arg.stateid = &p->o_res.stateid; |
| 1428 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1429 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1430 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1431 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1432 | |
| 1433 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1434 | nfs4_label_free(p->a_label); |
| 1435 | err_free_f: |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1436 | nfs4_label_free(p->f_attr.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1437 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1438 | kfree(p); |
| 1439 | err: |
| 1440 | dput(parent); |
| 1441 | return NULL; |
| 1442 | } |
| 1443 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1444 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1445 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1446 | struct nfs4_opendata *p = container_of(kref, |
| 1447 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1448 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1449 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1450 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1451 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1452 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1453 | if (p->state != NULL) |
| 1454 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1455 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1456 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1457 | nfs4_label_free(p->a_label); |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1458 | nfs4_label_free(p->f_attr.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1459 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1460 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1461 | dput(p->dentry); |
| 1462 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1463 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1464 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1465 | kfree(p); |
| 1466 | } |
| 1467 | |
| 1468 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1469 | { |
| 1470 | if (p != NULL) |
| 1471 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1472 | } |
| 1473 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1474 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1475 | fmode_t fmode) |
| 1476 | { |
| 1477 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1478 | case FMODE_READ|FMODE_WRITE: |
| 1479 | return state->n_rdwr != 0; |
| 1480 | case FMODE_WRITE: |
| 1481 | return state->n_wronly != 0; |
| 1482 | case FMODE_READ: |
| 1483 | return state->n_rdonly != 0; |
| 1484 | } |
| 1485 | WARN_ON_ONCE(1); |
| 1486 | return false; |
| 1487 | } |
| 1488 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1489 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1490 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1491 | { |
| 1492 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1493 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1494 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1495 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1496 | switch (claim) { |
| 1497 | case NFS4_OPEN_CLAIM_NULL: |
| 1498 | case NFS4_OPEN_CLAIM_FH: |
| 1499 | goto out; |
| 1500 | default: |
| 1501 | break; |
| 1502 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1503 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1504 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1505 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1506 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1507 | break; |
| 1508 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1509 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1510 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1511 | break; |
| 1512 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1513 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1514 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1515 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1516 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1517 | return ret; |
| 1518 | } |
| 1519 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1520 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1521 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1522 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1523 | if (delegation == NULL) |
| 1524 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1525 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1526 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1527 | switch (claim) { |
| 1528 | case NFS4_OPEN_CLAIM_NULL: |
| 1529 | case NFS4_OPEN_CLAIM_FH: |
| 1530 | break; |
| 1531 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1532 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1533 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1534 | fallthrough; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1535 | default: |
| 1536 | return 0; |
| 1537 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1538 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1539 | return 1; |
| 1540 | } |
| 1541 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1542 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1543 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1544 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1545 | case FMODE_WRITE: |
| 1546 | state->n_wronly++; |
| 1547 | break; |
| 1548 | case FMODE_READ: |
| 1549 | state->n_rdonly++; |
| 1550 | break; |
| 1551 | case FMODE_READ|FMODE_WRITE: |
| 1552 | state->n_rdwr++; |
| 1553 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1554 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1557 | #ifdef CONFIG_NFS_V4_1 |
| 1558 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1559 | { |
| 1560 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1561 | return true; |
| 1562 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1563 | return true; |
| 1564 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1565 | return true; |
| 1566 | return false; |
| 1567 | } |
| 1568 | #endif /* CONFIG_NFS_V4_1 */ |
| 1569 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1570 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1571 | { |
| 1572 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1573 | wake_up_all(&state->waitq); |
| 1574 | } |
| 1575 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1576 | 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] | 1577 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1578 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1579 | bool need_recover = false; |
| 1580 | |
| 1581 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1582 | need_recover = true; |
| 1583 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1584 | need_recover = true; |
| 1585 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1586 | need_recover = true; |
| 1587 | if (need_recover) |
| 1588 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1589 | } |
| 1590 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1591 | /* |
| 1592 | * Check for whether or not the caller may update the open stateid |
| 1593 | * to the value passed in by stateid. |
| 1594 | * |
| 1595 | * Note: This function relies heavily on the server implementing |
| 1596 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1597 | * correctly. |
| 1598 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1599 | * are then incremented on every state transition. |
| 1600 | */ |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1601 | static bool nfs_stateid_is_sequential(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1602 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1603 | { |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1604 | if (test_bit(NFS_OPEN_STATE, &state->flags)) { |
| 1605 | /* The common case - we're updating to a new sequence number */ |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1606 | if (nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1607 | if (nfs4_stateid_is_next(&state->open_stateid, stateid)) |
| 1608 | return true; |
| 1609 | return false; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1610 | } |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1611 | /* The server returned a new stateid */ |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1612 | } |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1613 | /* This is the first OPEN in this generation */ |
| 1614 | if (stateid->seqid == cpu_to_be32(1)) |
| 1615 | return true; |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1616 | return false; |
| 1617 | } |
| 1618 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1619 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1620 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1621 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1622 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1623 | if (state->n_wronly) |
| 1624 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1625 | if (state->n_rdonly) |
| 1626 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1627 | if (state->n_rdwr) |
| 1628 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1629 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1630 | } |
| 1631 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1632 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1633 | nfs4_stateid *stateid, fmode_t fmode) |
| 1634 | { |
| 1635 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1636 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1637 | case FMODE_WRITE: |
| 1638 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1639 | break; |
| 1640 | case FMODE_READ: |
| 1641 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1642 | break; |
| 1643 | case 0: |
| 1644 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1645 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1646 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1647 | } |
| 1648 | if (stateid == NULL) |
| 1649 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1650 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1651 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1652 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1653 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1654 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1655 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1656 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1657 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1658 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1659 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1660 | out: |
| 1661 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1662 | } |
| 1663 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1664 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1665 | nfs4_stateid *arg_stateid, |
| 1666 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1667 | { |
| 1668 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1669 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1670 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1671 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1672 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1673 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1674 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1675 | } |
| 1676 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1677 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1678 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1679 | __must_hold(&state->owner->so_lock) |
| 1680 | __must_hold(&state->seqlock) |
| 1681 | __must_hold(RCU) |
| 1682 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1683 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1684 | DEFINE_WAIT(wait); |
| 1685 | int status = 0; |
| 1686 | for (;;) { |
| 1687 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1688 | if (nfs_stateid_is_sequential(state, stateid)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1689 | break; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1690 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1691 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1692 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1693 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1694 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1695 | break; |
| 1696 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1697 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1698 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1699 | /* |
| 1700 | * Ensure we process the state changes in the same order |
| 1701 | * in which the server processed them by delaying the |
| 1702 | * update of the stateid until we are in sequence. |
| 1703 | */ |
| 1704 | write_sequnlock(&state->seqlock); |
| 1705 | spin_unlock(&state->owner->so_lock); |
| 1706 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1707 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1708 | |
zhouchuangao | bb00238 | 2021-05-09 19:34:37 -0700 | [diff] [blame] | 1709 | if (!fatal_signal_pending(current)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1710 | if (schedule_timeout(5*HZ) == 0) |
| 1711 | status = -EAGAIN; |
| 1712 | else |
| 1713 | status = 0; |
| 1714 | } else |
| 1715 | status = -EINTR; |
| 1716 | finish_wait(&state->waitq, &wait); |
| 1717 | rcu_read_lock(); |
| 1718 | spin_lock(&state->owner->so_lock); |
| 1719 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1720 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1721 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1722 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1723 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1724 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1725 | nfs_test_and_clear_all_open_stateid(state); |
| 1726 | } |
| 1727 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1728 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1729 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1730 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1731 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1732 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1733 | } |
| 1734 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1735 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1736 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1737 | fmode_t fmode, |
| 1738 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1740 | /* |
| 1741 | * Protect the call to nfs4_state_set_mode_locked and |
| 1742 | * serialise the stateid update |
| 1743 | */ |
| 1744 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1745 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1746 | switch (fmode) { |
| 1747 | case FMODE_READ: |
| 1748 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1749 | break; |
| 1750 | case FMODE_WRITE: |
| 1751 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1752 | break; |
| 1753 | case FMODE_READ|FMODE_WRITE: |
| 1754 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1755 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1756 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1757 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1758 | } |
| 1759 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1760 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1761 | { |
| 1762 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1763 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1764 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1765 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1766 | } |
| 1767 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1768 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1769 | const nfs4_stateid *deleg_stateid, |
| 1770 | fmode_t fmode) |
| 1771 | { |
| 1772 | /* |
| 1773 | * Protect the call to nfs4_state_set_mode_locked and |
| 1774 | * serialise the stateid update |
| 1775 | */ |
| 1776 | write_seqlock(&state->seqlock); |
| 1777 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1778 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1779 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1782 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1783 | { |
| 1784 | write_seqlock(&state->seqlock); |
| 1785 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1786 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1787 | write_sequnlock(&state->seqlock); |
| 1788 | } |
| 1789 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1790 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1791 | const nfs4_stateid *open_stateid, |
| 1792 | const nfs4_stateid *delegation, |
| 1793 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1794 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1795 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1796 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1797 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1798 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1799 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1800 | int ret = 0; |
| 1801 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1802 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1803 | |
| 1804 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1805 | spin_lock(&state->owner->so_lock); |
| 1806 | if (open_stateid != NULL) { |
| 1807 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1808 | ret = 1; |
| 1809 | } |
| 1810 | |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1811 | deleg_cur = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1812 | if (deleg_cur == NULL) |
| 1813 | goto no_delegation; |
| 1814 | |
| 1815 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1816 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1817 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1818 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1819 | goto no_delegation_unlock; |
| 1820 | |
| 1821 | if (delegation == NULL) |
| 1822 | delegation = &deleg_cur->stateid; |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1823 | else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1824 | goto no_delegation_unlock; |
| 1825 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1826 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1827 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1828 | ret = 1; |
| 1829 | no_delegation_unlock: |
| 1830 | spin_unlock(&deleg_cur->lock); |
| 1831 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1832 | if (ret) |
| 1833 | update_open_stateflags(state, fmode); |
| 1834 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1835 | rcu_read_unlock(); |
| 1836 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1837 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1838 | nfs4_schedule_state_manager(clp); |
| 1839 | if (freeme.type != 0) |
| 1840 | nfs4_test_and_free_stateid(server, &freeme, |
| 1841 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1842 | |
| 1843 | return ret; |
| 1844 | } |
| 1845 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1846 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1847 | const nfs4_stateid *stateid) |
| 1848 | { |
| 1849 | struct nfs4_state *state = lsp->ls_state; |
| 1850 | bool ret = false; |
| 1851 | |
| 1852 | spin_lock(&state->state_lock); |
| 1853 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1854 | goto out_noupdate; |
| 1855 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1856 | goto out_noupdate; |
| 1857 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1858 | ret = true; |
| 1859 | out_noupdate: |
| 1860 | spin_unlock(&state->state_lock); |
| 1861 | return ret; |
| 1862 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1863 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1864 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1865 | { |
| 1866 | struct nfs_delegation *delegation; |
| 1867 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1868 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1869 | rcu_read_lock(); |
Trond Myklebust | 40e6aa1 | 2019-10-27 13:38:45 -0400 | [diff] [blame] | 1870 | delegation = nfs4_get_valid_delegation(inode); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1871 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1872 | rcu_read_unlock(); |
| 1873 | return; |
| 1874 | } |
| 1875 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1876 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1877 | } |
| 1878 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1879 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1880 | { |
| 1881 | struct nfs4_state *state = opendata->state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1882 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1883 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1884 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1885 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1886 | nfs4_stateid stateid; |
| 1887 | int ret = -EAGAIN; |
| 1888 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1889 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1890 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1891 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1892 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1893 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1894 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1895 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1896 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1897 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 1898 | delegation = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1899 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1900 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1901 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1902 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1903 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1904 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1905 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1906 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1907 | if (!opendata->is_recover) { |
| 1908 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1909 | if (ret != 0) |
| 1910 | goto out; |
| 1911 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1912 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1913 | |
| 1914 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1915 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1916 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1917 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1918 | out: |
| 1919 | return ERR_PTR(ret); |
| 1920 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1921 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1922 | return state; |
| 1923 | } |
| 1924 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1925 | static void |
| 1926 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1927 | { |
| 1928 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1929 | struct nfs_delegation *delegation; |
| 1930 | int delegation_flags = 0; |
| 1931 | |
| 1932 | rcu_read_lock(); |
| 1933 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1934 | if (delegation) |
| 1935 | delegation_flags = delegation->flags; |
| 1936 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1937 | switch (data->o_arg.claim) { |
| 1938 | default: |
| 1939 | break; |
| 1940 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1941 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1942 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1943 | "returning a delegation for " |
| 1944 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1945 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1946 | return; |
| 1947 | } |
| 1948 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1949 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1950 | data->owner->so_cred, |
| 1951 | data->o_res.delegation_type, |
| 1952 | &data->o_res.delegation, |
| 1953 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1954 | else |
| 1955 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1956 | data->owner->so_cred, |
| 1957 | data->o_res.delegation_type, |
| 1958 | &data->o_res.delegation, |
| 1959 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1960 | |
| 1961 | if (data->o_res.do_recall) |
| 1962 | nfs_async_inode_return_delegation(state->inode, |
| 1963 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | /* |
| 1967 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1968 | * and update the nfs4_state. |
| 1969 | */ |
| 1970 | static struct nfs4_state * |
| 1971 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1972 | { |
| 1973 | struct inode *inode = data->state->inode; |
| 1974 | struct nfs4_state *state = data->state; |
| 1975 | int ret; |
| 1976 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1977 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1978 | if (data->rpc_status) |
| 1979 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1980 | /* cached opens have already been processed */ |
| 1981 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1982 | } |
| 1983 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1984 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1985 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1986 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1987 | |
| 1988 | if (data->o_res.delegation_type != 0) |
| 1989 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1990 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1991 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1992 | NULL, data->o_arg.fmode)) |
| 1993 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1994 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1995 | |
| 1996 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1997 | } |
| 1998 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1999 | static struct inode * |
| 2000 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 2001 | { |
| 2002 | struct inode *inode; |
| 2003 | |
| 2004 | switch (data->o_arg.claim) { |
| 2005 | case NFS4_OPEN_CLAIM_NULL: |
| 2006 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 2007 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 2008 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 2009 | return ERR_PTR(-EAGAIN); |
| 2010 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 2011 | &data->f_attr, data->f_attr.label); |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 2012 | break; |
| 2013 | default: |
| 2014 | inode = d_inode(data->dentry); |
| 2015 | ihold(inode); |
| 2016 | nfs_refresh_inode(inode, &data->f_attr); |
| 2017 | } |
| 2018 | return inode; |
| 2019 | } |
| 2020 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2021 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2022 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 2023 | { |
| 2024 | struct nfs4_state *state; |
| 2025 | struct inode *inode; |
| 2026 | |
| 2027 | inode = nfs4_opendata_get_inode(data); |
| 2028 | if (IS_ERR(inode)) |
| 2029 | return ERR_CAST(inode); |
| 2030 | if (data->state != NULL && data->state->inode == inode) { |
| 2031 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2032 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2033 | } else |
| 2034 | state = nfs4_get_open_state(inode, data->owner); |
| 2035 | iput(inode); |
| 2036 | if (state == NULL) |
| 2037 | state = ERR_PTR(-ENOMEM); |
| 2038 | return state; |
| 2039 | } |
| 2040 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2041 | static struct nfs4_state * |
| 2042 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2043 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2044 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2045 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2046 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2047 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2048 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2049 | goto out; |
| 2050 | } |
| 2051 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2052 | state = nfs4_opendata_find_nfs4_state(data); |
| 2053 | if (IS_ERR(state)) |
| 2054 | goto out; |
| 2055 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2056 | if (data->o_res.delegation_type != 0) |
| 2057 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 2058 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 2059 | NULL, data->o_arg.fmode)) { |
| 2060 | nfs4_put_open_state(state); |
| 2061 | state = ERR_PTR(-EAGAIN); |
| 2062 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2063 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 2064 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2065 | return state; |
| 2066 | } |
| 2067 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2068 | static struct nfs4_state * |
| 2069 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2070 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2071 | struct nfs4_state *ret; |
| 2072 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2073 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2074 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2075 | else |
| 2076 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2077 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2078 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2079 | } |
| 2080 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2081 | static struct nfs_open_context * |
| 2082 | 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] | 2083 | { |
| 2084 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2085 | struct nfs_open_context *ctx; |
| 2086 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2087 | rcu_read_lock(); |
| 2088 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2089 | if (ctx->state != state) |
| 2090 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2091 | if ((ctx->mode & mode) != mode) |
| 2092 | continue; |
| 2093 | if (!get_nfs_open_context(ctx)) |
| 2094 | continue; |
| 2095 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2096 | return ctx; |
| 2097 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2098 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2099 | return ERR_PTR(-ENOENT); |
| 2100 | } |
| 2101 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2102 | static struct nfs_open_context * |
| 2103 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2104 | { |
| 2105 | struct nfs_open_context *ctx; |
| 2106 | |
| 2107 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2108 | if (!IS_ERR(ctx)) |
| 2109 | return ctx; |
| 2110 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2111 | if (!IS_ERR(ctx)) |
| 2112 | return ctx; |
| 2113 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2114 | } |
| 2115 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2116 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2117 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2118 | { |
| 2119 | struct nfs4_opendata *opendata; |
| 2120 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2121 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2122 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2123 | if (opendata == NULL) |
| 2124 | return ERR_PTR(-ENOMEM); |
| 2125 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2126 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2127 | return opendata; |
| 2128 | } |
| 2129 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2130 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2131 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2132 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2133 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2134 | int ret; |
| 2135 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2136 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2137 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2138 | opendata->o_arg.open_flags = 0; |
| 2139 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2140 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2141 | NFS_SB(opendata->dentry->d_sb), |
| 2142 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2143 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2144 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2145 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2146 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2147 | if (ret != 0) |
| 2148 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2149 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2150 | if (IS_ERR(newstate)) |
| 2151 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2152 | if (newstate != opendata->state) |
| 2153 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2154 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2155 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2159 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2160 | int ret; |
| 2161 | |
| 2162 | /* memory barrier prior to reading state->n_* */ |
| 2163 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2164 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2165 | if (ret != 0) |
| 2166 | return ret; |
| 2167 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2168 | if (ret != 0) |
| 2169 | return ret; |
| 2170 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2171 | if (ret != 0) |
| 2172 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2173 | /* |
| 2174 | * We may have performed cached opens for all three recoveries. |
| 2175 | * Check if we need to update the current stateid. |
| 2176 | */ |
| 2177 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2178 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2179 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2180 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2181 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2182 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2183 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2184 | return 0; |
| 2185 | } |
| 2186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | /* |
| 2188 | * OPEN_RECLAIM: |
| 2189 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2191 | 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] | 2192 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2193 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2194 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2195 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | int status; |
| 2197 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2198 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2199 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2200 | if (IS_ERR(opendata)) |
| 2201 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2202 | rcu_read_lock(); |
| 2203 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2204 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2205 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2206 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2207 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2208 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2209 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | return status; |
| 2211 | } |
| 2212 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2213 | 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] | 2214 | { |
| 2215 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2216 | struct nfs4_exception exception = { }; |
| 2217 | int err; |
| 2218 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2219 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2220 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2221 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2222 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2223 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2224 | break; |
| 2225 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | } while (exception.retry); |
| 2227 | return err; |
| 2228 | } |
| 2229 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2230 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2231 | { |
| 2232 | struct nfs_open_context *ctx; |
| 2233 | int ret; |
| 2234 | |
| 2235 | ctx = nfs4_state_find_open_context(state); |
| 2236 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2237 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2238 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2239 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2240 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2241 | put_nfs_open_context(ctx); |
| 2242 | return ret; |
| 2243 | } |
| 2244 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2245 | 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] | 2246 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2247 | switch (err) { |
| 2248 | default: |
| 2249 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2250 | "%d.\n", __func__, err); |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame] | 2251 | fallthrough; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2252 | case 0: |
| 2253 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2254 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2255 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2256 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2257 | break; |
| 2258 | case -NFS4ERR_BADSESSION: |
| 2259 | case -NFS4ERR_BADSLOT: |
| 2260 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2261 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2262 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2263 | return -EAGAIN; |
| 2264 | case -NFS4ERR_STALE_CLIENTID: |
| 2265 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2266 | /* Don't recall a delegation if it was lost */ |
| 2267 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2268 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2269 | case -NFS4ERR_MOVED: |
| 2270 | nfs4_schedule_migration_recovery(server); |
| 2271 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2272 | case -NFS4ERR_LEASE_MOVED: |
| 2273 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2274 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2275 | case -NFS4ERR_DELEG_REVOKED: |
| 2276 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2277 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2278 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2279 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2280 | nfs_inode_find_state_and_recover(state->inode, |
| 2281 | stateid); |
| 2282 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2283 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2284 | case -NFS4ERR_DELAY: |
| 2285 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2286 | ssleep(1); |
| 2287 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2288 | case -ENOMEM: |
| 2289 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2290 | if (fl) { |
| 2291 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2292 | if (lsp) |
| 2293 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2294 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2295 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | return err; |
| 2298 | } |
| 2299 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2300 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2301 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2302 | { |
| 2303 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2304 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2305 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2306 | |
| 2307 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2308 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2309 | if (IS_ERR(opendata)) |
| 2310 | return PTR_ERR(opendata); |
| 2311 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2312 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2313 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2314 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2315 | goto out; |
| 2316 | } |
| 2317 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2318 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2319 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2320 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2321 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2322 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2323 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2324 | if (err) |
| 2325 | goto out; |
| 2326 | } |
| 2327 | nfs_state_clear_delegation(state); |
| 2328 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2329 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2330 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2331 | } |
| 2332 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2333 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2334 | { |
| 2335 | struct nfs4_opendata *data = calldata; |
| 2336 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2337 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2338 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2339 | } |
| 2340 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2341 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2342 | { |
| 2343 | struct nfs4_opendata *data = calldata; |
| 2344 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2345 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2346 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2347 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2348 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2349 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2350 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2351 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2352 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2353 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | static void nfs4_open_confirm_release(void *calldata) |
| 2357 | { |
| 2358 | struct nfs4_opendata *data = calldata; |
| 2359 | struct nfs4_state *state = NULL; |
| 2360 | |
| 2361 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2362 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2363 | goto out_free; |
| 2364 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2365 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2366 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2367 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2368 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2369 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2370 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2371 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2375 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2376 | .rpc_call_done = nfs4_open_confirm_done, |
| 2377 | .rpc_release = nfs4_open_confirm_release, |
| 2378 | }; |
| 2379 | |
| 2380 | /* |
| 2381 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2382 | */ |
| 2383 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2384 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2385 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2386 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2387 | struct rpc_message msg = { |
| 2388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2389 | .rpc_argp = &data->c_arg, |
| 2390 | .rpc_resp = &data->c_res, |
| 2391 | .rpc_cred = data->owner->so_cred, |
| 2392 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2393 | struct rpc_task_setup task_setup_data = { |
| 2394 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2395 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2396 | .callback_ops = &nfs4_open_confirm_ops, |
| 2397 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2398 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2399 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2400 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | int status; |
| 2402 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2403 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2404 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2405 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2406 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2407 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2408 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2409 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2410 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2411 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2412 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2413 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2414 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2415 | smp_wmb(); |
| 2416 | } else |
| 2417 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2418 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | return status; |
| 2420 | } |
| 2421 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2422 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2424 | struct nfs4_opendata *data = calldata; |
| 2425 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2426 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2427 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2428 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2429 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2430 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2431 | /* |
| 2432 | * Check if we still need to send an OPEN call, or if we can use |
| 2433 | * a delegation instead. |
| 2434 | */ |
| 2435 | if (data->state != NULL) { |
| 2436 | struct nfs_delegation *delegation; |
| 2437 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2438 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2439 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2440 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2441 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 2442 | delegation = nfs4_get_valid_delegation(data->state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2443 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2444 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2445 | rcu_read_unlock(); |
| 2446 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2447 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2448 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2449 | switch (claim) { |
| 2450 | default: |
| 2451 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2452 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2453 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2454 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2455 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2456 | fallthrough; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2457 | case NFS4_OPEN_CLAIM_FH: |
| 2458 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2459 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2460 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2461 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2462 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2463 | &data->o_res.seq_res, |
| 2464 | task) != 0) |
| 2465 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2466 | |
| 2467 | /* Set the create mode (note dependency on the session type) */ |
| 2468 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2469 | if (data->o_arg.open_flags & O_EXCL) { |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 2470 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2471 | if (clp->cl_mvops->minor_version == 0) { |
| 2472 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2473 | /* don't put an ACCESS op in OPEN compound if O_EXCL, |
| 2474 | * because ACCESS will return permission denied for |
| 2475 | * all bits until close */ |
| 2476 | data->o_res.access_request = data->o_arg.access = 0; |
| 2477 | } else if (nfs4_has_persistent_session(clp)) |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2478 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2479 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2480 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2481 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2482 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2483 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2484 | out_no_action: |
| 2485 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2486 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2487 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2488 | } |
| 2489 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2490 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2491 | { |
| 2492 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2494 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2495 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2496 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2497 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2498 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2499 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2500 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2501 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2502 | case S_IFREG: |
| 2503 | break; |
| 2504 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2505 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2506 | break; |
| 2507 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2508 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2509 | break; |
| 2510 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2511 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2512 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2513 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2514 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2515 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2516 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2517 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2518 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2519 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2520 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2521 | static void nfs4_open_release(void *calldata) |
| 2522 | { |
| 2523 | struct nfs4_opendata *data = calldata; |
| 2524 | struct nfs4_state *state = NULL; |
| 2525 | |
| 2526 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2527 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2528 | goto out_free; |
| 2529 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2530 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2531 | goto out_free; |
| 2532 | /* In case we need an open_confirm, no cleanup! */ |
| 2533 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2534 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2535 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2536 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2537 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2538 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2539 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2543 | .rpc_call_prepare = nfs4_open_prepare, |
| 2544 | .rpc_call_done = nfs4_open_done, |
| 2545 | .rpc_release = nfs4_open_release, |
| 2546 | }; |
| 2547 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2548 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2549 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2550 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2551 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2552 | struct nfs_server *server = NFS_SERVER(dir); |
| 2553 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2554 | struct nfs_openres *o_res = &data->o_res; |
| 2555 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2556 | struct rpc_message msg = { |
| 2557 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2558 | .rpc_argp = o_arg, |
| 2559 | .rpc_resp = o_res, |
| 2560 | .rpc_cred = data->owner->so_cred, |
| 2561 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2562 | struct rpc_task_setup task_setup_data = { |
| 2563 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2564 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2565 | .callback_ops = &nfs4_open_ops, |
| 2566 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2567 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2568 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2569 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2570 | int status; |
| 2571 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 2572 | if (server->nfs_client->cl_minorversion) |
| 2573 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
| 2574 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2575 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2576 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2577 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2578 | data->cancelled = false; |
| 2579 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2580 | if (!ctx) { |
| 2581 | 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] | 2582 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2583 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2584 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2585 | 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] | 2586 | pnfs_lgopen_prepare(data, ctx); |
| 2587 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2588 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2589 | if (IS_ERR(task)) |
| 2590 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2591 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2592 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2593 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2594 | smp_wmb(); |
| 2595 | } else |
| 2596 | status = data->rpc_status; |
| 2597 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2598 | |
| 2599 | return status; |
| 2600 | } |
| 2601 | |
| 2602 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2603 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2604 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2605 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2606 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2607 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2608 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2609 | if (status != 0 || !data->rpc_done) |
| 2610 | return status; |
| 2611 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2612 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2613 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2614 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2615 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2616 | |
| 2617 | return status; |
| 2618 | } |
| 2619 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2620 | /* |
| 2621 | * Additional permission checks in order to distinguish between an |
| 2622 | * open for read, and an open for execute. This works around the |
| 2623 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2624 | * the same. |
| 2625 | * Note that in the non-execute case, we want to turn off permission |
| 2626 | * checking if we just created a new file (POSIX open() semantics). |
| 2627 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2628 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2629 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2630 | struct nfs4_state *state, fmode_t fmode, |
| 2631 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2632 | { |
| 2633 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2634 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2635 | |
| 2636 | /* access call failed or for some reason the server doesn't |
| 2637 | * support any access modes -- defer access call until later */ |
| 2638 | if (opendata->o_res.access_supported == 0) |
| 2639 | return 0; |
| 2640 | |
| 2641 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2642 | /* |
| 2643 | * Use openflags to check for exec, because fmode won't |
| 2644 | * always have FMODE_EXEC set when file open for exec. |
| 2645 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2646 | if (openflags & __FMODE_EXEC) { |
| 2647 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2648 | if (S_ISDIR(state->inode->i_mode)) |
| 2649 | mask = NFS4_ACCESS_LOOKUP; |
| 2650 | else |
| 2651 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2652 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2653 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2654 | |
| 2655 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2656 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2657 | nfs_access_add_cache(state->inode, &cache); |
| 2658 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2659 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2660 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2661 | return 0; |
| 2662 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2663 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2664 | } |
| 2665 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2666 | /* |
| 2667 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2668 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2669 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2670 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2671 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2672 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2673 | struct nfs_server *server = NFS_SERVER(dir); |
| 2674 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2675 | struct nfs_openres *o_res = &data->o_res; |
| 2676 | int status; |
| 2677 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2678 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2679 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2680 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2681 | if (status != 0) { |
| 2682 | if (status == -NFS4ERR_BADNAME && |
| 2683 | !(o_arg->open_flags & O_CREAT)) |
| 2684 | return -ENOENT; |
| 2685 | return status; |
| 2686 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2687 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2688 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2689 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2690 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2691 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2692 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2693 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2694 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2695 | if (data->file_created || |
| 2696 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 2697 | nfs4_update_changeattr(dir, &o_res->cinfo, |
| 2698 | o_res->f_attr->time_start, |
| 2699 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2700 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2701 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2702 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2704 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2706 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2708 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2709 | nfs4_sequence_free_slot(&o_res->seq_res); |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 2710 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2711 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2712 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | /* |
| 2716 | * OPEN_EXPIRED: |
| 2717 | * reclaim state on the server after a network partition. |
| 2718 | * Assumes caller holds the appropriate lock |
| 2719 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2720 | 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] | 2721 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2722 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2723 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2725 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2726 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2727 | if (IS_ERR(opendata)) |
| 2728 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2729 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2730 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2731 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2732 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2733 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2736 | 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] | 2737 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2738 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2739 | struct nfs4_exception exception = { }; |
| 2740 | int err; |
| 2741 | |
| 2742 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2743 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2744 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2745 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2746 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2747 | switch (err) { |
| 2748 | default: |
| 2749 | goto out; |
| 2750 | case -NFS4ERR_GRACE: |
| 2751 | case -NFS4ERR_DELAY: |
| 2752 | nfs4_handle_exception(server, err, &exception); |
| 2753 | err = 0; |
| 2754 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2755 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2756 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2757 | return err; |
| 2758 | } |
| 2759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2761 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2763 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2765 | ctx = nfs4_state_find_open_context(state); |
| 2766 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2767 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2768 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2769 | put_nfs_open_context(ctx); |
| 2770 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2773 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2774 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2775 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2776 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2777 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2781 | { |
| 2782 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2783 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2787 | { |
| 2788 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2789 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2790 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2791 | return nfs4_open_expired(sp, state); |
| 2792 | } |
| 2793 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2794 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2795 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2796 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2797 | { |
| 2798 | return -NFS4ERR_BAD_STATEID; |
| 2799 | } |
| 2800 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2801 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2802 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2803 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2804 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2805 | { |
| 2806 | int status; |
| 2807 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2808 | switch (stateid->type) { |
| 2809 | default: |
| 2810 | break; |
| 2811 | case NFS4_INVALID_STATEID_TYPE: |
| 2812 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2813 | return -NFS4ERR_BAD_STATEID; |
| 2814 | case NFS4_REVOKED_STATEID_TYPE: |
| 2815 | goto out_free; |
| 2816 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2817 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2818 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2819 | switch (status) { |
| 2820 | case -NFS4ERR_EXPIRED: |
| 2821 | case -NFS4ERR_ADMIN_REVOKED: |
| 2822 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2823 | break; |
| 2824 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2825 | return status; |
| 2826 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2827 | out_free: |
| 2828 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2829 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2830 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2831 | } |
| 2832 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2833 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2834 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2835 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2836 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2837 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2838 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2839 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2840 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2841 | /* Get the delegation credential for use by test/free_stateid */ |
| 2842 | rcu_read_lock(); |
| 2843 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2844 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2845 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2846 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2847 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2848 | } |
| 2849 | |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2850 | spin_lock(&delegation->lock); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2851 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2852 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2853 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2854 | &delegation->flags)) { |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2855 | spin_unlock(&delegation->lock); |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2856 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2857 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2858 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2859 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2860 | if (delegation->cred) |
| 2861 | cred = get_cred(delegation->cred); |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2862 | spin_unlock(&delegation->lock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2863 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2864 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2865 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2866 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2867 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2868 | else |
| 2869 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2870 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2871 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2872 | return ret; |
| 2873 | } |
| 2874 | |
| 2875 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2876 | { |
| 2877 | nfs4_stateid tmp; |
| 2878 | |
| 2879 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2880 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2881 | &tmp, NULL) && |
| 2882 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2883 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2884 | else |
| 2885 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2889 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2890 | * |
| 2891 | * @state: NFSv4 state for an inode |
| 2892 | * |
| 2893 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2894 | * Otherwise a negative NFS4ERR value is returned. |
| 2895 | */ |
| 2896 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2897 | { |
| 2898 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2899 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2900 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2901 | |
| 2902 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2903 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2904 | |
| 2905 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2906 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2907 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2908 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2909 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2910 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2911 | spin_unlock(&state->state_lock); |
| 2912 | |
| 2913 | nfs4_put_lock_state(prev); |
| 2914 | prev = lsp; |
| 2915 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2916 | status = nfs41_test_and_free_expired_stateid(server, |
| 2917 | &lsp->ls_stateid, |
| 2918 | cred); |
| 2919 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2920 | if (status == -NFS4ERR_EXPIRED || |
| 2921 | status == -NFS4ERR_BAD_STATEID) { |
| 2922 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2923 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2924 | if (!recover_lost_locks) |
| 2925 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2926 | } else if (status != NFS_OK) { |
| 2927 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2928 | nfs4_put_lock_state(prev); |
| 2929 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2930 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2931 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2932 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2933 | } |
| 2934 | spin_unlock(&state->state_lock); |
| 2935 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2936 | out: |
| 2937 | return ret; |
| 2938 | } |
| 2939 | |
| 2940 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2941 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2942 | * |
| 2943 | * @state: NFSv4 state for an inode |
| 2944 | * |
| 2945 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2946 | * Otherwise a negative NFS4ERR value is returned. |
| 2947 | */ |
| 2948 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2949 | { |
| 2950 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2951 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2952 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2953 | int status; |
| 2954 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2955 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2956 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2957 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2958 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2959 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2960 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2961 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2962 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2963 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2964 | if (nfs_open_stateid_recover_openmode(state)) |
| 2965 | return -NFS4ERR_OPENMODE; |
| 2966 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2970 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2971 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2972 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2973 | status = nfs41_check_delegation_stateid(state); |
| 2974 | if (status != NFS_OK) |
| 2975 | return status; |
| 2976 | nfs41_delegation_recover_stateid(state); |
| 2977 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2978 | status = nfs41_check_expired_locks(state); |
| 2979 | if (status != NFS_OK) |
| 2980 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2981 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2982 | if (status != NFS_OK) |
| 2983 | status = nfs4_open_expired(sp, state); |
| 2984 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2985 | } |
| 2986 | #endif |
| 2987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2989 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2990 | * fields corresponding to attributes that were used to store the verifier. |
| 2991 | * Make sure we clobber those fields in the later setattr call |
| 2992 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2993 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2994 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2995 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2996 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2997 | __u32 attrset[3]; |
| 2998 | unsigned ret; |
| 2999 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3000 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3001 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 3002 | attrset[i] = opendata->o_res.attrset[i]; |
| 3003 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 3004 | attrset[i] &= ~bitmask[i]; |
| 3005 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3006 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3007 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 3008 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3009 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3010 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 3011 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 3012 | ret |= ATTR_ATIME_SET; |
| 3013 | else |
| 3014 | ret |= ATTR_ATIME; |
| 3015 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3016 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3017 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 3018 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 3019 | ret |= ATTR_MTIME_SET; |
| 3020 | else |
| 3021 | ret |= ATTR_MTIME; |
| 3022 | } |
| 3023 | |
| 3024 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3025 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3026 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3027 | } |
| 3028 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3029 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3030 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3031 | { |
| 3032 | struct nfs4_state_owner *sp = opendata->owner; |
| 3033 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3034 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3035 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3036 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3037 | struct inode *dir = d_inode(opendata->dir); |
| 3038 | unsigned long dir_verifier; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3039 | unsigned int seq; |
| 3040 | int ret; |
| 3041 | |
| 3042 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3043 | dir_verifier = nfs_save_change_attribute(dir); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3044 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 3045 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 3046 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3047 | goto out; |
| 3048 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 3049 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3050 | ret = PTR_ERR(state); |
| 3051 | if (IS_ERR(state)) |
| 3052 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 3053 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3054 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 3055 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 3056 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 3057 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3058 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3059 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3060 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3061 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3062 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3063 | alias = d_exact_alias(dentry, state->inode); |
| 3064 | if (!alias) |
| 3065 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 3066 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 3067 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3068 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3069 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3070 | } |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | switch(opendata->o_arg.claim) { |
| 3074 | default: |
| 3075 | break; |
| 3076 | case NFS4_OPEN_CLAIM_NULL: |
| 3077 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 3078 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 3079 | if (!opendata->rpc_done) |
| 3080 | break; |
| 3081 | if (opendata->o_res.delegation_type != 0) |
| 3082 | dir_verifier = nfs_save_change_attribute(dir); |
| 3083 | nfs_set_verifier(dentry, dir_verifier); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3084 | } |
| 3085 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 3086 | /* Parse layoutget results before we check for access */ |
| 3087 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 3088 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3089 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 3090 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3091 | if (ret != 0) |
| 3092 | goto out; |
| 3093 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3094 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3095 | nfs_inode_attach_open_context(ctx); |
| 3096 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3097 | nfs4_schedule_stateid_recovery(server, state); |
| 3098 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3099 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3100 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3101 | if (!opendata->cancelled) |
| 3102 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3103 | return ret; |
| 3104 | } |
| 3105 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3106 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3107 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3109 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3110 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3111 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3112 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3113 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | { |
| 3115 | struct nfs4_state_owner *sp; |
| 3116 | struct nfs4_state *state = NULL; |
| 3117 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3118 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3119 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3120 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3121 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3122 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3123 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3124 | struct iattr *sattr = c->sattr; |
| 3125 | struct nfs4_label *label = c->label; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3126 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | |
| 3128 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3130 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3131 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3133 | goto out_err; |
| 3134 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3135 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3136 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3137 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3138 | if (d_really_is_positive(dentry)) |
| 3139 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3140 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3141 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3142 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3143 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3144 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3145 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3146 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3148 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3149 | if (!opendata->f_attr.mdsthreshold) { |
| 3150 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3151 | if (!opendata->f_attr.mdsthreshold) |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3152 | goto err_opendata_put; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3153 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3154 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3155 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3156 | if (d_really_is_positive(dentry)) |
| 3157 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3158 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3159 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3160 | if (status != 0) |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3161 | goto err_opendata_put; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3162 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3163 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3164 | 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] | 3165 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3166 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3167 | /* |
| 3168 | * send create attributes which was not set by open |
| 3169 | * with an extra setattr. |
| 3170 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3171 | if (attrs || label) { |
| 3172 | unsigned ia_old = sattr->ia_valid; |
| 3173 | |
| 3174 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3175 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3176 | status = nfs4_do_setattr(state->inode, cred, |
| 3177 | opendata->o_res.f_attr, sattr, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 3178 | ctx, label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3179 | if (status == 0) { |
| 3180 | nfs_setattr_update_inode(state->inode, sattr, |
| 3181 | opendata->o_res.f_attr); |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3182 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, |
| 3183 | opendata->o_res.f_attr->label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3184 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3185 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3186 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3187 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3188 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3189 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3190 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3191 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3192 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3193 | opendata->f_attr.mdsthreshold = NULL; |
| 3194 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3195 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3196 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3199 | err_opendata_put: |
| 3200 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3201 | err_put_state_owner: |
| 3202 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | return status; |
| 3205 | } |
| 3206 | |
| 3207 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3208 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3209 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3210 | int flags, |
| 3211 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3212 | struct nfs4_label *label, |
| 3213 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3215 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3216 | struct nfs4_exception exception = { |
| 3217 | .interruptible = true, |
| 3218 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3220 | struct nfs4_open_createattrs c = { |
| 3221 | .label = label, |
| 3222 | .sattr = sattr, |
| 3223 | .verf = { |
| 3224 | [0] = (__u32)jiffies, |
| 3225 | [1] = (__u32)current->pid, |
| 3226 | }, |
| 3227 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | int status; |
| 3229 | |
| 3230 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3231 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3232 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3233 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | if (status == 0) |
| 3235 | break; |
| 3236 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3237 | * book-keeping w.r.t. state-changing operations |
| 3238 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3239 | * It is actually a sign of a bug on the client or on the server. |
| 3240 | * |
| 3241 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3242 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | * have unhashed the old state_owner for us, and that we can |
| 3244 | * therefore safely retry using a new one. We should still warn |
| 3245 | * the user though... |
| 3246 | */ |
| 3247 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3248 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3249 | " returned a bad sequence-id error!\n", |
| 3250 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | exception.retry = 1; |
| 3252 | continue; |
| 3253 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3254 | /* |
| 3255 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3256 | * state before it received the OPEN_CONFIRM. |
| 3257 | * Recover by retrying the request as per the discussion |
| 3258 | * on Page 181 of RFC3530. |
| 3259 | */ |
| 3260 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3261 | exception.retry = 1; |
| 3262 | continue; |
| 3263 | } |
Robert Milkowski | 924491f | 2020-01-28 08:37:47 +0000 | [diff] [blame] | 3264 | if (status == -NFS4ERR_EXPIRED) { |
| 3265 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 3266 | exception.retry = 1; |
| 3267 | continue; |
| 3268 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3269 | if (status == -EAGAIN) { |
| 3270 | /* We must have found a delegation */ |
| 3271 | exception.retry = 1; |
| 3272 | continue; |
| 3273 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3274 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3275 | continue; |
| 3276 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | status, &exception)); |
| 3278 | } while (exception.retry); |
| 3279 | return res; |
| 3280 | } |
| 3281 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3282 | static int _nfs4_do_setattr(struct inode *inode, |
| 3283 | struct nfs_setattrargs *arg, |
| 3284 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3285 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3286 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3287 | { |
| 3288 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3289 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3290 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3291 | .rpc_argp = arg, |
| 3292 | .rpc_resp = res, |
| 3293 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3294 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3295 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3296 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3297 | bool truncate; |
| 3298 | int status; |
| 3299 | |
| 3300 | nfs_fattr_init(res->fattr); |
| 3301 | |
| 3302 | /* Servers should only apply open mode checks for file size changes */ |
| 3303 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3304 | if (!truncate) { |
| 3305 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3306 | goto zero_stateid; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3307 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3308 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3309 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3310 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3311 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3312 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3313 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3314 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3315 | l_ctx = nfs_get_lock_context(ctx); |
| 3316 | if (IS_ERR(l_ctx)) |
| 3317 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3318 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3319 | &arg->stateid, &delegation_cred); |
| 3320 | nfs_put_lock_context(l_ctx); |
| 3321 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3322 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3323 | else if (status == -EAGAIN) |
| 3324 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3325 | } else { |
| 3326 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3327 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3328 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3329 | if (delegation_cred) |
| 3330 | msg.rpc_cred = delegation_cred; |
| 3331 | |
| 3332 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3333 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3334 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3335 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3336 | renew_lease(server, timestamp); |
| 3337 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3338 | return status; |
| 3339 | } |
| 3340 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3341 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3342 | struct nfs_fattr *fattr, struct iattr *sattr, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 3343 | struct nfs_open_context *ctx, struct nfs4_label *ilabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3345 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3346 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3347 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3348 | struct nfs_setattrargs arg = { |
| 3349 | .fh = NFS_FH(inode), |
| 3350 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3352 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3353 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3354 | }; |
| 3355 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | .fattr = fattr, |
| 3357 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3358 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3359 | struct nfs4_exception exception = { |
| 3360 | .state = state, |
| 3361 | .inode = inode, |
| 3362 | .stateid = &arg.stateid, |
| 3363 | }; |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3364 | unsigned long adjust_flags = NFS_INO_INVALID_CHANGE; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3365 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 3367 | if (sattr->ia_valid & (ATTR_MODE | ATTR_KILL_SUID | ATTR_KILL_SGID)) |
| 3368 | adjust_flags |= NFS_INO_INVALID_MODE; |
| 3369 | if (sattr->ia_valid & (ATTR_UID | ATTR_GID)) |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3370 | adjust_flags |= NFS_INO_INVALID_OTHER; |
| 3371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | do { |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 3373 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label), |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3374 | inode, adjust_flags); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3375 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3376 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3377 | switch (err) { |
| 3378 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3379 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3380 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3381 | "applying open mode checks to " |
| 3382 | "a SETATTR that is not " |
| 3383 | "changing file size.\n", |
| 3384 | server->nfs_client->cl_hostname); |
| 3385 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3386 | if (state && !(state->state & FMODE_WRITE)) { |
| 3387 | err = -EBADF; |
| 3388 | if (sattr->ia_valid & ATTR_OPEN) |
| 3389 | err = -EACCES; |
| 3390 | goto out; |
| 3391 | } |
| 3392 | } |
| 3393 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3395 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | return err; |
| 3397 | } |
| 3398 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3399 | static bool |
| 3400 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3401 | { |
| 3402 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3403 | return false; |
| 3404 | |
| 3405 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3406 | } |
| 3407 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3408 | /* |
| 3409 | * Update the seqid of an open stateid |
| 3410 | */ |
| 3411 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3412 | struct nfs4_state *state) |
| 3413 | { |
| 3414 | __be32 seqid_open; |
| 3415 | u32 dst_seqid; |
| 3416 | int seq; |
| 3417 | |
| 3418 | for (;;) { |
| 3419 | if (!nfs4_valid_open_stateid(state)) |
| 3420 | break; |
| 3421 | seq = read_seqbegin(&state->seqlock); |
| 3422 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3423 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3424 | if (read_seqretry(&state->seqlock, seq)) |
| 3425 | continue; |
| 3426 | break; |
| 3427 | } |
| 3428 | seqid_open = state->open_stateid.seqid; |
| 3429 | if (read_seqretry(&state->seqlock, seq)) |
| 3430 | continue; |
| 3431 | |
| 3432 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3433 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3434 | dst->seqid = seqid_open; |
| 3435 | break; |
| 3436 | } |
| 3437 | } |
| 3438 | |
| 3439 | /* |
| 3440 | * Update the seqid of an open stateid after receiving |
| 3441 | * NFS4ERR_OLD_STATEID |
| 3442 | */ |
| 3443 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3444 | struct nfs4_state *state) |
| 3445 | { |
| 3446 | __be32 seqid_open; |
| 3447 | u32 dst_seqid; |
| 3448 | bool ret; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3449 | int seq, status = -EAGAIN; |
| 3450 | DEFINE_WAIT(wait); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3451 | |
| 3452 | for (;;) { |
| 3453 | ret = false; |
| 3454 | if (!nfs4_valid_open_stateid(state)) |
| 3455 | break; |
| 3456 | seq = read_seqbegin(&state->seqlock); |
| 3457 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3458 | if (read_seqretry(&state->seqlock, seq)) |
| 3459 | continue; |
| 3460 | break; |
| 3461 | } |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3462 | |
| 3463 | write_seqlock(&state->seqlock); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3464 | seqid_open = state->open_stateid.seqid; |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3465 | |
| 3466 | dst_seqid = be32_to_cpu(dst->seqid); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3467 | |
| 3468 | /* Did another OPEN bump the state's seqid? try again: */ |
| 3469 | if ((s32)(be32_to_cpu(seqid_open) - dst_seqid) > 0) { |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3470 | dst->seqid = seqid_open; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3471 | write_sequnlock(&state->seqlock); |
| 3472 | ret = true; |
| 3473 | break; |
| 3474 | } |
| 3475 | |
| 3476 | /* server says we're behind but we haven't seen the update yet */ |
| 3477 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 3478 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 3479 | write_sequnlock(&state->seqlock); |
| 3480 | trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); |
| 3481 | |
zhouchuangao | bb00238 | 2021-05-09 19:34:37 -0700 | [diff] [blame] | 3482 | if (fatal_signal_pending(current)) |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3483 | status = -EINTR; |
| 3484 | else |
| 3485 | if (schedule_timeout(5*HZ) != 0) |
| 3486 | status = 0; |
| 3487 | |
| 3488 | finish_wait(&state->waitq, &wait); |
| 3489 | |
| 3490 | if (!status) |
| 3491 | continue; |
| 3492 | if (status == -EINTR) |
| 3493 | break; |
| 3494 | |
| 3495 | /* we slept the whole 5 seconds, we must have lost a seqid */ |
| 3496 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3497 | ret = true; |
| 3498 | break; |
| 3499 | } |
| 3500 | |
| 3501 | return ret; |
| 3502 | } |
| 3503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | struct nfs4_closedata { |
| 3505 | struct inode *inode; |
| 3506 | struct nfs4_state *state; |
| 3507 | struct nfs_closeargs arg; |
| 3508 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3509 | struct { |
| 3510 | struct nfs4_layoutreturn_args arg; |
| 3511 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3512 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3513 | u32 roc_barrier; |
| 3514 | bool roc; |
| 3515 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3516 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3517 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | }; |
| 3519 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3520 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3521 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3522 | struct nfs4_closedata *calldata = data; |
| 3523 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3524 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3525 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3526 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3527 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3528 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3529 | nfs4_put_open_state(calldata->state); |
| 3530 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3531 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3532 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3533 | kfree(calldata); |
| 3534 | } |
| 3535 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3536 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3538 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3541 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3542 | struct nfs4_exception exception = { |
| 3543 | .state = state, |
| 3544 | .inode = calldata->inode, |
| 3545 | .stateid = &calldata->arg.stateid, |
| 3546 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3548 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3549 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3550 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3551 | |
| 3552 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 3553 | if (pnfs_roc_done(task, &calldata->arg.lr_args, &calldata->res.lr_res, |
| 3554 | &calldata->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3555 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3556 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3557 | /* 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] | 3558 | * the state_owner. we keep this around to process errors |
| 3559 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | switch (task->tk_status) { |
| 3561 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3562 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3563 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3564 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3565 | case -NFS4ERR_ACCESS: |
| 3566 | if (calldata->arg.bitmask != NULL) { |
| 3567 | calldata->arg.bitmask = NULL; |
| 3568 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3569 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3570 | |
| 3571 | } |
| 3572 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3573 | case -NFS4ERR_OLD_STATEID: |
| 3574 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3575 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3576 | state)) |
| 3577 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3578 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3579 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3581 | case -NFS4ERR_EXPIRED: |
| 3582 | nfs4_free_revoked_stateid(server, |
| 3583 | &calldata->arg.stateid, |
| 3584 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3585 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3586 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3587 | if (calldata->arg.fmode == 0) |
| 3588 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3589 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3591 | task->tk_status = nfs4_async_handle_exception(task, |
| 3592 | server, task->tk_status, &exception); |
| 3593 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3594 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3596 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3597 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3598 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3599 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3600 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3601 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 3602 | dprintk("%s: ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3603 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3604 | out_restart: |
| 3605 | task->tk_status = 0; |
| 3606 | rpc_restart_call_prepare(task); |
| 3607 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3610 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3612 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3613 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3614 | struct inode *inode = calldata->inode; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3615 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3616 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3617 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3618 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3619 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3620 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3621 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3622 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3623 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3624 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3625 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3626 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3627 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3628 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3629 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3630 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3631 | if (state->n_rdonly == 0) |
| 3632 | call_close |= is_rdonly; |
| 3633 | else if (is_rdonly) |
| 3634 | calldata->arg.fmode |= FMODE_READ; |
| 3635 | if (state->n_wronly == 0) |
| 3636 | call_close |= is_wronly; |
| 3637 | else if (is_wronly) |
| 3638 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3639 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3640 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3641 | } else if (is_rdwr) |
| 3642 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3643 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3644 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3645 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3646 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3647 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3648 | |
| 3649 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3650 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3651 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3652 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3653 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3654 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3655 | nfs_release_seqid(calldata->arg.seqid); |
| 3656 | goto out_wait; |
| 3657 | } |
| 3658 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3659 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3660 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3661 | calldata->arg.lr_args = NULL; |
| 3662 | calldata->res.lr_res = NULL; |
| 3663 | } |
| 3664 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3665 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3666 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3667 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3668 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3669 | /* Close-to-open cache consistency revalidation */ |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3670 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3671 | nfs4_bitmask_set(calldata->arg.bitmask_store, |
| 3672 | server->cache_consistency_bitmask, |
| 3673 | inode, server, NULL); |
| 3674 | calldata->arg.bitmask = calldata->arg.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3675 | } else |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3676 | calldata->arg.bitmask = NULL; |
| 3677 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3678 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3679 | calldata->arg.share_access = |
| 3680 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3681 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3682 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3683 | if (calldata->res.fattr == NULL) |
| 3684 | calldata->arg.bitmask = NULL; |
| 3685 | else if (calldata->arg.bitmask == NULL) |
| 3686 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3687 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3688 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3689 | &calldata->arg.seq_args, |
| 3690 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3691 | task) != 0) |
| 3692 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3693 | return; |
| 3694 | out_no_action: |
| 3695 | task->tk_action = NULL; |
| 3696 | out_wait: |
| 3697 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | } |
| 3699 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3700 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3701 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3702 | .rpc_call_done = nfs4_close_done, |
| 3703 | .rpc_release = nfs4_free_closedata, |
| 3704 | }; |
| 3705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | /* |
| 3707 | * It is possible for data to be read/written from a mem-mapped file |
| 3708 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3709 | * This means that we can't safely call nfsv4 close on a file until |
| 3710 | * the inode is cleared. This in turn means that we are not good |
| 3711 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3712 | * share state even when we are done with one of the three share |
| 3713 | * stateid's in the inode. |
| 3714 | * |
| 3715 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3716 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3717 | 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] | 3718 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3719 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3720 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3722 | struct nfs4_state_owner *sp = state->owner; |
| 3723 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3724 | struct rpc_message msg = { |
| 3725 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3726 | .rpc_cred = state->owner->so_cred, |
| 3727 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3728 | struct rpc_task_setup task_setup_data = { |
| 3729 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3730 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3731 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3732 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 3733 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3734 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3735 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 3737 | if (server->nfs_client->cl_minorversion) |
| 3738 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
| 3739 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3740 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3741 | &task_setup_data.rpc_client, &msg); |
| 3742 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3743 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3745 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3746 | 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] | 3747 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3749 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3750 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3751 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3753 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3754 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3755 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3756 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3757 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3758 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3759 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3760 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3761 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3762 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3763 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3764 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3765 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3766 | if (calldata->lr.roc) { |
| 3767 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3768 | calldata->res.lr_res = &calldata->lr.res; |
| 3769 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3770 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3771 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3772 | msg.rpc_argp = &calldata->arg; |
| 3773 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3774 | task_setup_data.callback_data = calldata; |
| 3775 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3776 | if (IS_ERR(task)) |
| 3777 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3778 | status = 0; |
| 3779 | if (wait) |
| 3780 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3781 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3782 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3783 | out_free_calldata: |
| 3784 | kfree(calldata); |
| 3785 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3786 | nfs4_put_open_state(state); |
| 3787 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3788 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | } |
| 3790 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3791 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3792 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3793 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3796 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3797 | |
| 3798 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3800 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3801 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3802 | |
| 3803 | nfs4_label_release_security(label); |
| 3804 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3805 | if (IS_ERR(state)) |
| 3806 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3807 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | } |
| 3809 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3810 | 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] | 3811 | { |
| 3812 | if (ctx->state == NULL) |
| 3813 | return; |
| 3814 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3815 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3816 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3817 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3820 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3821 | #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] | 3822 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3825 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3826 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3827 | struct nfs4_server_caps_arg args = { |
| 3828 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3829 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3830 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | struct nfs4_server_caps_res res = {}; |
| 3832 | struct rpc_message msg = { |
| 3833 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3834 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | .rpc_resp = &res, |
| 3836 | }; |
| 3837 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3838 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3840 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3841 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3842 | FATTR4_WORD0_LINK_SUPPORT | |
| 3843 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3844 | FATTR4_WORD0_ACLSUPPORT; |
| 3845 | if (minorversion) |
| 3846 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3847 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3848 | 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] | 3849 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3850 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3851 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3852 | case 0: |
| 3853 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3854 | res.attr_bitmask[2] = 0; |
| 3855 | break; |
| 3856 | case 1: |
| 3857 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3858 | break; |
| 3859 | case 2: |
| 3860 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3861 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | ce62b11 | 2018-03-05 15:01:18 -0500 | [diff] [blame] | 3863 | server->caps &= ~(NFS_CAP_ACLS | NFS_CAP_HARDLINKS | |
| 3864 | NFS_CAP_SYMLINKS| NFS_CAP_SECURITY_LABEL); |
| 3865 | server->fattr_valid = NFS_ATTR_FATTR_V4; |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3866 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3867 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | server->caps |= NFS_CAP_ACLS; |
| 3869 | if (res.has_links != 0) |
| 3870 | server->caps |= NFS_CAP_HARDLINKS; |
| 3871 | if (res.has_symlinks != 0) |
| 3872 | server->caps |= NFS_CAP_SYMLINKS; |
Scott Mayhew | 0b4f132 | 2021-06-02 13:13:11 -0400 | [diff] [blame] | 3873 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3874 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3875 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3876 | #endif |
Trond Myklebust | ce62b11 | 2018-03-05 15:01:18 -0500 | [diff] [blame] | 3877 | if (!(res.attr_bitmask[0] & FATTR4_WORD0_FILEID)) |
| 3878 | server->fattr_valid &= ~NFS_ATTR_FATTR_FILEID; |
| 3879 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_MODE)) |
| 3880 | server->fattr_valid &= ~NFS_ATTR_FATTR_MODE; |
| 3881 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)) |
| 3882 | server->fattr_valid &= ~NFS_ATTR_FATTR_NLINK; |
| 3883 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_OWNER)) |
| 3884 | server->fattr_valid &= ~(NFS_ATTR_FATTR_OWNER | |
| 3885 | NFS_ATTR_FATTR_OWNER_NAME); |
| 3886 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)) |
| 3887 | server->fattr_valid &= ~(NFS_ATTR_FATTR_GROUP | |
| 3888 | NFS_ATTR_FATTR_GROUP_NAME); |
| 3889 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_SPACE_USED)) |
| 3890 | server->fattr_valid &= ~NFS_ATTR_FATTR_SPACE_USED; |
| 3891 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)) |
| 3892 | server->fattr_valid &= ~NFS_ATTR_FATTR_ATIME; |
| 3893 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)) |
| 3894 | server->fattr_valid &= ~NFS_ATTR_FATTR_CTIME; |
| 3895 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)) |
| 3896 | server->fattr_valid &= ~NFS_ATTR_FATTR_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3897 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3898 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3899 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3900 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3901 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3902 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3903 | 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] | 3904 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3905 | |
| 3906 | /* Avoid a regression due to buggy server */ |
| 3907 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3908 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3909 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3910 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3913 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | return status; |
| 3917 | } |
| 3918 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3919 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3921 | struct nfs4_exception exception = { |
| 3922 | .interruptible = true, |
| 3923 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | int err; |
Anna Schumaker | 01dde76 | 2021-10-14 13:55:04 -0400 | [diff] [blame] | 3925 | |
| 3926 | nfs4_server_set_init_caps(server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | do { |
| 3928 | err = nfs4_handle_exception(server, |
| 3929 | _nfs4_server_capabilities(server, fhandle), |
| 3930 | &exception); |
| 3931 | } while (exception.retry); |
| 3932 | return err; |
| 3933 | } |
| 3934 | |
| 3935 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3936 | struct nfs_fsinfo *info) |
| 3937 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3938 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3940 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | }; |
| 3942 | struct nfs4_lookup_res res = { |
| 3943 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3944 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | .fh = fhandle, |
| 3946 | }; |
| 3947 | struct rpc_message msg = { |
| 3948 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3949 | .rpc_argp = &args, |
| 3950 | .rpc_resp = &res, |
| 3951 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3952 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3953 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3954 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3955 | /* |
| 3956 | * Process the label in the upcoming getfattr |
| 3957 | */ |
| 3958 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3959 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3960 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3961 | 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] | 3962 | } |
| 3963 | |
| 3964 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3965 | struct nfs_fsinfo *info) |
| 3966 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3967 | struct nfs4_exception exception = { |
| 3968 | .interruptible = true, |
| 3969 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | int err; |
| 3971 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3972 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3973 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3974 | switch (err) { |
| 3975 | case 0: |
| 3976 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3977 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3978 | default: |
| 3979 | err = nfs4_handle_exception(server, err, &exception); |
| 3980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3982 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | return err; |
| 3984 | } |
| 3985 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3986 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3987 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3988 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3989 | struct rpc_auth_create_args auth_args = { |
| 3990 | .pseudoflavor = flavor, |
| 3991 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3992 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3993 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3994 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3995 | if (IS_ERR(auth)) |
| 3996 | return -EACCES; |
| 3997 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3998 | } |
| 3999 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4000 | /* |
| 4001 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 4002 | * |
| 4003 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 4004 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 4005 | * |
| 4006 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 4007 | * negative errno value. |
| 4008 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4009 | 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] | 4010 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4012 | /* Per 3530bis 15.33.5 */ |
| 4013 | static const rpc_authflavor_t flav_array[] = { |
| 4014 | RPC_AUTH_GSS_KRB5P, |
| 4015 | RPC_AUTH_GSS_KRB5I, |
| 4016 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 4017 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4018 | RPC_AUTH_NULL, |
| 4019 | }; |
| 4020 | int status = -EPERM; |
| 4021 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 4023 | if (server->auth_info.flavor_len > 0) { |
| 4024 | /* try each flavor specified by user */ |
| 4025 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 4026 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4027 | server->auth_info.flavors[i]); |
| 4028 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4029 | continue; |
| 4030 | break; |
| 4031 | } |
| 4032 | } else { |
| 4033 | /* no flavors specified by user, try default list */ |
| 4034 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 4035 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4036 | flav_array[i]); |
| 4037 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4038 | continue; |
| 4039 | break; |
| 4040 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4041 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4042 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4043 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 4044 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4045 | * to access the mount. It could also mean that we tried to mount |
| 4046 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 4047 | * existing mount programs don't handle -EACCES very well so it should |
| 4048 | * be mapped to -EPERM instead. |
| 4049 | */ |
| 4050 | if (status == -EACCES) |
| 4051 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4052 | return status; |
| 4053 | } |
| 4054 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4055 | /** |
| 4056 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 4057 | * @server: initialized nfs_server handle |
| 4058 | * @fhandle: we fill in the pseudo-fs root file handle |
| 4059 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4060 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4061 | * |
| 4062 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4063 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 4064 | 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] | 4065 | struct nfs_fsinfo *info, |
| 4066 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4067 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4068 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4069 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4070 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4071 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4072 | |
| 4073 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 4074 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 4075 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | if (status == 0) |
| 4078 | status = nfs4_server_capabilities(server, fhandle); |
| 4079 | if (status == 0) |
| 4080 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4081 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 4082 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4085 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 4086 | struct nfs_fsinfo *info) |
| 4087 | { |
| 4088 | int error; |
| 4089 | struct nfs_fattr *fattr = info->fattr; |
| 4090 | |
| 4091 | error = nfs4_server_capabilities(server, mntfh); |
| 4092 | if (error < 0) { |
| 4093 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 4094 | return error; |
| 4095 | } |
| 4096 | |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4097 | error = nfs4_proc_getattr(server, mntfh, fattr, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4098 | if (error < 0) { |
| 4099 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4100 | goto out; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4104 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4105 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4106 | |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4107 | out: |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4108 | return error; |
| 4109 | } |
| 4110 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4111 | /* |
| 4112 | * Get locations and (maybe) other attributes of a referral. |
| 4113 | * Note that we'll actually follow the referral later when |
| 4114 | * we detect fsid mismatch in inode revalidation |
| 4115 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4116 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4117 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4118 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4119 | { |
| 4120 | int status = -ENOMEM; |
| 4121 | struct page *page = NULL; |
| 4122 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4123 | |
| 4124 | page = alloc_page(GFP_KERNEL); |
| 4125 | if (page == NULL) |
| 4126 | goto out; |
| 4127 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4128 | if (locations == NULL) |
| 4129 | goto out; |
| 4130 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4131 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4132 | if (status != 0) |
| 4133 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4134 | |
| 4135 | /* |
| 4136 | * If the fsid didn't change, this is a migration event, not a |
| 4137 | * referral. Cause us to drop into the exception handler, which |
| 4138 | * will kick off migration recovery. |
| 4139 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4140 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4141 | dprintk("%s: server did not return a different fsid for" |
| 4142 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4143 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4144 | goto out; |
| 4145 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4146 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4147 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4148 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4149 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4150 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4151 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4152 | out: |
| 4153 | if (page) |
| 4154 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4155 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4156 | return status; |
| 4157 | } |
| 4158 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4159 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4160 | struct nfs_fattr *fattr, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4162 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | struct nfs4_getattr_arg args = { |
| 4164 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4165 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | }; |
| 4167 | struct nfs4_getattr_res res = { |
| 4168 | .fattr = fattr, |
| 4169 | .server = server, |
| 4170 | }; |
| 4171 | struct rpc_message msg = { |
| 4172 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4173 | .rpc_argp = &args, |
| 4174 | .rpc_resp = &res, |
| 4175 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4176 | unsigned short task_flags = 0; |
| 4177 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 4178 | if (nfs4_has_session(server->nfs_client)) |
| 4179 | task_flags = RPC_TASK_MOVEABLE; |
| 4180 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4181 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4182 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4183 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4184 | |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4185 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label), inode, 0); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4186 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4187 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4188 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4189 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | } |
| 4191 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4192 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4193 | struct nfs_fattr *fattr, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4195 | struct nfs4_exception exception = { |
| 4196 | .interruptible = true, |
| 4197 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | int err; |
| 4199 | do { |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4200 | err = _nfs4_proc_getattr(server, fhandle, fattr, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4201 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4202 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | &exception); |
| 4204 | } while (exception.retry); |
| 4205 | return err; |
| 4206 | } |
| 4207 | |
| 4208 | /* |
| 4209 | * The file is not closed if it is opened due to the a request to change |
| 4210 | * the size of the file. The open call will not be needed once the |
| 4211 | * VFS layer lookup-intents are implemented. |
| 4212 | * |
| 4213 | * Close is called when the inode is destroyed. |
| 4214 | * If we haven't opened the file for O_WRONLY, we |
| 4215 | * need to in the size_change case to obtain a stateid. |
| 4216 | * |
| 4217 | * Got race? |
| 4218 | * Because OPEN is always done by name in nfsv4, it is |
| 4219 | * possible that we opened a different file by the same |
| 4220 | * name. We can recognize this race condition, but we |
| 4221 | * can't do anything about it besides returning an error. |
| 4222 | * |
| 4223 | * This will be fixed with VFS changes (lookup-intent). |
| 4224 | */ |
| 4225 | static int |
| 4226 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4227 | struct iattr *sattr) |
| 4228 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4229 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4230 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4231 | struct nfs_open_context *ctx = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | int status; |
| 4233 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4234 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4235 | sattr->ia_valid & ATTR_SIZE && |
| 4236 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4237 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4238 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4239 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4241 | /* Deal with open(O_TRUNC) */ |
| 4242 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4243 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4244 | |
| 4245 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4246 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4247 | return 0; |
| 4248 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4249 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4250 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4251 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4252 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4253 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4254 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4255 | } |
| 4256 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4257 | /* Return any delegations if we're going to change ACLs */ |
| 4258 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4259 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4260 | |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 4261 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4262 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4263 | nfs_setattr_update_inode(inode, sattr, fattr); |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 4264 | nfs_setsecurity(inode, fattr, fattr->label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | return status; |
| 4267 | } |
| 4268 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4269 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4270 | struct dentry *dentry, struct nfs_fh *fhandle, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4271 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4272 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4273 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4274 | int status; |
| 4275 | struct nfs4_lookup_arg args = { |
| 4276 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4277 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4278 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4279 | }; |
| 4280 | struct nfs4_lookup_res res = { |
| 4281 | .server = server, |
| 4282 | .fattr = fattr, |
| 4283 | .fh = fhandle, |
| 4284 | }; |
| 4285 | struct rpc_message msg = { |
| 4286 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4287 | .rpc_argp = &args, |
| 4288 | .rpc_resp = &res, |
| 4289 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4290 | unsigned short task_flags = 0; |
| 4291 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 4292 | if (server->nfs_client->cl_minorversion) |
| 4293 | task_flags = RPC_TASK_MOVEABLE; |
| 4294 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4295 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4296 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4297 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4298 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4299 | args.bitmask = nfs4_bitmask(server, fattr->label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4300 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4301 | nfs_fattr_init(fattr); |
| 4302 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4303 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4304 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4305 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4306 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | dprintk("NFS reply lookup: %d\n", status); |
| 4308 | return status; |
| 4309 | } |
| 4310 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4311 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4312 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4313 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4314 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4315 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4316 | fattr->nlink = 2; |
| 4317 | } |
| 4318 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4319 | 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] | 4320 | struct dentry *dentry, struct nfs_fh *fhandle, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4321 | struct nfs_fattr *fattr) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4322 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4323 | struct nfs4_exception exception = { |
| 4324 | .interruptible = true, |
| 4325 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4326 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4327 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4328 | int err; |
| 4329 | do { |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4330 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4331 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4332 | switch (err) { |
| 4333 | case -NFS4ERR_BADNAME: |
| 4334 | err = -ENOENT; |
| 4335 | goto out; |
| 4336 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4337 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4338 | if (err == -NFS4ERR_MOVED) |
| 4339 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4340 | goto out; |
| 4341 | case -NFS4ERR_WRONGSEC: |
| 4342 | err = -EPERM; |
| 4343 | if (client != *clnt) |
| 4344 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4345 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4346 | if (IS_ERR(client)) |
| 4347 | return PTR_ERR(client); |
| 4348 | |
| 4349 | exception.retry = 1; |
| 4350 | break; |
| 4351 | default: |
| 4352 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4353 | } |
| 4354 | } while (exception.retry); |
| 4355 | |
| 4356 | out: |
| 4357 | if (err == 0) |
| 4358 | *clnt = client; |
| 4359 | else if (client != *clnt) |
| 4360 | rpc_shutdown_client(client); |
| 4361 | |
| 4362 | return err; |
| 4363 | } |
| 4364 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4365 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4366 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4368 | int status; |
| 4369 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4370 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4371 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4372 | if (client != NFS_CLIENT(dir)) { |
| 4373 | rpc_shutdown_client(client); |
| 4374 | nfs_fixup_secinfo_attributes(fattr); |
| 4375 | } |
| 4376 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | } |
| 4378 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4379 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4380 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4381 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4382 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4383 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4384 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4385 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4386 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4387 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4388 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4389 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4390 | } |
| 4391 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4392 | static int _nfs4_proc_lookupp(struct inode *inode, |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4393 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4394 | { |
| 4395 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4396 | struct nfs_server *server = NFS_SERVER(inode); |
| 4397 | int status; |
| 4398 | struct nfs4_lookupp_arg args = { |
| 4399 | .bitmask = server->attr_bitmask, |
| 4400 | .fh = NFS_FH(inode), |
| 4401 | }; |
| 4402 | struct nfs4_lookupp_res res = { |
| 4403 | .server = server, |
| 4404 | .fattr = fattr, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4405 | .fh = fhandle, |
| 4406 | }; |
| 4407 | struct rpc_message msg = { |
| 4408 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4409 | .rpc_argp = &args, |
| 4410 | .rpc_resp = &res, |
| 4411 | }; |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4412 | unsigned short task_flags = 0; |
| 4413 | |
| 4414 | if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL) |
| 4415 | task_flags |= RPC_TASK_TIMEOUT; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4416 | |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4417 | args.bitmask = nfs4_bitmask(server, fattr->label); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4418 | |
| 4419 | nfs_fattr_init(fattr); |
| 4420 | |
| 4421 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4422 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4423 | &res.seq_res, task_flags); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4424 | dprintk("NFS reply lookupp: %d\n", status); |
| 4425 | return status; |
| 4426 | } |
| 4427 | |
| 4428 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4429 | struct nfs_fattr *fattr) |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4430 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4431 | struct nfs4_exception exception = { |
| 4432 | .interruptible = true, |
| 4433 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4434 | int err; |
| 4435 | do { |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4436 | err = _nfs4_proc_lookupp(inode, fhandle, fattr); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4437 | trace_nfs4_lookupp(inode, err); |
| 4438 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4439 | &exception); |
| 4440 | } while (exception.retry); |
| 4441 | return err; |
| 4442 | } |
| 4443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4445 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4446 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | struct nfs4_accessargs args = { |
| 4448 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4449 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4451 | struct nfs4_accessres res = { |
| 4452 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4453 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | struct rpc_message msg = { |
| 4455 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4456 | .rpc_argp = &args, |
| 4457 | .rpc_resp = &res, |
| 4458 | .rpc_cred = entry->cred, |
| 4459 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4460 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4462 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4463 | res.fattr = nfs_alloc_fattr(); |
| 4464 | if (res.fattr == NULL) |
| 4465 | return -ENOMEM; |
| 4466 | args.bitmask = server->cache_consistency_bitmask; |
| 4467 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4468 | 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] | 4469 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4470 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4471 | if (res.fattr) |
| 4472 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4474 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | return status; |
| 4476 | } |
| 4477 | |
| 4478 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4479 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4480 | struct nfs4_exception exception = { |
| 4481 | .interruptible = true, |
| 4482 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | int err; |
| 4484 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4485 | err = _nfs4_proc_access(inode, entry); |
| 4486 | trace_nfs4_access(inode, err); |
| 4487 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | &exception); |
| 4489 | } while (exception.retry); |
| 4490 | return err; |
| 4491 | } |
| 4492 | |
| 4493 | /* |
| 4494 | * TODO: For the time being, we don't try to get any attributes |
| 4495 | * along with any of the zero-copy operations READ, READDIR, |
| 4496 | * READLINK, WRITE. |
| 4497 | * |
| 4498 | * In the case of the first three, we want to put the GETATTR |
| 4499 | * after the read-type operation -- this is because it is hard |
| 4500 | * to predict the length of a GETATTR response in v4, and thus |
| 4501 | * align the READ data correctly. This means that the GETATTR |
| 4502 | * may end up partially falling into the page cache, and we should |
| 4503 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4504 | * To do this efficiently, we need to know the total length |
| 4505 | * of data received, which doesn't seem to be available outside |
| 4506 | * of the RPC layer. |
| 4507 | * |
| 4508 | * In the case of WRITE, we also want to put the GETATTR after |
| 4509 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4510 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | * |
| 4512 | * Both of these changes to the XDR layer would in fact be quite |
| 4513 | * minor, but I decided to leave them for a subsequent patch. |
| 4514 | */ |
| 4515 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4516 | unsigned int pgbase, unsigned int pglen) |
| 4517 | { |
| 4518 | struct nfs4_readlink args = { |
| 4519 | .fh = NFS_FH(inode), |
| 4520 | .pgbase = pgbase, |
| 4521 | .pglen = pglen, |
| 4522 | .pages = &page, |
| 4523 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4524 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | struct rpc_message msg = { |
| 4526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4527 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4528 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | }; |
| 4530 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4531 | 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] | 4532 | } |
| 4533 | |
| 4534 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4535 | unsigned int pgbase, unsigned int pglen) |
| 4536 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4537 | struct nfs4_exception exception = { |
| 4538 | .interruptible = true, |
| 4539 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | int err; |
| 4541 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4542 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4543 | trace_nfs4_readlink(inode, err); |
| 4544 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | &exception); |
| 4546 | } while (exception.retry); |
| 4547 | return err; |
| 4548 | } |
| 4549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4550 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4551 | * 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] | 4552 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | static int |
| 4554 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4555 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4557 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4558 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4559 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | int status = 0; |
| 4562 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4563 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4564 | if (IS_ERR(ctx)) |
| 4565 | return PTR_ERR(ctx); |
| 4566 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4567 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4568 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4569 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4570 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4571 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | if (IS_ERR(state)) { |
| 4573 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4574 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4577 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4578 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | return status; |
| 4580 | } |
| 4581 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4582 | static int |
| 4583 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4585 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4586 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4588 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4590 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4591 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4592 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4594 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4595 | .rpc_argp = &args, |
| 4596 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4598 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4599 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4600 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4601 | 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] | 4602 | if (status == 0) { |
| 4603 | spin_lock(&dir->i_lock); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4604 | /* Removing a directory decrements nlink in the parent */ |
| 4605 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4606 | nfs4_dec_nlink_locked(dir); |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 4607 | nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, |
| 4608 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4609 | spin_unlock(&dir->i_lock); |
| 4610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | return status; |
| 4612 | } |
| 4613 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4614 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4615 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4616 | struct nfs4_exception exception = { |
| 4617 | .interruptible = true, |
| 4618 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4619 | struct inode *inode = d_inode(dentry); |
| 4620 | int err; |
| 4621 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4622 | if (inode) { |
| 4623 | if (inode->i_nlink == 1) |
| 4624 | nfs4_inode_return_delegation(inode); |
| 4625 | else |
| 4626 | nfs4_inode_make_writeable(inode); |
| 4627 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4628 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4629 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4630 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4631 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4632 | &exception); |
| 4633 | } while (exception.retry); |
| 4634 | return err; |
| 4635 | } |
| 4636 | |
| 4637 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4639 | struct nfs4_exception exception = { |
| 4640 | .interruptible = true, |
| 4641 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4645 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4646 | trace_nfs4_remove(dir, name, err); |
| 4647 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | &exception); |
| 4649 | } while (exception.retry); |
| 4650 | return err; |
| 4651 | } |
| 4652 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4653 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4654 | struct dentry *dentry, |
| 4655 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4657 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4658 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4660 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4662 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4663 | |
| 4664 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4665 | |
| 4666 | if (inode) |
| 4667 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | } |
| 4669 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4670 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4671 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4672 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4673 | &data->args.seq_args, |
| 4674 | &data->res.seq_res, |
| 4675 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | } |
| 4677 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4678 | 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] | 4679 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4680 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4681 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4682 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4683 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4684 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4685 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4686 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4687 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4688 | if (task->tk_status == 0) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4689 | nfs4_update_changeattr(dir, &res->cinfo, |
| 4690 | res->dir_attr->time_start, |
| 4691 | NFS_INO_INVALID_DATA); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4692 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4693 | } |
| 4694 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4695 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4696 | struct dentry *old_dentry, |
| 4697 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4698 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4699 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4700 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4701 | struct inode *old_inode = d_inode(old_dentry); |
| 4702 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4703 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4704 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4705 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4706 | if (new_inode) |
| 4707 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4708 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4709 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4710 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4711 | } |
| 4712 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4713 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4714 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4715 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4716 | &data->args.seq_args, |
| 4717 | &data->res.seq_res, |
| 4718 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4722 | struct inode *new_dir) |
| 4723 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4724 | struct nfs_renamedata *data = task->tk_calldata; |
| 4725 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4726 | |
| 4727 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4728 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4729 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4730 | return 0; |
| 4731 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4732 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4733 | if (new_dir != old_dir) { |
| 4734 | /* Note: If we moved a directory, nlink will change */ |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4735 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4736 | res->old_fattr->time_start, |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 4737 | NFS_INO_INVALID_NLINK | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4738 | NFS_INO_INVALID_DATA); |
| 4739 | nfs4_update_changeattr(new_dir, &res->new_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4740 | res->new_fattr->time_start, |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 4741 | NFS_INO_INVALID_NLINK | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4742 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4743 | } else |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4744 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4745 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4746 | NFS_INO_INVALID_DATA); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4747 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4748 | return 1; |
| 4749 | } |
| 4750 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4751 | 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] | 4752 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4753 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4754 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | struct nfs4_link_arg arg = { |
| 4756 | .fh = NFS_FH(inode), |
| 4757 | .dir_fh = NFS_FH(dir), |
| 4758 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4759 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4761 | struct nfs4_link_res res = { |
| 4762 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4763 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | struct rpc_message msg = { |
| 4765 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4766 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4767 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4769 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | |
Anna Schumaker | aa7ca3b | 2021-10-22 13:11:03 -0400 | [diff] [blame] | 4771 | res.fattr = nfs_alloc_fattr_with_label(server); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4772 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4773 | goto out; |
| 4774 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4775 | nfs4_inode_make_writeable(inode); |
Anna Schumaker | aa7ca3b | 2021-10-22 13:11:03 -0400 | [diff] [blame] | 4776 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, res.fattr->label), inode, |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 4777 | NFS_INO_INVALID_CHANGE); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4778 | 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] | 4779 | if (!status) { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4780 | nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, |
| 4781 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 1301e42 | 2021-04-01 14:57:56 -0400 | [diff] [blame] | 4782 | nfs4_inc_nlink(inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4783 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4784 | if (!status) |
Anna Schumaker | aa7ca3b | 2021-10-22 13:11:03 -0400 | [diff] [blame] | 4785 | nfs_setsecurity(inode, res.fattr, res.fattr->label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4786 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4787 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4788 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4789 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | return status; |
| 4791 | } |
| 4792 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4793 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4795 | struct nfs4_exception exception = { |
| 4796 | .interruptible = true, |
| 4797 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | int err; |
| 4799 | do { |
| 4800 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4801 | _nfs4_proc_link(inode, dir, name), |
| 4802 | &exception); |
| 4803 | } while (exception.retry); |
| 4804 | return err; |
| 4805 | } |
| 4806 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4807 | struct nfs4_createdata { |
| 4808 | struct rpc_message msg; |
| 4809 | struct nfs4_create_arg arg; |
| 4810 | struct nfs4_create_res res; |
| 4811 | struct nfs_fh fh; |
| 4812 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4813 | }; |
| 4814 | |
| 4815 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4816 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4817 | { |
| 4818 | struct nfs4_createdata *data; |
| 4819 | |
| 4820 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4821 | if (data != NULL) { |
| 4822 | struct nfs_server *server = NFS_SERVER(dir); |
| 4823 | |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4824 | data->fattr.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4825 | if (IS_ERR(data->fattr.label)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4826 | goto out_free; |
| 4827 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4828 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4829 | data->msg.rpc_argp = &data->arg; |
| 4830 | data->msg.rpc_resp = &data->res; |
| 4831 | data->arg.dir_fh = NFS_FH(dir); |
| 4832 | data->arg.server = server; |
| 4833 | data->arg.name = name; |
| 4834 | data->arg.attrs = sattr; |
| 4835 | data->arg.ftype = ftype; |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4836 | data->arg.bitmask = nfs4_bitmask(server, data->fattr.label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4837 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4838 | data->res.server = server; |
| 4839 | data->res.fh = &data->fh; |
| 4840 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4841 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4842 | } |
| 4843 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4844 | out_free: |
| 4845 | kfree(data); |
| 4846 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4850 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4851 | 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] | 4852 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4853 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4854 | spin_lock(&dir->i_lock); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4855 | /* Creating a directory bumps nlink in the parent */ |
| 4856 | if (data->arg.ftype == NF4DIR) |
| 4857 | nfs4_inc_nlink_locked(dir); |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 4858 | nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, |
| 4859 | data->res.fattr->time_start, |
| 4860 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4861 | spin_unlock(&dir->i_lock); |
Anna Schumaker | d91bfc4 | 2021-10-22 13:11:09 -0400 | [diff] [blame^] | 4862 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4863 | } |
| 4864 | return status; |
| 4865 | } |
| 4866 | |
| 4867 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4868 | { |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4869 | nfs4_label_free(data->fattr.label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4870 | kfree(data); |
| 4871 | } |
| 4872 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4873 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4874 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4875 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4877 | struct nfs4_createdata *data; |
| 4878 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4880 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4881 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4882 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4883 | status = -ENOMEM; |
| 4884 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4885 | if (data == NULL) |
| 4886 | goto out; |
| 4887 | |
| 4888 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4889 | data->arg.u.symlink.pages = &page; |
| 4890 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4891 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4893 | status = nfs4_do_create(dir, dentry, data); |
| 4894 | |
| 4895 | nfs4_free_createdata(data); |
| 4896 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | return status; |
| 4898 | } |
| 4899 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4900 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4901 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4903 | struct nfs4_exception exception = { |
| 4904 | .interruptible = true, |
| 4905 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4906 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4908 | |
| 4909 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4912 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4913 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4914 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | &exception); |
| 4916 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4917 | |
| 4918 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | return err; |
| 4920 | } |
| 4921 | |
| 4922 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4923 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4925 | struct nfs4_createdata *data; |
| 4926 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4928 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4929 | if (data == NULL) |
| 4930 | goto out; |
| 4931 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4932 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4933 | status = nfs4_do_create(dir, dentry, data); |
| 4934 | |
| 4935 | nfs4_free_createdata(data); |
| 4936 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | return status; |
| 4938 | } |
| 4939 | |
| 4940 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4941 | struct iattr *sattr) |
| 4942 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4943 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4944 | struct nfs4_exception exception = { |
| 4945 | .interruptible = true, |
| 4946 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4947 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4949 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4950 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4951 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4952 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4953 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4955 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4956 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4957 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | &exception); |
| 4959 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4960 | nfs4_label_release_security(label); |
| 4961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | return err; |
| 4963 | } |
| 4964 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4965 | static int _nfs4_proc_readdir(struct nfs_readdir_arg *nr_arg, |
| 4966 | struct nfs_readdir_res *nr_res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4968 | struct inode *dir = d_inode(nr_arg->dentry); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4969 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 | struct nfs4_readdir_arg args = { |
| 4971 | .fh = NFS_FH(dir), |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4972 | .pages = nr_arg->pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4973 | .pgbase = 0, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4974 | .count = nr_arg->page_len, |
| 4975 | .plus = nr_arg->plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4976 | }; |
| 4977 | struct nfs4_readdir_res res; |
| 4978 | struct rpc_message msg = { |
| 4979 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4980 | .rpc_argp = &args, |
| 4981 | .rpc_resp = &res, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4982 | .rpc_cred = nr_arg->cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | }; |
| 4984 | int status; |
| 4985 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4986 | dprintk("%s: dentry = %pd2, cookie = %llu\n", __func__, |
| 4987 | nr_arg->dentry, (unsigned long long)nr_arg->cookie); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4988 | if (!(server->caps & NFS_CAP_SECURITY_LABEL)) |
| 4989 | args.bitmask = server->attr_bitmask_nl; |
| 4990 | else |
| 4991 | args.bitmask = server->attr_bitmask; |
| 4992 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4993 | 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] | 4994 | res.pgbase = args.pgbase; |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4995 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 4996 | &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4997 | if (status >= 0) { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4998 | memcpy(nr_res->verf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4999 | status += args.pgbase; |
| 5000 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 5001 | |
| 5002 | nfs_invalidate_atime(dir); |
| 5003 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5004 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | return status; |
| 5006 | } |
| 5007 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5008 | static int nfs4_proc_readdir(struct nfs_readdir_arg *arg, |
| 5009 | struct nfs_readdir_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5011 | struct nfs4_exception exception = { |
| 5012 | .interruptible = true, |
| 5013 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | int err; |
| 5015 | do { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5016 | err = _nfs4_proc_readdir(arg, res); |
| 5017 | trace_nfs4_readdir(d_inode(arg->dentry), err); |
| 5018 | err = nfs4_handle_exception(NFS_SERVER(d_inode(arg->dentry)), |
| 5019 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | } while (exception.retry); |
| 5021 | return err; |
| 5022 | } |
| 5023 | |
| 5024 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5025 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5027 | struct nfs4_createdata *data; |
| 5028 | int mode = sattr->ia_mode; |
| 5029 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5031 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 5032 | if (data == NULL) |
| 5033 | goto out; |
| 5034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5036 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5038 | data->arg.ftype = NF4BLK; |
| 5039 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5040 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | } |
| 5042 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5043 | data->arg.ftype = NF4CHR; |
| 5044 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5045 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5046 | } else if (!S_ISSOCK(mode)) { |
| 5047 | status = -EINVAL; |
| 5048 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5049 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5050 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5051 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5052 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5053 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5054 | nfs4_free_createdata(data); |
| 5055 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | return status; |
| 5057 | } |
| 5058 | |
| 5059 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 5060 | struct iattr *sattr, dev_t rdev) |
| 5061 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5062 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5063 | struct nfs4_exception exception = { |
| 5064 | .interruptible = true, |
| 5065 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5066 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 5068 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5069 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5070 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5071 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 5072 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5074 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 5075 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 5076 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | &exception); |
| 5078 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5079 | |
| 5080 | nfs4_label_release_security(label); |
| 5081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | return err; |
| 5083 | } |
| 5084 | |
| 5085 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5086 | struct nfs_fsstat *fsstat) |
| 5087 | { |
| 5088 | struct nfs4_statfs_arg args = { |
| 5089 | .fh = fhandle, |
| 5090 | .bitmask = server->attr_bitmask, |
| 5091 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5092 | struct nfs4_statfs_res res = { |
| 5093 | .fsstat = fsstat, |
| 5094 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | struct rpc_message msg = { |
| 5096 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5097 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5098 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | }; |
| 5100 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5101 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5102 | 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] | 5103 | } |
| 5104 | |
| 5105 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5106 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5107 | struct nfs4_exception exception = { |
| 5108 | .interruptible = true, |
| 5109 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | int err; |
| 5111 | do { |
| 5112 | err = nfs4_handle_exception(server, |
| 5113 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5114 | &exception); |
| 5115 | } while (exception.retry); |
| 5116 | return err; |
| 5117 | } |
| 5118 | |
| 5119 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5120 | struct nfs_fsinfo *fsinfo) |
| 5121 | { |
| 5122 | struct nfs4_fsinfo_arg args = { |
| 5123 | .fh = fhandle, |
| 5124 | .bitmask = server->attr_bitmask, |
| 5125 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5126 | struct nfs4_fsinfo_res res = { |
| 5127 | .fsinfo = fsinfo, |
| 5128 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | struct rpc_message msg = { |
| 5130 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5131 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5132 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | }; |
| 5134 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5135 | 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] | 5136 | } |
| 5137 | |
| 5138 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5139 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5140 | struct nfs4_exception exception = { |
| 5141 | .interruptible = true, |
| 5142 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | int err; |
| 5144 | |
| 5145 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5146 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5147 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5148 | if (err == 0) { |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 5149 | nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5150 | break; |
| 5151 | } |
| 5152 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | } while (exception.retry); |
| 5154 | return err; |
| 5155 | } |
| 5156 | |
| 5157 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5158 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5159 | int error; |
| 5160 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5161 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5162 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5163 | if (error == 0) { |
| 5164 | /* block layout checks this! */ |
| 5165 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5166 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5167 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5168 | |
| 5169 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5173 | struct nfs_pathconf *pathconf) |
| 5174 | { |
| 5175 | struct nfs4_pathconf_arg args = { |
| 5176 | .fh = fhandle, |
| 5177 | .bitmask = server->attr_bitmask, |
| 5178 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5179 | struct nfs4_pathconf_res res = { |
| 5180 | .pathconf = pathconf, |
| 5181 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | struct rpc_message msg = { |
| 5183 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5184 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5185 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | }; |
| 5187 | |
| 5188 | /* None of the pathconf attributes are mandatory to implement */ |
| 5189 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5190 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5191 | return 0; |
| 5192 | } |
| 5193 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5194 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5195 | 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] | 5196 | } |
| 5197 | |
| 5198 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5199 | struct nfs_pathconf *pathconf) |
| 5200 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5201 | struct nfs4_exception exception = { |
| 5202 | .interruptible = true, |
| 5203 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5204 | int err; |
| 5205 | |
| 5206 | do { |
| 5207 | err = nfs4_handle_exception(server, |
| 5208 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5209 | &exception); |
| 5210 | } while (exception.retry); |
| 5211 | return err; |
| 5212 | } |
| 5213 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5214 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5215 | const struct nfs_open_context *ctx, |
| 5216 | const struct nfs_lock_context *l_ctx, |
| 5217 | fmode_t fmode) |
| 5218 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5219 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5220 | } |
| 5221 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5222 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5223 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5224 | const struct nfs_open_context *ctx, |
| 5225 | const struct nfs_lock_context *l_ctx, |
| 5226 | fmode_t fmode) |
| 5227 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5228 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5229 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5230 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5231 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5232 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5233 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | static bool nfs4_error_stateid_expired(int err) |
| 5237 | { |
| 5238 | switch (err) { |
| 5239 | case -NFS4ERR_DELEG_REVOKED: |
| 5240 | case -NFS4ERR_ADMIN_REVOKED: |
| 5241 | case -NFS4ERR_BAD_STATEID: |
| 5242 | case -NFS4ERR_STALE_STATEID: |
| 5243 | case -NFS4ERR_OLD_STATEID: |
| 5244 | case -NFS4ERR_OPENMODE: |
| 5245 | case -NFS4ERR_EXPIRED: |
| 5246 | return true; |
| 5247 | } |
| 5248 | return false; |
| 5249 | } |
| 5250 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5251 | 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] | 5252 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5253 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5255 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5256 | if (task->tk_status < 0) { |
| 5257 | struct nfs4_exception exception = { |
| 5258 | .inode = hdr->inode, |
| 5259 | .state = hdr->args.context->state, |
| 5260 | .stateid = &hdr->args.stateid, |
| 5261 | }; |
| 5262 | task->tk_status = nfs4_async_handle_exception(task, |
| 5263 | server, task->tk_status, &exception); |
| 5264 | if (exception.retry) { |
| 5265 | rpc_restart_call_prepare(task); |
| 5266 | return -EAGAIN; |
| 5267 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5268 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5270 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5271 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5272 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5275 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5276 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5277 | { |
| 5278 | |
| 5279 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5280 | nfs4_stateid_is_current(&args->stateid, |
| 5281 | args->context, |
| 5282 | args->lock_context, |
| 5283 | FMODE_READ)) |
| 5284 | return false; |
| 5285 | rpc_restart_call_prepare(task); |
| 5286 | return true; |
| 5287 | } |
| 5288 | |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5289 | static bool nfs4_read_plus_not_supported(struct rpc_task *task, |
| 5290 | struct nfs_pgio_header *hdr) |
| 5291 | { |
| 5292 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
| 5293 | struct rpc_message *msg = &task->tk_msg; |
| 5294 | |
| 5295 | if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS] && |
| 5296 | server->caps & NFS_CAP_READ_PLUS && task->tk_status == -ENOTSUPP) { |
| 5297 | server->caps &= ~NFS_CAP_READ_PLUS; |
| 5298 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5299 | rpc_restart_call_prepare(task); |
| 5300 | return true; |
| 5301 | } |
| 5302 | return false; |
| 5303 | } |
| 5304 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5305 | 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] | 5306 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5307 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5308 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5309 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5310 | return -EAGAIN; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5311 | if (nfs4_read_plus_not_supported(task, hdr)) |
| 5312 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5313 | if (task->tk_status > 0) |
| 5314 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5315 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5316 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
Anna Schumaker | 21e3140 | 2020-12-03 15:18:39 -0500 | [diff] [blame] | 5319 | #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] | 5320 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5321 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5322 | { |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5323 | /* Note: We don't use READ_PLUS with pNFS yet */ |
| 5324 | 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] | 5325 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS]; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5326 | } |
| 5327 | #else |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5328 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5329 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5330 | { |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5331 | } |
| 5332 | #endif /* CONFIG_NFS_V4_2 */ |
| 5333 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5334 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5335 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5337 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5338 | if (!hdr->pgio_done_cb) |
| 5339 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5340 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5341 | nfs42_read_plus_support(hdr, msg); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5342 | 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] | 5343 | } |
| 5344 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5345 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5346 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5347 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5348 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5349 | &hdr->args.seq_args, |
| 5350 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5351 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5352 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5353 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5354 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5355 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5356 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5357 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5358 | return -EIO; |
| 5359 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | } |
| 5361 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5362 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5363 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5364 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5365 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5366 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5367 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5368 | if (task->tk_status < 0) { |
| 5369 | struct nfs4_exception exception = { |
| 5370 | .inode = hdr->inode, |
| 5371 | .state = hdr->args.context->state, |
| 5372 | .stateid = &hdr->args.stateid, |
| 5373 | }; |
| 5374 | task->tk_status = nfs4_async_handle_exception(task, |
| 5375 | NFS_SERVER(inode), task->tk_status, |
| 5376 | &exception); |
| 5377 | if (exception.retry) { |
| 5378 | rpc_restart_call_prepare(task); |
| 5379 | return -EAGAIN; |
| 5380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5381 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5382 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5383 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5384 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5385 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5386 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5389 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5390 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5391 | { |
| 5392 | |
| 5393 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5394 | nfs4_stateid_is_current(&args->stateid, |
| 5395 | args->context, |
| 5396 | args->lock_context, |
| 5397 | FMODE_WRITE)) |
| 5398 | return false; |
| 5399 | rpc_restart_call_prepare(task); |
| 5400 | return true; |
| 5401 | } |
| 5402 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5403 | 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] | 5404 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5405 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5406 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5407 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5408 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5409 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5410 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5411 | } |
| 5412 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5413 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5414 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5415 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5416 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5417 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5418 | return false; |
| 5419 | /* Otherwise, request attributes if and only if we don't hold |
| 5420 | * a delegation |
| 5421 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5422 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5423 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5424 | |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5425 | static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src, |
| 5426 | struct inode *inode, struct nfs_server *server, |
| 5427 | struct nfs4_label *label) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5428 | { |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5429 | unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5430 | unsigned int i; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5431 | |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5432 | memcpy(bitmask, src, sizeof(*bitmask) * NFS4_BITMASK_SZ); |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5433 | |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5434 | if (cache_validity & NFS_INO_INVALID_CHANGE) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5435 | bitmask[0] |= FATTR4_WORD0_CHANGE; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5436 | if (cache_validity & NFS_INO_INVALID_ATIME) |
| 5437 | bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 5438 | if (cache_validity & NFS_INO_INVALID_MODE) |
| 5439 | bitmask[1] |= FATTR4_WORD1_MODE; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5440 | if (cache_validity & NFS_INO_INVALID_OTHER) |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 5441 | bitmask[1] |= FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP; |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 5442 | if (cache_validity & NFS_INO_INVALID_NLINK) |
| 5443 | bitmask[1] |= FATTR4_WORD1_NUMLINKS; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5444 | if (label && label->len && cache_validity & NFS_INO_INVALID_LABEL) |
| 5445 | bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5446 | if (cache_validity & NFS_INO_INVALID_CTIME) |
| 5447 | bitmask[1] |= FATTR4_WORD1_TIME_METADATA; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5448 | if (cache_validity & NFS_INO_INVALID_MTIME) |
| 5449 | bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5450 | if (cache_validity & NFS_INO_INVALID_BLOCKS) |
| 5451 | bitmask[1] |= FATTR4_WORD1_SPACE_USED; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5452 | |
Trond Myklebust | cc7f2da | 2021-04-11 14:31:24 -0400 | [diff] [blame] | 5453 | if (cache_validity & NFS_INO_INVALID_SIZE) |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5454 | bitmask[0] |= FATTR4_WORD0_SIZE; |
| 5455 | |
| 5456 | for (i = 0; i < NFS4_BITMASK_SZ; i++) |
| 5457 | bitmask[i] &= server->attr_bitmask[i]; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5458 | } |
| 5459 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5460 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5461 | struct rpc_message *msg, |
| 5462 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5463 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5464 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5465 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5466 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5467 | hdr->args.bitmask = NULL; |
| 5468 | hdr->res.fattr = NULL; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5469 | } else { |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5470 | nfs4_bitmask_set(hdr->args.bitmask_store, |
| 5471 | server->cache_consistency_bitmask, |
| 5472 | hdr->inode, server, NULL); |
| 5473 | hdr->args.bitmask = hdr->args.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5474 | } |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5475 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5476 | if (!hdr->pgio_done_cb) |
| 5477 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5478 | hdr->res.server = server; |
| 5479 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5481 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Olga Kornievskaia | cd1b659 | 2020-02-12 17:32:12 -0500 | [diff] [blame] | 5482 | 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] | 5483 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5486 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5487 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5488 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5489 | &data->args.seq_args, |
| 5490 | &data->res.seq_res, |
| 5491 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | } |
| 5493 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5494 | 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] | 5495 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5497 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5498 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5499 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5500 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5501 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5502 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5504 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | } |
| 5506 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5507 | 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] | 5508 | { |
| 5509 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5510 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5511 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5512 | } |
| 5513 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5514 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5515 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5517 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5518 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5519 | if (data->commit_done_cb == NULL) |
| 5520 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5521 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5522 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5523 | 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] | 5524 | 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] | 5525 | } |
| 5526 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5527 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5528 | struct nfs_commitres *res) |
| 5529 | { |
| 5530 | struct inode *dst_inode = file_inode(dst); |
| 5531 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5532 | struct rpc_message msg = { |
| 5533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5534 | .rpc_argp = args, |
| 5535 | .rpc_resp = res, |
| 5536 | }; |
| 5537 | |
| 5538 | args->fh = NFS_FH(dst_inode); |
| 5539 | return nfs4_call_sync(server->client, server, &msg, |
| 5540 | &args->seq_args, &res->seq_res, 1); |
| 5541 | } |
| 5542 | |
| 5543 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5544 | { |
| 5545 | struct nfs_commitargs args = { |
| 5546 | .offset = offset, |
| 5547 | .count = count, |
| 5548 | }; |
| 5549 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5550 | struct nfs4_exception exception = { }; |
| 5551 | int status; |
| 5552 | |
| 5553 | do { |
| 5554 | status = _nfs4_proc_commit(dst, &args, res); |
| 5555 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5556 | } while (exception.retry); |
| 5557 | |
| 5558 | return status; |
| 5559 | } |
| 5560 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5561 | struct nfs4_renewdata { |
| 5562 | struct nfs_client *client; |
| 5563 | unsigned long timestamp; |
| 5564 | }; |
| 5565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | /* |
| 5567 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5568 | * standalone procedure for queueing an asynchronous RENEW. |
| 5569 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5570 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5571 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5572 | struct nfs4_renewdata *data = calldata; |
| 5573 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5574 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5575 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5576 | nfs4_schedule_state_renewal(clp); |
| 5577 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5578 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5579 | } |
| 5580 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5581 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5582 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5583 | struct nfs4_renewdata *data = calldata; |
| 5584 | struct nfs_client *clp = data->client; |
| 5585 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5586 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5587 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5588 | switch (task->tk_status) { |
| 5589 | case 0: |
| 5590 | break; |
| 5591 | case -NFS4ERR_LEASE_MOVED: |
| 5592 | nfs4_schedule_lease_moved_recovery(clp); |
| 5593 | break; |
| 5594 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5595 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5596 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5597 | return; |
| 5598 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5599 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5600 | return; |
| 5601 | } |
| 5602 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5603 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5604 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | } |
| 5606 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5607 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5608 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5609 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5610 | }; |
| 5611 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5612 | 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] | 5613 | { |
| 5614 | struct rpc_message msg = { |
| 5615 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5616 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5617 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5619 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5621 | if (renew_flags == 0) |
| 5622 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5623 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5624 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5625 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5626 | if (data == NULL) { |
| 5627 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5628 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5629 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5630 | data->client = clp; |
| 5631 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5632 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5633 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | } |
| 5635 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5636 | 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] | 5637 | { |
| 5638 | struct rpc_message msg = { |
| 5639 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5640 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5641 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | }; |
| 5643 | unsigned long now = jiffies; |
| 5644 | int status; |
| 5645 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5646 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | if (status < 0) |
| 5648 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5649 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5650 | return 0; |
| 5651 | } |
| 5652 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5653 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5654 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5655 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5656 | } |
| 5657 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5658 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5659 | * 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] | 5660 | * the stack. |
| 5661 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5662 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5663 | |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5664 | int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5665 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5666 | { |
| 5667 | struct page *newpage, **spages; |
| 5668 | int rc = 0; |
| 5669 | size_t len; |
| 5670 | spages = pages; |
| 5671 | |
| 5672 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5673 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5674 | newpage = alloc_page(GFP_KERNEL); |
| 5675 | |
| 5676 | if (newpage == NULL) |
| 5677 | goto unwind; |
| 5678 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5679 | buf += len; |
| 5680 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5681 | *pages++ = newpage; |
| 5682 | rc++; |
| 5683 | } while (buflen != 0); |
| 5684 | |
| 5685 | return rc; |
| 5686 | |
| 5687 | unwind: |
| 5688 | for(; rc > 0; rc--) |
| 5689 | __free_page(spages[rc-1]); |
| 5690 | return -ENOMEM; |
| 5691 | } |
| 5692 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5693 | struct nfs4_cached_acl { |
| 5694 | int cached; |
| 5695 | size_t len; |
Gustavo A. R. Silva | 5601cda | 2020-03-09 13:24:42 -0500 | [diff] [blame] | 5696 | char data[]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5697 | }; |
| 5698 | |
| 5699 | 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] | 5700 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5701 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5702 | |
| 5703 | spin_lock(&inode->i_lock); |
| 5704 | kfree(nfsi->nfs4_acl); |
| 5705 | nfsi->nfs4_acl = acl; |
| 5706 | spin_unlock(&inode->i_lock); |
| 5707 | } |
| 5708 | |
| 5709 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5710 | { |
| 5711 | nfs4_set_cached_acl(inode, NULL); |
| 5712 | } |
| 5713 | |
| 5714 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5715 | { |
| 5716 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5717 | struct nfs4_cached_acl *acl; |
| 5718 | int ret = -ENOENT; |
| 5719 | |
| 5720 | spin_lock(&inode->i_lock); |
| 5721 | acl = nfsi->nfs4_acl; |
| 5722 | if (acl == NULL) |
| 5723 | goto out; |
| 5724 | if (buf == NULL) /* user is just asking for length */ |
| 5725 | goto out_len; |
| 5726 | if (acl->cached == 0) |
| 5727 | goto out; |
| 5728 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5729 | if (acl->len > buflen) |
| 5730 | goto out; |
| 5731 | memcpy(buf, acl->data, acl->len); |
| 5732 | out_len: |
| 5733 | ret = acl->len; |
| 5734 | out: |
| 5735 | spin_unlock(&inode->i_lock); |
| 5736 | return ret; |
| 5737 | } |
| 5738 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5739 | 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] | 5740 | { |
| 5741 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5742 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5743 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5744 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5745 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5746 | if (acl == NULL) |
| 5747 | goto out; |
| 5748 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5749 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5750 | } else { |
| 5751 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5752 | if (acl == NULL) |
| 5753 | goto out; |
| 5754 | acl->cached = 0; |
| 5755 | } |
| 5756 | acl->len = acl_len; |
| 5757 | out: |
| 5758 | nfs4_set_cached_acl(inode, acl); |
| 5759 | } |
| 5760 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5761 | /* |
| 5762 | * The getxattr API returns the required buffer length when called with a |
| 5763 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5764 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5765 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5766 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5767 | * the cache. If not so, we throw away the page, and cache the required |
| 5768 | * length. The next getxattr call will then produce another round trip to |
| 5769 | * the server, this time with the input buf of the required size. |
| 5770 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5771 | 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] | 5772 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5773 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5774 | struct nfs_getaclargs args = { |
| 5775 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5776 | .acl_len = buflen, |
| 5777 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5778 | struct nfs_getaclres res = { |
| 5779 | .acl_len = buflen, |
| 5780 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5781 | struct rpc_message msg = { |
| 5782 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5783 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5784 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5785 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5786 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5787 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5788 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5789 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5790 | if (buflen == 0) |
| 5791 | buflen = server->rsize; |
| 5792 | |
| 5793 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5794 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5795 | if (!pages) |
| 5796 | return -ENOMEM; |
| 5797 | |
| 5798 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5799 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5800 | for (i = 0; i < npages; i++) { |
| 5801 | pages[i] = alloc_page(GFP_KERNEL); |
| 5802 | if (!pages[i]) |
| 5803 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5804 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5805 | |
| 5806 | /* for decoding across pages */ |
| 5807 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5808 | if (!res.acl_scratch) |
| 5809 | goto out_free; |
| 5810 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5811 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5812 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5813 | 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] | 5814 | __func__, buf, buflen, npages, args.acl_len); |
| 5815 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5816 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5817 | if (ret) |
| 5818 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5819 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5820 | /* Handle the case where the passed-in buffer is too short */ |
| 5821 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5822 | /* Did the user only issue a request for the acl length? */ |
| 5823 | if (buf == NULL) |
| 5824 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5825 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5826 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5827 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5828 | 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] | 5829 | if (buf) { |
| 5830 | if (res.acl_len > buflen) { |
| 5831 | ret = -ERANGE; |
| 5832 | goto out_free; |
| 5833 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5834 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5835 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5836 | out_ok: |
| 5837 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5838 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5839 | for (i = 0; i < npages; i++) |
| 5840 | if (pages[i]) |
| 5841 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5842 | if (res.acl_scratch) |
| 5843 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5844 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5845 | return ret; |
| 5846 | } |
| 5847 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5848 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5849 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5850 | struct nfs4_exception exception = { |
| 5851 | .interruptible = true, |
| 5852 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5853 | ssize_t ret; |
| 5854 | do { |
| 5855 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5856 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5857 | if (ret >= 0) |
| 5858 | break; |
| 5859 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5860 | } while (exception.retry); |
| 5861 | return ret; |
| 5862 | } |
| 5863 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5864 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5865 | { |
| 5866 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5867 | int ret; |
| 5868 | |
| 5869 | if (!nfs4_server_supports_acls(server)) |
| 5870 | return -EOPNOTSUPP; |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 5871 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5872 | if (ret < 0) |
| 5873 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5874 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5875 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5876 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5877 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5878 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5879 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5880 | return ret; |
| 5881 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5882 | } |
| 5883 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5884 | 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] | 5885 | { |
| 5886 | struct nfs_server *server = NFS_SERVER(inode); |
| 5887 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5888 | struct nfs_setaclargs arg = { |
| 5889 | .fh = NFS_FH(inode), |
| 5890 | .acl_pages = pages, |
| 5891 | .acl_len = buflen, |
| 5892 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5893 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5894 | struct rpc_message msg = { |
| 5895 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5896 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5897 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5898 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5899 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5900 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5901 | |
J. Bruce Fields | 4f8be1f | 2021-01-28 17:36:38 -0500 | [diff] [blame] | 5902 | /* You can't remove system.nfs4_acl: */ |
| 5903 | if (buflen == 0) |
| 5904 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5905 | if (!nfs4_server_supports_acls(server)) |
| 5906 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5907 | if (npages > ARRAY_SIZE(pages)) |
| 5908 | return -ERANGE; |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5909 | i = nfs4_buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5910 | if (i < 0) |
| 5911 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5912 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5913 | 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] | 5914 | |
| 5915 | /* |
| 5916 | * Free each page after tx, so the only ref left is |
| 5917 | * held by the network stack |
| 5918 | */ |
| 5919 | for (; i > 0; i--) |
| 5920 | put_page(pages[i-1]); |
| 5921 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5922 | /* |
| 5923 | * Acl update can result in inode attribute update. |
| 5924 | * so mark the attribute cache invalid. |
| 5925 | */ |
| 5926 | spin_lock(&inode->i_lock); |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 5927 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 5928 | NFS_INO_INVALID_CTIME | |
| 5929 | NFS_INO_REVAL_FORCED); |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5930 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5931 | nfs_access_zap_cache(inode); |
| 5932 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5933 | return ret; |
| 5934 | } |
| 5935 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5936 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5937 | { |
| 5938 | struct nfs4_exception exception = { }; |
| 5939 | int err; |
| 5940 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5941 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5942 | trace_nfs4_set_acl(inode, err); |
Dai Ngo | f8849e2 | 2021-05-19 17:15:10 -0400 | [diff] [blame] | 5943 | if (err == -NFS4ERR_BADOWNER || err == -NFS4ERR_BADNAME) { |
| 5944 | /* |
| 5945 | * no need to retry since the kernel |
| 5946 | * isn't involved in encoding the ACEs. |
| 5947 | */ |
| 5948 | err = -EINVAL; |
| 5949 | break; |
| 5950 | } |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5951 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5952 | &exception); |
| 5953 | } while (exception.retry); |
| 5954 | return err; |
| 5955 | } |
| 5956 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5957 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5958 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5959 | size_t buflen) |
| 5960 | { |
| 5961 | struct nfs_server *server = NFS_SERVER(inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5962 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5963 | |
| 5964 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 5965 | struct nfs_fattr fattr = { |
| 5966 | .label = &label, |
| 5967 | }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5968 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5969 | .fh = NFS_FH(inode), |
| 5970 | .bitmask = bitmask, |
| 5971 | }; |
| 5972 | struct nfs4_getattr_res res = { |
| 5973 | .fattr = &fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5974 | .server = server, |
| 5975 | }; |
| 5976 | struct rpc_message msg = { |
| 5977 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5978 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5979 | .rpc_resp = &res, |
| 5980 | }; |
| 5981 | int ret; |
| 5982 | |
| 5983 | nfs_fattr_init(&fattr); |
| 5984 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5985 | 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] | 5986 | if (ret) |
| 5987 | return ret; |
| 5988 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5989 | return -ENOENT; |
Ondrej Mosnacek | 53cb245 | 2021-01-15 18:43:56 +0100 | [diff] [blame] | 5990 | return label.len; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5991 | } |
| 5992 | |
| 5993 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5994 | size_t buflen) |
| 5995 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5996 | struct nfs4_exception exception = { |
| 5997 | .interruptible = true, |
| 5998 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5999 | int err; |
| 6000 | |
| 6001 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6002 | return -EOPNOTSUPP; |
| 6003 | |
| 6004 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6005 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 6006 | trace_nfs4_get_security_label(inode, err); |
| 6007 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6008 | &exception); |
| 6009 | } while (exception.retry); |
| 6010 | return err; |
| 6011 | } |
| 6012 | |
| 6013 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 6014 | struct nfs4_label *ilabel, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6015 | struct nfs_fattr *fattr) |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6016 | { |
| 6017 | |
| 6018 | struct iattr sattr = {0}; |
| 6019 | struct nfs_server *server = NFS_SERVER(inode); |
| 6020 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6021 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6022 | .fh = NFS_FH(inode), |
| 6023 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6024 | .server = server, |
| 6025 | .bitmask = bitmask, |
| 6026 | .label = ilabel, |
| 6027 | }; |
| 6028 | struct nfs_setattrres res = { |
| 6029 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6030 | .server = server, |
| 6031 | }; |
| 6032 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6033 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 6034 | .rpc_argp = &arg, |
| 6035 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6036 | }; |
| 6037 | int status; |
| 6038 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6039 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6040 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6041 | 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] | 6042 | if (status) |
| 6043 | dprintk("%s failed: %d\n", __func__, status); |
| 6044 | |
| 6045 | return status; |
| 6046 | } |
| 6047 | |
| 6048 | static int nfs4_do_set_security_label(struct inode *inode, |
| 6049 | struct nfs4_label *ilabel, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6050 | struct nfs_fattr *fattr) |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6051 | { |
| 6052 | struct nfs4_exception exception = { }; |
| 6053 | int err; |
| 6054 | |
| 6055 | do { |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6056 | err = _nfs4_do_set_security_label(inode, ilabel, fattr); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6057 | trace_nfs4_set_security_label(inode, err); |
| 6058 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6059 | &exception); |
| 6060 | } while (exception.retry); |
| 6061 | return err; |
| 6062 | } |
| 6063 | |
| 6064 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6065 | 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] | 6066 | { |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6067 | struct nfs4_label ilabel = {0, 0, buflen, (char *)buf }; |
| 6068 | struct nfs_fattr *fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6069 | int status; |
| 6070 | |
| 6071 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6072 | return -EOPNOTSUPP; |
| 6073 | |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6074 | fattr = nfs_alloc_fattr_with_label(NFS_SERVER(inode)); |
| 6075 | if (fattr == NULL) |
| 6076 | return -ENOMEM; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6077 | |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6078 | status = nfs4_do_set_security_label(inode, &ilabel, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6079 | if (status == 0) |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6080 | nfs_setsecurity(inode, fattr, fattr->label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6081 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6082 | return status; |
| 6083 | } |
| 6084 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 6085 | |
| 6086 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6087 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 6088 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6089 | { |
| 6090 | __be32 verf[2]; |
| 6091 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6092 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 6093 | /* An impossible timestamp guarantees this value |
| 6094 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6095 | verf[0] = cpu_to_be32(U32_MAX); |
| 6096 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6097 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6098 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6099 | u64 ns = ktime_to_ns(nn->boot_time); |
| 6100 | |
| 6101 | verf[0] = cpu_to_be32(ns >> 32); |
| 6102 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6103 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6104 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 6105 | } |
| 6106 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6107 | static size_t |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6108 | nfs4_get_uniquifier(struct nfs_client *clp, char *buf, size_t buflen) |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6109 | { |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6110 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 6111 | struct nfs_netns_client *nn_clp = nn->nfs_client; |
| 6112 | const char *id; |
| 6113 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6114 | buf[0] = '\0'; |
| 6115 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6116 | if (nn_clp) { |
| 6117 | rcu_read_lock(); |
| 6118 | id = rcu_dereference(nn_clp->identifier); |
| 6119 | if (id) |
| 6120 | strscpy(buf, id, buflen); |
| 6121 | rcu_read_unlock(); |
| 6122 | } |
| 6123 | |
| 6124 | if (nfs4_client_id_uniquifier[0] != '\0' && buf[0] == '\0') |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6125 | strscpy(buf, nfs4_client_id_uniquifier, buflen); |
| 6126 | |
| 6127 | return strlen(buf); |
| 6128 | } |
| 6129 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6130 | static int |
| 6131 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6132 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6133 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6134 | size_t buflen; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6135 | size_t len; |
| 6136 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6137 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6138 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6139 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 6140 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6141 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6142 | len = 14 + |
| 6143 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 6144 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6145 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6146 | 1; |
| 6147 | rcu_read_unlock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6148 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6149 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6150 | if (buflen) |
| 6151 | len += buflen + 1; |
| 6152 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6153 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6154 | return -EINVAL; |
| 6155 | |
| 6156 | /* |
| 6157 | * Since this string is allocated at mount time, and held until the |
| 6158 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6159 | * about a memory-reclaim deadlock. |
| 6160 | */ |
| 6161 | str = kmalloc(len, GFP_KERNEL); |
| 6162 | if (!str) |
| 6163 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6164 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6165 | rcu_read_lock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6166 | if (buflen) |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6167 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6168 | clp->cl_rpcclient->cl_nodename, buf, |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6169 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6170 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6171 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6172 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6173 | clp->cl_rpcclient->cl_nodename, |
| 6174 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6175 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6176 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6177 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6178 | clp->cl_owner_id = str; |
| 6179 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6180 | } |
| 6181 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6182 | static int |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6183 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6184 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6185 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6186 | size_t buflen; |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6187 | size_t len; |
| 6188 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6189 | |
| 6190 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6191 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6192 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6193 | len = 10 + 10 + 1 + 10 + 1 + |
| 6194 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6195 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6196 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6197 | if (buflen) |
| 6198 | len += buflen + 1; |
| 6199 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6200 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6201 | return -EINVAL; |
| 6202 | |
| 6203 | /* |
| 6204 | * Since this string is allocated at mount time, and held until the |
| 6205 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6206 | * about a memory-reclaim deadlock. |
| 6207 | */ |
| 6208 | str = kmalloc(len, GFP_KERNEL); |
| 6209 | if (!str) |
| 6210 | return -ENOMEM; |
| 6211 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6212 | if (buflen) |
| 6213 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
| 6214 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6215 | buf, clp->cl_rpcclient->cl_nodename); |
| 6216 | else |
| 6217 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
| 6218 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6219 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6220 | clp->cl_owner_id = str; |
| 6221 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6222 | } |
| 6223 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6224 | /* |
| 6225 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6226 | * services. Advertise one based on the address family of the |
| 6227 | * clientaddr. |
| 6228 | */ |
| 6229 | static unsigned int |
| 6230 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6231 | { |
| 6232 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6233 | return scnprintf(buf, len, "tcp6"); |
| 6234 | else |
| 6235 | return scnprintf(buf, len, "tcp"); |
| 6236 | } |
| 6237 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6238 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6239 | { |
| 6240 | struct nfs4_setclientid *sc = calldata; |
| 6241 | |
| 6242 | if (task->tk_status == 0) |
| 6243 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6244 | } |
| 6245 | |
| 6246 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6247 | .rpc_call_done = nfs4_setclientid_done, |
| 6248 | }; |
| 6249 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6250 | /** |
| 6251 | * nfs4_proc_setclientid - Negotiate client ID |
| 6252 | * @clp: state data structure |
| 6253 | * @program: RPC program for NFSv4 callback service |
| 6254 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6255 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6256 | * @res: where to place the result |
| 6257 | * |
| 6258 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6259 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6260 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6261 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6262 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6263 | { |
| 6264 | nfs4_verifier sc_verifier; |
| 6265 | struct nfs4_setclientid setclientid = { |
| 6266 | .sc_verifier = &sc_verifier, |
| 6267 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6268 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | }; |
| 6270 | struct rpc_message msg = { |
| 6271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6272 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6273 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6274 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6275 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6276 | struct rpc_task_setup task_setup_data = { |
| 6277 | .rpc_client = clp->cl_rpcclient, |
| 6278 | .rpc_message = &msg, |
| 6279 | .callback_ops = &nfs4_setclientid_ops, |
| 6280 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6281 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6282 | }; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6283 | unsigned long now = jiffies; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6284 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6285 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6286 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6287 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6288 | |
| 6289 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6290 | status = nfs4_init_uniform_client_string(clp); |
| 6291 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6292 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6293 | |
| 6294 | if (status) |
| 6295 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6296 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6297 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6298 | setclientid.sc_netid_len = |
| 6299 | nfs4_init_callback_netid(clp, |
| 6300 | setclientid.sc_netid, |
| 6301 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6302 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6303 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6304 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6305 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6306 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6307 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6308 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6309 | |
| 6310 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6311 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6312 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6313 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6314 | put_rpccred(setclientid.sc_cred); |
| 6315 | } |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6316 | |
| 6317 | if (status == 0) |
| 6318 | do_renew_lease(clp, now); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6319 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6320 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6321 | dprintk("NFS reply setclientid: %d\n", status); |
| 6322 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6323 | } |
| 6324 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6325 | /** |
| 6326 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6327 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6328 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6329 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6330 | * |
| 6331 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6332 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6333 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6334 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6335 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6337 | struct rpc_message msg = { |
| 6338 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6339 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6340 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6342 | int status; |
| 6343 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6344 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6345 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6346 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6347 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6348 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6349 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6350 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | return status; |
| 6352 | } |
| 6353 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6354 | struct nfs4_delegreturndata { |
| 6355 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6356 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6357 | struct nfs_fh fh; |
| 6358 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6359 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6360 | struct { |
| 6361 | struct nfs4_layoutreturn_args arg; |
| 6362 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6363 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6364 | u32 roc_barrier; |
| 6365 | bool roc; |
| 6366 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6367 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6368 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6369 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6370 | }; |
| 6371 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6372 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6373 | { |
| 6374 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6375 | struct nfs4_exception exception = { |
| 6376 | .inode = data->inode, |
| 6377 | .stateid = &data->stateid, |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 6378 | .task_is_privileged = data->args.seq_args.sa_privileged, |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6379 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6380 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6381 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6382 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6383 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6384 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6385 | |
| 6386 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6387 | if (pnfs_roc_done(task, &data->args.lr_args, &data->res.lr_res, |
| 6388 | &data->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6389 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6390 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6391 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6392 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6393 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6394 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6395 | case -NFS4ERR_ADMIN_REVOKED: |
| 6396 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6397 | case -NFS4ERR_EXPIRED: |
| 6398 | nfs4_free_revoked_stateid(data->res.server, |
| 6399 | data->args.stateid, |
| 6400 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6401 | fallthrough; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6402 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6403 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 244fcd2 | 2019-12-20 10:43:37 -0500 | [diff] [blame] | 6404 | case -ETIMEDOUT: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6405 | task->tk_status = 0; |
| 6406 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6407 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6408 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6409 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6410 | if (data->args.bitmask) { |
| 6411 | data->args.bitmask = NULL; |
| 6412 | data->res.fattr = NULL; |
| 6413 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6414 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6415 | case -NFS4ERR_ACCESS: |
| 6416 | if (data->args.bitmask) { |
| 6417 | data->args.bitmask = NULL; |
| 6418 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6419 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6420 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6421 | fallthrough; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6422 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6423 | task->tk_status = nfs4_async_handle_exception(task, |
| 6424 | data->res.server, task->tk_status, |
| 6425 | &exception); |
| 6426 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6427 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6428 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6429 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6430 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6431 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6432 | out_restart: |
| 6433 | task->tk_status = 0; |
| 6434 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6435 | } |
| 6436 | |
| 6437 | static void nfs4_delegreturn_release(void *calldata) |
| 6438 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6439 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6440 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6441 | |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6442 | if (data->lr.roc) |
| 6443 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6444 | data->res.lr_ret); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6445 | if (inode) { |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6446 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6447 | nfs_iput_and_deactive(inode); |
| 6448 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6449 | kfree(calldata); |
| 6450 | } |
| 6451 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6452 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6453 | { |
| 6454 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6455 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6456 | |
| 6457 | d_data = (struct nfs4_delegreturndata *)data; |
| 6458 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6459 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6460 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6461 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6462 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6463 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6464 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6465 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6466 | d_data->args.lr_args = NULL; |
| 6467 | d_data->res.lr_res = NULL; |
| 6468 | } |
| 6469 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6470 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6471 | &d_data->args.seq_args, |
| 6472 | &d_data->res.seq_res, |
| 6473 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6474 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6475 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6476 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6477 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6478 | .rpc_call_done = nfs4_delegreturn_done, |
| 6479 | .rpc_release = nfs4_delegreturn_release, |
| 6480 | }; |
| 6481 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6482 | 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] | 6483 | { |
| 6484 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6485 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6486 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6487 | struct rpc_message msg = { |
| 6488 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6489 | .rpc_cred = cred, |
| 6490 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6491 | struct rpc_task_setup task_setup_data = { |
| 6492 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6493 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6494 | .callback_ops = &nfs4_delegreturn_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 6495 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT | RPC_TASK_MOVEABLE, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6496 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6497 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6498 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6499 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6500 | if (data == NULL) |
| 6501 | return -ENOMEM; |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6502 | |
| 6503 | nfs4_state_protect(server->nfs_client, |
| 6504 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6505 | &task_setup_data.rpc_client, &msg); |
| 6506 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6507 | data->args.fhandle = &data->fh; |
| 6508 | data->args.stateid = &data->stateid; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 6509 | nfs4_bitmask_set(data->args.bitmask_store, |
| 6510 | server->cache_consistency_bitmask, inode, server, |
| 6511 | NULL); |
| 6512 | data->args.bitmask = data->args.bitmask_store; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6513 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6514 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6515 | data->res.fattr = &data->fattr; |
| 6516 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6517 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6518 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6519 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6520 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6521 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6522 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6523 | if (data->inode || issync) { |
| 6524 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, |
| 6525 | cred); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6526 | if (data->lr.roc) { |
| 6527 | data->args.lr_args = &data->lr.arg; |
| 6528 | data->res.lr_res = &data->lr.res; |
| 6529 | } |
| 6530 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6531 | |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 6532 | if (!data->inode) |
| 6533 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, |
| 6534 | 1); |
| 6535 | else |
| 6536 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, |
| 6537 | 0); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6538 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6539 | msg.rpc_argp = &data->args; |
| 6540 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6541 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6542 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6543 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6544 | if (!issync) |
| 6545 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6546 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6547 | if (status != 0) |
| 6548 | goto out; |
| 6549 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6550 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6551 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6552 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6553 | } |
| 6554 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6555 | 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] | 6556 | { |
| 6557 | struct nfs_server *server = NFS_SERVER(inode); |
| 6558 | struct nfs4_exception exception = { }; |
| 6559 | int err; |
| 6560 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6561 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6562 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6563 | switch (err) { |
| 6564 | case -NFS4ERR_STALE_STATEID: |
| 6565 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | case 0: |
| 6567 | return 0; |
| 6568 | } |
| 6569 | err = nfs4_handle_exception(server, err, &exception); |
| 6570 | } while (exception.retry); |
| 6571 | return err; |
| 6572 | } |
| 6573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6574 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6575 | { |
| 6576 | struct inode *inode = state->inode; |
| 6577 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6578 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6579 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6580 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6581 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6582 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6583 | struct nfs_lockt_res res = { |
| 6584 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6585 | }; |
| 6586 | struct rpc_message msg = { |
| 6587 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6588 | .rpc_argp = &arg, |
| 6589 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6590 | .rpc_cred = state->owner->so_cred, |
| 6591 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6592 | struct nfs4_lock_state *lsp; |
| 6593 | int status; |
| 6594 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6595 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6596 | status = nfs4_set_lock_state(state, request); |
| 6597 | if (status != 0) |
| 6598 | goto out; |
| 6599 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6600 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6601 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6602 | 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] | 6603 | switch (status) { |
| 6604 | case 0: |
| 6605 | request->fl_type = F_UNLCK; |
| 6606 | break; |
| 6607 | case -NFS4ERR_DENIED: |
| 6608 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6609 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6610 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6611 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6612 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6613 | return status; |
| 6614 | } |
| 6615 | |
| 6616 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6617 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6618 | struct nfs4_exception exception = { |
| 6619 | .interruptible = true, |
| 6620 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | int err; |
| 6622 | |
| 6623 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6624 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6625 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6626 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6627 | &exception); |
| 6628 | } while (exception.retry); |
| 6629 | return err; |
| 6630 | } |
| 6631 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6632 | /* |
| 6633 | * Update the seqid of a lock stateid after receiving |
| 6634 | * NFS4ERR_OLD_STATEID |
| 6635 | */ |
| 6636 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6637 | struct nfs4_lock_state *lsp) |
| 6638 | { |
| 6639 | struct nfs4_state *state = lsp->ls_state; |
| 6640 | bool ret = false; |
| 6641 | |
| 6642 | spin_lock(&state->state_lock); |
| 6643 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6644 | goto out; |
| 6645 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6646 | nfs4_stateid_seqid_inc(dst); |
| 6647 | else |
| 6648 | dst->seqid = lsp->ls_stateid.seqid; |
| 6649 | ret = true; |
| 6650 | out: |
| 6651 | spin_unlock(&state->state_lock); |
| 6652 | return ret; |
| 6653 | } |
| 6654 | |
| 6655 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6656 | struct nfs4_lock_state *lsp) |
| 6657 | { |
| 6658 | struct nfs4_state *state = lsp->ls_state; |
| 6659 | bool ret; |
| 6660 | |
| 6661 | spin_lock(&state->state_lock); |
| 6662 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6663 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6664 | spin_unlock(&state->state_lock); |
| 6665 | return ret; |
| 6666 | } |
| 6667 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6668 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6669 | struct nfs_locku_args arg; |
| 6670 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6671 | struct nfs4_lock_state *lsp; |
| 6672 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6673 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6674 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6675 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6676 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6677 | }; |
| 6678 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6679 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6680 | struct nfs_open_context *ctx, |
| 6681 | struct nfs4_lock_state *lsp, |
| 6682 | struct nfs_seqid *seqid) |
| 6683 | { |
| 6684 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6685 | struct nfs4_state *state = lsp->ls_state; |
| 6686 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6687 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6688 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6689 | if (p == NULL) |
| 6690 | return NULL; |
| 6691 | p->arg.fh = NFS_FH(inode); |
| 6692 | p->arg.fl = &p->fl; |
| 6693 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6694 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6695 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6696 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6697 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6698 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6699 | locks_init_lock(&p->fl); |
| 6700 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6701 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6702 | spin_lock(&state->state_lock); |
| 6703 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6704 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6705 | return p; |
| 6706 | } |
| 6707 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6708 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6709 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6710 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6711 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6712 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6713 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6714 | put_nfs_open_context(calldata->ctx); |
| 6715 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6716 | } |
| 6717 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6718 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6719 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6720 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6721 | struct nfs4_exception exception = { |
| 6722 | .inode = calldata->lsp->ls_state->inode, |
| 6723 | .stateid = &calldata->arg.stateid, |
| 6724 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6725 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6726 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6727 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6728 | switch (task->tk_status) { |
| 6729 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6730 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6731 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6732 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6733 | &calldata->res.stateid)) |
| 6734 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6735 | fallthrough; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6736 | case -NFS4ERR_ADMIN_REVOKED: |
| 6737 | case -NFS4ERR_EXPIRED: |
| 6738 | nfs4_free_revoked_stateid(calldata->server, |
| 6739 | &calldata->arg.stateid, |
| 6740 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6741 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6742 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6743 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6744 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6745 | calldata->lsp)) |
| 6746 | rpc_restart_call_prepare(task); |
| 6747 | break; |
| 6748 | case -NFS4ERR_OLD_STATEID: |
| 6749 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6750 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6751 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6752 | break; |
| 6753 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6754 | task->tk_status = nfs4_async_handle_exception(task, |
| 6755 | calldata->server, task->tk_status, |
| 6756 | &exception); |
| 6757 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6758 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6759 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6760 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6761 | } |
| 6762 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6763 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6764 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6765 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6766 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6767 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6768 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6769 | return; |
| 6770 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6771 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6772 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6773 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6774 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6775 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6776 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6777 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6778 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6779 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6780 | &calldata->res.seq_res, |
| 6781 | task) != 0) |
| 6782 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6783 | return; |
| 6784 | out_no_action: |
| 6785 | task->tk_action = NULL; |
| 6786 | out_wait: |
| 6787 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6788 | } |
| 6789 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6790 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6791 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6792 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6793 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6794 | }; |
| 6795 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6796 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6797 | struct nfs_open_context *ctx, |
| 6798 | struct nfs4_lock_state *lsp, |
| 6799 | struct nfs_seqid *seqid) |
| 6800 | { |
| 6801 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6802 | struct rpc_message msg = { |
| 6803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6804 | .rpc_cred = ctx->cred, |
| 6805 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6806 | struct rpc_task_setup task_setup_data = { |
| 6807 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6808 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6809 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6810 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6811 | .flags = RPC_TASK_ASYNC, |
| 6812 | }; |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 6813 | struct nfs_client *client = |
| 6814 | NFS_SERVER(lsp->ls_state->inode)->nfs_client; |
| 6815 | |
| 6816 | if (client->cl_minorversion) |
| 6817 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6818 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6819 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6820 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6821 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6822 | /* Ensure this is an unlock - when canceling a lock, the |
| 6823 | * canceled lock is passed in, and it won't be an unlock. |
| 6824 | */ |
| 6825 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6826 | if (fl->fl_flags & FL_CLOSE) |
| 6827 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6828 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6829 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6830 | if (data == NULL) { |
| 6831 | nfs_free_seqid(seqid); |
| 6832 | return ERR_PTR(-ENOMEM); |
| 6833 | } |
| 6834 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6835 | 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] | 6836 | msg.rpc_argp = &data->arg; |
| 6837 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6838 | task_setup_data.callback_data = data; |
| 6839 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6840 | } |
| 6841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6842 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6843 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6844 | struct inode *inode = state->inode; |
| 6845 | struct nfs4_state_owner *sp = state->owner; |
| 6846 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6847 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6848 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6849 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6850 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6851 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6852 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6853 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6854 | status = nfs4_set_lock_state(state, request); |
| 6855 | /* Unlock _before_ we do the RPC call */ |
| 6856 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6857 | /* Exclude nfs_delegation_claim_locks() */ |
| 6858 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6859 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6860 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6861 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6862 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6863 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6864 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6865 | } |
| 6866 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6867 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6868 | if (status != 0) |
| 6869 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6870 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6871 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6872 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6873 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6874 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6875 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6876 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6877 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6878 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6879 | 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] | 6880 | status = PTR_ERR(task); |
| 6881 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6882 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6883 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6884 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6885 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6886 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6887 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6888 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6889 | } |
| 6890 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6891 | struct nfs4_lockdata { |
| 6892 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6893 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6894 | struct nfs4_lock_state *lsp; |
| 6895 | struct nfs_open_context *ctx; |
| 6896 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6897 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6898 | int rpc_status; |
| 6899 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6900 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6901 | }; |
| 6902 | |
| 6903 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6904 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6905 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6906 | { |
| 6907 | struct nfs4_lockdata *p; |
| 6908 | struct inode *inode = lsp->ls_state->inode; |
| 6909 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6910 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6911 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6912 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6913 | if (p == NULL) |
| 6914 | return NULL; |
| 6915 | |
| 6916 | p->arg.fh = NFS_FH(inode); |
| 6917 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6918 | 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] | 6919 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6920 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6921 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6922 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6923 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6924 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6925 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6926 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6927 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6928 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6929 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6930 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6931 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6932 | locks_init_lock(&p->fl); |
| 6933 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6934 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6935 | out_free_seqid: |
| 6936 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6937 | out_free: |
| 6938 | kfree(p); |
| 6939 | return NULL; |
| 6940 | } |
| 6941 | |
| 6942 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6943 | { |
| 6944 | struct nfs4_lockdata *data = calldata; |
| 6945 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6946 | |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6947 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6948 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6949 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6950 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6951 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6952 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6953 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6954 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6955 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6956 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6957 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6958 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6959 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6960 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6961 | &data->lsp->ls_stateid); |
| 6962 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6963 | if (!nfs4_valid_open_stateid(state)) { |
| 6964 | data->rpc_status = -EBADF; |
| 6965 | task->tk_action = NULL; |
| 6966 | goto out_release_open_seqid; |
| 6967 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6968 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6969 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6970 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6971 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6972 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6973 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6974 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6975 | nfs_release_seqid(data->arg.open_seqid); |
| 6976 | out_release_lock_seqid: |
| 6977 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6978 | out_wait: |
| 6979 | nfs4_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 6980 | dprintk("%s: ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6981 | } |
| 6982 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6983 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6984 | { |
| 6985 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6986 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6987 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6988 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6989 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6990 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6991 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6992 | switch (task->tk_status) { |
| 6993 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6994 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6995 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6996 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6997 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6998 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6999 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7000 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7001 | if (data->arg.new_lock_owner != 0) { |
| 7002 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 7003 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 7004 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7005 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 7006 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7007 | break; |
| 7008 | case -NFS4ERR_BAD_STATEID: |
| 7009 | case -NFS4ERR_OLD_STATEID: |
| 7010 | case -NFS4ERR_STALE_STATEID: |
| 7011 | case -NFS4ERR_EXPIRED: |
| 7012 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7013 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7014 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7015 | goto out_restart; |
| 7016 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7017 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7018 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7019 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7020 | out_done: |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 7021 | dprintk("%s: ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7022 | return; |
| 7023 | out_restart: |
| 7024 | if (!data->cancelled) |
| 7025 | rpc_restart_call_prepare(task); |
| 7026 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7027 | } |
| 7028 | |
| 7029 | static void nfs4_lock_release(void *calldata) |
| 7030 | { |
| 7031 | struct nfs4_lockdata *data = calldata; |
| 7032 | |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7033 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7034 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7035 | struct rpc_task *task; |
| 7036 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 7037 | data->arg.lock_seqid); |
| 7038 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7039 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7040 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7041 | } else |
| 7042 | nfs_free_seqid(data->arg.lock_seqid); |
| 7043 | nfs4_put_lock_state(data->lsp); |
| 7044 | put_nfs_open_context(data->ctx); |
| 7045 | kfree(data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7046 | } |
| 7047 | |
| 7048 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 7049 | .rpc_call_prepare = nfs4_lock_prepare, |
| 7050 | .rpc_call_done = nfs4_lock_done, |
| 7051 | .rpc_release = nfs4_lock_release, |
| 7052 | }; |
| 7053 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7054 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 7055 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7056 | switch (error) { |
| 7057 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 7058 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7059 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7060 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7061 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 7062 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7063 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7064 | break; |
| 7065 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7066 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7067 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 7068 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7069 | } |
| 7070 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7071 | 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] | 7072 | { |
| 7073 | struct nfs4_lockdata *data; |
| 7074 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7075 | struct rpc_message msg = { |
| 7076 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 7077 | .rpc_cred = state->owner->so_cred, |
| 7078 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7079 | struct rpc_task_setup task_setup_data = { |
| 7080 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7081 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7082 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 7083 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 7084 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7085 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7086 | int ret; |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 7087 | struct nfs_client *client = NFS_SERVER(state->inode)->nfs_client; |
| 7088 | |
| 7089 | if (client->cl_minorversion) |
| 7090 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7091 | |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7092 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7093 | fl->fl_u.nfs4_fl.owner, |
| 7094 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7095 | if (data == NULL) |
| 7096 | return -ENOMEM; |
| 7097 | if (IS_SETLKW(cmd)) |
| 7098 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7099 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 7100 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 7101 | msg.rpc_argp = &data->arg; |
| 7102 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7103 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7104 | if (recovery_type > NFS_LOCK_NEW) { |
| 7105 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 7106 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7107 | } else |
| 7108 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7109 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 7110 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7111 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 7112 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7113 | if (ret == 0) { |
| 7114 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7115 | if (ret) |
| 7116 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 7117 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7118 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 7119 | data->cancelled = true; |
Dave Wysochanski | 3d1a90a | 2020-12-11 05:12:51 -0500 | [diff] [blame] | 7120 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 7121 | rpc_put_task(task); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 7122 | dprintk("%s: ret = %d\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7123 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7124 | } |
| 7125 | |
| 7126 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 7127 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7128 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7129 | struct nfs4_exception exception = { |
| 7130 | .inode = state->inode, |
| 7131 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7132 | int err; |
| 7133 | |
| 7134 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7135 | /* Cache the lock if possible... */ |
| 7136 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7137 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7138 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 7139 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7140 | break; |
| 7141 | nfs4_handle_exception(server, err, &exception); |
| 7142 | } while (exception.retry); |
| 7143 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7147 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7148 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7149 | struct nfs4_exception exception = { |
| 7150 | .inode = state->inode, |
| 7151 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7152 | int err; |
| 7153 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 7154 | err = nfs4_set_lock_state(state, request); |
| 7155 | if (err != 0) |
| 7156 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 7157 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 7158 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 7159 | return 0; |
| 7160 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7161 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7162 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7163 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7164 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7165 | switch (err) { |
| 7166 | default: |
| 7167 | goto out; |
| 7168 | case -NFS4ERR_GRACE: |
| 7169 | case -NFS4ERR_DELAY: |
| 7170 | nfs4_handle_exception(server, err, &exception); |
| 7171 | err = 0; |
| 7172 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7173 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7174 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7175 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7176 | } |
| 7177 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7178 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7179 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7180 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7181 | struct nfs4_lock_state *lsp; |
| 7182 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7183 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7184 | status = nfs4_set_lock_state(state, request); |
| 7185 | if (status != 0) |
| 7186 | return status; |
| 7187 | lsp = request->fl_u.nfs4_fl.owner; |
| 7188 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7189 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7190 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7191 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7192 | } |
| 7193 | #endif |
| 7194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7195 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7196 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7197 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7198 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7199 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7200 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7201 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7202 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7203 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7204 | if (status < 0) |
| 7205 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7206 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7207 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7208 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7209 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7210 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7211 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7212 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7213 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7214 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7215 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7216 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7217 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7218 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7219 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7220 | out: |
| 7221 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7222 | return status; |
| 7223 | } |
| 7224 | |
| 7225 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7226 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7227 | struct nfs4_exception exception = { |
| 7228 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7229 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7230 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7231 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7232 | int err; |
| 7233 | |
| 7234 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7235 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7236 | if (err == -NFS4ERR_DENIED) |
| 7237 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7238 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7239 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7240 | } while (exception.retry); |
| 7241 | return err; |
| 7242 | } |
| 7243 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7244 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7245 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7246 | |
| 7247 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7248 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7249 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7250 | { |
| 7251 | int status = -ERESTARTSYS; |
| 7252 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7253 | |
| 7254 | while(!signalled()) { |
| 7255 | status = nfs4_proc_setlk(state, cmd, request); |
| 7256 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7257 | break; |
| 7258 | freezable_schedule_timeout_interruptible(timeout); |
| 7259 | timeout *= 2; |
| 7260 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7261 | status = -ERESTARTSYS; |
| 7262 | } |
| 7263 | return status; |
| 7264 | } |
| 7265 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7266 | #ifdef CONFIG_NFS_V4_1 |
| 7267 | struct nfs4_lock_waiter { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7268 | struct inode *inode; |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7269 | struct nfs_lowner owner; |
| 7270 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7271 | }; |
| 7272 | |
| 7273 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7274 | 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] | 7275 | { |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7276 | struct nfs4_lock_waiter *waiter = |
| 7277 | container_of(wait, struct nfs4_lock_waiter, wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7278 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7279 | /* NULL key means to wake up everyone */ |
| 7280 | if (key) { |
| 7281 | struct cb_notify_lock_args *cbnl = key; |
| 7282 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7283 | *wowner = &waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7284 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7285 | /* Only wake if the callback was for the same owner. */ |
| 7286 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7287 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7288 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7289 | /* Make sure it's for the right inode */ |
| 7290 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7291 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7292 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7293 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7294 | return woken_wake_function(wait, mode, flags, key); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7295 | } |
| 7296 | |
| 7297 | static int |
| 7298 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7299 | { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7300 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7301 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7302 | struct nfs_client *clp = server->nfs_client; |
| 7303 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7304 | struct nfs4_lock_waiter waiter = { |
| 7305 | .inode = state->inode, |
| 7306 | .owner = { .clientid = clp->cl_clientid, |
| 7307 | .id = lsp->ls_seqid.owner_id, |
| 7308 | .s_dev = server->s_dev }, |
| 7309 | }; |
| 7310 | int status; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7311 | |
| 7312 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7313 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7314 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7315 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7316 | init_wait(&waiter.wait); |
| 7317 | waiter.wait.func = nfs4_wake_lock_waiter; |
| 7318 | add_wait_queue(q, &waiter.wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7319 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7320 | do { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7321 | status = nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7322 | if (status != -EAGAIN || IS_SETLK(cmd)) |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7323 | break; |
| 7324 | |
| 7325 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7326 | freezer_do_not_count(); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7327 | wait_woken(&waiter.wait, TASK_INTERRUPTIBLE, |
| 7328 | NFS4_LOCK_MAXTIMEOUT); |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7329 | freezer_count(); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7330 | } while (!signalled()); |
| 7331 | |
| 7332 | remove_wait_queue(q, &waiter.wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7333 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7334 | return status; |
| 7335 | } |
| 7336 | #else /* !CONFIG_NFS_V4_1 */ |
| 7337 | static inline int |
| 7338 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7339 | { |
| 7340 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7341 | } |
| 7342 | #endif |
| 7343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7344 | static int |
| 7345 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7346 | { |
| 7347 | struct nfs_open_context *ctx; |
| 7348 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7349 | int status; |
| 7350 | |
| 7351 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7352 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7353 | state = ctx->state; |
| 7354 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7355 | if (IS_GETLK(cmd)) { |
| 7356 | if (state != NULL) |
| 7357 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7358 | return 0; |
| 7359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7360 | |
| 7361 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7362 | return -EINVAL; |
| 7363 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7364 | if (request->fl_type == F_UNLCK) { |
| 7365 | if (state != NULL) |
| 7366 | return nfs4_proc_unlck(state, cmd, request); |
| 7367 | return 0; |
| 7368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7369 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7370 | if (state == NULL) |
| 7371 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7372 | |
| 7373 | if ((request->fl_flags & FL_POSIX) && |
| 7374 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7375 | return -ENOLCK; |
| 7376 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7377 | /* |
| 7378 | * Don't rely on the VFS having checked the file open mode, |
| 7379 | * since it won't do this for flock() locks. |
| 7380 | */ |
| 7381 | switch (request->fl_type) { |
| 7382 | case F_RDLCK: |
| 7383 | if (!(filp->f_mode & FMODE_READ)) |
| 7384 | return -EBADF; |
| 7385 | break; |
| 7386 | case F_WRLCK: |
| 7387 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7388 | return -EBADF; |
| 7389 | } |
| 7390 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7391 | status = nfs4_set_lock_state(state, request); |
| 7392 | if (status != 0) |
| 7393 | return status; |
| 7394 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7395 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7396 | } |
| 7397 | |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7398 | static int nfs4_delete_lease(struct file *file, void **priv) |
| 7399 | { |
| 7400 | return generic_setlease(file, F_UNLCK, NULL, priv); |
| 7401 | } |
| 7402 | |
| 7403 | static int nfs4_add_lease(struct file *file, long arg, struct file_lock **lease, |
| 7404 | void **priv) |
| 7405 | { |
| 7406 | struct inode *inode = file_inode(file); |
| 7407 | fmode_t type = arg == F_RDLCK ? FMODE_READ : FMODE_WRITE; |
| 7408 | int ret; |
| 7409 | |
| 7410 | /* No delegation, no lease */ |
| 7411 | if (!nfs4_have_delegation(inode, type)) |
Trond Myklebust | df2c7b9 | 2021-06-25 15:08:39 -0400 | [diff] [blame] | 7412 | return -EAGAIN; |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7413 | ret = generic_setlease(file, arg, lease, priv); |
| 7414 | if (ret || nfs4_have_delegation(inode, type)) |
| 7415 | return ret; |
| 7416 | /* We raced with a delegation return */ |
| 7417 | nfs4_delete_lease(file, priv); |
Trond Myklebust | df2c7b9 | 2021-06-25 15:08:39 -0400 | [diff] [blame] | 7418 | return -EAGAIN; |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | int nfs4_proc_setlease(struct file *file, long arg, struct file_lock **lease, |
| 7422 | void **priv) |
| 7423 | { |
| 7424 | switch (arg) { |
| 7425 | case F_RDLCK: |
| 7426 | case F_WRLCK: |
| 7427 | return nfs4_add_lease(file, arg, lease, priv); |
| 7428 | case F_UNLCK: |
| 7429 | return nfs4_delete_lease(file, priv); |
| 7430 | default: |
| 7431 | return -EINVAL; |
| 7432 | } |
| 7433 | } |
| 7434 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7435 | 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] | 7436 | { |
| 7437 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7438 | int err; |
| 7439 | |
| 7440 | err = nfs4_set_lock_state(state, fl); |
| 7441 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7442 | return err; |
Olga Kornievskaia | 3d7a952 | 2020-08-20 18:52:43 -0400 | [diff] [blame] | 7443 | do { |
| 7444 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
| 7445 | if (err != -NFS4ERR_DELAY) |
| 7446 | break; |
| 7447 | ssleep(1); |
| 7448 | } while (err == -NFS4ERR_DELAY); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7449 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7450 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7451 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7452 | struct nfs_release_lockowner_data { |
| 7453 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7454 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7455 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7456 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7457 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7458 | }; |
| 7459 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7460 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7461 | { |
| 7462 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7463 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7464 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7465 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7466 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7467 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7468 | } |
| 7469 | |
| 7470 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7471 | { |
| 7472 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7473 | struct nfs_server *server = data->server; |
| 7474 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7475 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7476 | |
| 7477 | switch (task->tk_status) { |
| 7478 | case 0: |
| 7479 | renew_lease(server, data->timestamp); |
| 7480 | break; |
| 7481 | case -NFS4ERR_STALE_CLIENTID: |
| 7482 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7483 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7484 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7485 | case -NFS4ERR_LEASE_MOVED: |
| 7486 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7487 | if (nfs4_async_handle_error(task, server, |
| 7488 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7489 | rpc_restart_call_prepare(task); |
| 7490 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7491 | } |
| 7492 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7493 | static void nfs4_release_lockowner_release(void *calldata) |
| 7494 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7495 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7496 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7497 | kfree(calldata); |
| 7498 | } |
| 7499 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7500 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7501 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7502 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7503 | .rpc_release = nfs4_release_lockowner_release, |
| 7504 | }; |
| 7505 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7506 | static void |
| 7507 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7508 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7509 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7510 | struct rpc_message msg = { |
| 7511 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7512 | }; |
| 7513 | |
| 7514 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7515 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7516 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7517 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7518 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7519 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7520 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7521 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7522 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7523 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7524 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7525 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7526 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7527 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7528 | 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] | 7529 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7530 | } |
| 7531 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7532 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7533 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7534 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7535 | struct user_namespace *mnt_userns, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7536 | struct dentry *unused, struct inode *inode, |
| 7537 | const char *key, const void *buf, |
| 7538 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7539 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7540 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7541 | } |
| 7542 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7543 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7544 | struct dentry *unused, struct inode *inode, |
| 7545 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7546 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7547 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7548 | } |
| 7549 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7550 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7551 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7552 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7553 | } |
| 7554 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7555 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7556 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7557 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7558 | struct user_namespace *mnt_userns, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7559 | struct dentry *unused, struct inode *inode, |
| 7560 | const char *key, const void *buf, |
| 7561 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7562 | { |
| 7563 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7564 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7565 | |
| 7566 | return -EOPNOTSUPP; |
| 7567 | } |
| 7568 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7569 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7570 | struct dentry *unused, struct inode *inode, |
| 7571 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7572 | { |
| 7573 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7574 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7575 | return -EOPNOTSUPP; |
| 7576 | } |
| 7577 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7578 | static ssize_t |
| 7579 | 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] | 7580 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7581 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7582 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7583 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7584 | len = security_inode_listsecurity(inode, list, list_len); |
Chengguang Xu | 82c596e | 2020-06-17 09:09:39 +0800 | [diff] [blame] | 7585 | if (len >= 0 && list_len && len > list_len) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7586 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7587 | } |
| 7588 | return len; |
| 7589 | } |
| 7590 | |
| 7591 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7592 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7593 | .get = nfs4_xattr_get_nfs4_label, |
| 7594 | .set = nfs4_xattr_set_nfs4_label, |
| 7595 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7596 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7597 | #else |
| 7598 | |
| 7599 | static ssize_t |
| 7600 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7601 | { |
| 7602 | return 0; |
| 7603 | } |
| 7604 | |
| 7605 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7606 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7607 | #ifdef CONFIG_NFS_V4_2 |
| 7608 | static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7609 | struct user_namespace *mnt_userns, |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7610 | struct dentry *unused, struct inode *inode, |
| 7611 | const char *key, const void *buf, |
| 7612 | size_t buflen, int flags) |
| 7613 | { |
| 7614 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7615 | int ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7616 | |
| 7617 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7618 | return -EOPNOTSUPP; |
| 7619 | |
| 7620 | /* |
| 7621 | * There is no mapping from the MAY_* flags to the NFS_ACCESS_XA* |
| 7622 | * flags right now. Handling of xattr operations use the normal |
| 7623 | * file read/write permissions. |
| 7624 | * |
| 7625 | * Just in case the server has other ideas (which RFC 8276 allows), |
| 7626 | * do a cached access check for the XA* flags to possibly avoid |
| 7627 | * doing an RPC and getting EACCES back. |
| 7628 | */ |
| 7629 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7630 | if (!(cache.mask & NFS_ACCESS_XAWRITE)) |
| 7631 | return -EACCES; |
| 7632 | } |
| 7633 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7634 | if (buf == NULL) { |
| 7635 | ret = nfs42_proc_removexattr(inode, key); |
| 7636 | if (!ret) |
| 7637 | nfs4_xattr_cache_remove(inode, key); |
| 7638 | } else { |
| 7639 | ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags); |
| 7640 | if (!ret) |
| 7641 | nfs4_xattr_cache_add(inode, key, buf, NULL, buflen); |
| 7642 | } |
| 7643 | |
| 7644 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7645 | } |
| 7646 | |
| 7647 | static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler, |
| 7648 | struct dentry *unused, struct inode *inode, |
| 7649 | const char *key, void *buf, size_t buflen) |
| 7650 | { |
| 7651 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7652 | ssize_t ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7653 | |
| 7654 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7655 | return -EOPNOTSUPP; |
| 7656 | |
| 7657 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7658 | if (!(cache.mask & NFS_ACCESS_XAREAD)) |
| 7659 | return -EACCES; |
| 7660 | } |
| 7661 | |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 7662 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7663 | if (ret) |
| 7664 | return ret; |
| 7665 | |
| 7666 | ret = nfs4_xattr_cache_get(inode, key, buf, buflen); |
| 7667 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7668 | return ret; |
| 7669 | |
| 7670 | ret = nfs42_proc_getxattr(inode, key, buf, buflen); |
| 7671 | |
| 7672 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | static ssize_t |
| 7676 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7677 | { |
| 7678 | u64 cookie; |
| 7679 | bool eof; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7680 | ssize_t ret, size; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7681 | char *buf; |
| 7682 | size_t buflen; |
| 7683 | struct nfs_access_entry cache; |
| 7684 | |
| 7685 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7686 | return 0; |
| 7687 | |
| 7688 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7689 | if (!(cache.mask & NFS_ACCESS_XALIST)) |
| 7690 | return 0; |
| 7691 | } |
| 7692 | |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 7693 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7694 | if (ret) |
| 7695 | return ret; |
| 7696 | |
| 7697 | ret = nfs4_xattr_cache_list(inode, list, list_len); |
| 7698 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7699 | return ret; |
| 7700 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7701 | cookie = 0; |
| 7702 | eof = false; |
| 7703 | buflen = list_len ? list_len : XATTR_LIST_MAX; |
| 7704 | buf = list_len ? list : NULL; |
| 7705 | size = 0; |
| 7706 | |
| 7707 | while (!eof) { |
| 7708 | ret = nfs42_proc_listxattrs(inode, buf, buflen, |
| 7709 | &cookie, &eof); |
| 7710 | if (ret < 0) |
| 7711 | return ret; |
| 7712 | |
| 7713 | if (list_len) { |
| 7714 | buf += ret; |
| 7715 | buflen -= ret; |
| 7716 | } |
| 7717 | size += ret; |
| 7718 | } |
| 7719 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7720 | if (list_len) |
| 7721 | nfs4_xattr_cache_set_list(inode, list, size); |
| 7722 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7723 | return size; |
| 7724 | } |
| 7725 | |
| 7726 | #else |
| 7727 | |
| 7728 | static ssize_t |
| 7729 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7730 | { |
| 7731 | return 0; |
| 7732 | } |
| 7733 | #endif /* CONFIG_NFS_V4_2 */ |
| 7734 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7735 | /* |
| 7736 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7737 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7738 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7739 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7740 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7741 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7742 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7743 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7744 | return; |
| 7745 | |
| 7746 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7747 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7748 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7749 | fattr->nlink = 2; |
| 7750 | } |
| 7751 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7752 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7753 | const struct qstr *name, |
| 7754 | struct nfs4_fs_locations *fs_locations, |
| 7755 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7756 | { |
| 7757 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7758 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7759 | struct nfs4_fs_locations_arg args = { |
| 7760 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7761 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7762 | .page = page, |
| 7763 | .bitmask = bitmask, |
| 7764 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7765 | struct nfs4_fs_locations_res res = { |
| 7766 | .fs_locations = fs_locations, |
| 7767 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7768 | struct rpc_message msg = { |
| 7769 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7770 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7771 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7772 | }; |
| 7773 | int status; |
| 7774 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7775 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7776 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7777 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7778 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7779 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7780 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7781 | * is not supported */ |
| 7782 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7783 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7784 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7785 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7786 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7787 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7788 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7789 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7790 | 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] | 7791 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7792 | return status; |
| 7793 | } |
| 7794 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7795 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7796 | const struct qstr *name, |
| 7797 | struct nfs4_fs_locations *fs_locations, |
| 7798 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7799 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7800 | struct nfs4_exception exception = { |
| 7801 | .interruptible = true, |
| 7802 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7803 | int err; |
| 7804 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7805 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7806 | fs_locations, page); |
| 7807 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7808 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7809 | &exception); |
| 7810 | } while (exception.retry); |
| 7811 | return err; |
| 7812 | } |
| 7813 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7814 | /* |
| 7815 | * This operation also signals the server that this client is |
| 7816 | * performing migration recovery. The server can stop returning |
| 7817 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7818 | * appended to this compound to identify the client ID which is |
| 7819 | * performing recovery. |
| 7820 | */ |
| 7821 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7822 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7823 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7824 | { |
| 7825 | struct nfs_server *server = NFS_SERVER(inode); |
| 7826 | struct rpc_clnt *clnt = server->client; |
| 7827 | u32 bitmask[2] = { |
| 7828 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7829 | }; |
| 7830 | struct nfs4_fs_locations_arg args = { |
| 7831 | .clientid = server->nfs_client->cl_clientid, |
| 7832 | .fh = NFS_FH(inode), |
| 7833 | .page = page, |
| 7834 | .bitmask = bitmask, |
| 7835 | .migration = 1, /* skip LOOKUP */ |
| 7836 | .renew = 1, /* append RENEW */ |
| 7837 | }; |
| 7838 | struct nfs4_fs_locations_res res = { |
| 7839 | .fs_locations = locations, |
| 7840 | .migration = 1, |
| 7841 | .renew = 1, |
| 7842 | }; |
| 7843 | struct rpc_message msg = { |
| 7844 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7845 | .rpc_argp = &args, |
| 7846 | .rpc_resp = &res, |
| 7847 | .rpc_cred = cred, |
| 7848 | }; |
| 7849 | unsigned long now = jiffies; |
| 7850 | int status; |
| 7851 | |
| 7852 | nfs_fattr_init(&locations->fattr); |
| 7853 | locations->server = server; |
| 7854 | locations->nlocations = 0; |
| 7855 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7856 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7857 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7858 | &args.seq_args, &res.seq_res); |
| 7859 | if (status) |
| 7860 | return status; |
| 7861 | |
| 7862 | renew_lease(server, now); |
| 7863 | return 0; |
| 7864 | } |
| 7865 | |
| 7866 | #ifdef CONFIG_NFS_V4_1 |
| 7867 | |
| 7868 | /* |
| 7869 | * This operation also signals the server that this client is |
| 7870 | * performing migration recovery. The server can stop asserting |
| 7871 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7872 | * performing this operation is identified in the SEQUENCE |
| 7873 | * operation in this compound. |
| 7874 | * |
| 7875 | * When the client supports GETATTR(fs_locations_info), it can |
| 7876 | * be plumbed in here. |
| 7877 | */ |
| 7878 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7879 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7880 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7881 | { |
| 7882 | struct nfs_server *server = NFS_SERVER(inode); |
| 7883 | struct rpc_clnt *clnt = server->client; |
| 7884 | u32 bitmask[2] = { |
| 7885 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7886 | }; |
| 7887 | struct nfs4_fs_locations_arg args = { |
| 7888 | .fh = NFS_FH(inode), |
| 7889 | .page = page, |
| 7890 | .bitmask = bitmask, |
| 7891 | .migration = 1, /* skip LOOKUP */ |
| 7892 | }; |
| 7893 | struct nfs4_fs_locations_res res = { |
| 7894 | .fs_locations = locations, |
| 7895 | .migration = 1, |
| 7896 | }; |
| 7897 | struct rpc_message msg = { |
| 7898 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7899 | .rpc_argp = &args, |
| 7900 | .rpc_resp = &res, |
| 7901 | .rpc_cred = cred, |
| 7902 | }; |
| 7903 | int status; |
| 7904 | |
| 7905 | nfs_fattr_init(&locations->fattr); |
| 7906 | locations->server = server; |
| 7907 | locations->nlocations = 0; |
| 7908 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7909 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7910 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7911 | &args.seq_args, &res.seq_res); |
| 7912 | if (status == NFS4_OK && |
| 7913 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7914 | status = -NFS4ERR_LEASE_MOVED; |
| 7915 | return status; |
| 7916 | } |
| 7917 | |
| 7918 | #endif /* CONFIG_NFS_V4_1 */ |
| 7919 | |
| 7920 | /** |
| 7921 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7922 | * @inode: inode on FSID that is migrating |
| 7923 | * @locations: result of query |
| 7924 | * @page: buffer |
| 7925 | * @cred: credential to use for this operation |
| 7926 | * |
| 7927 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7928 | * operation failed, or a negative errno if a local error occurred. |
| 7929 | * |
| 7930 | * On success, "locations" is filled in, but if the server has |
| 7931 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7932 | * asserted. |
| 7933 | * |
| 7934 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7935 | * from this client that require migration recovery. |
| 7936 | */ |
| 7937 | int nfs4_proc_get_locations(struct inode *inode, |
| 7938 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7939 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7940 | { |
| 7941 | struct nfs_server *server = NFS_SERVER(inode); |
| 7942 | struct nfs_client *clp = server->nfs_client; |
| 7943 | const struct nfs4_mig_recovery_ops *ops = |
| 7944 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7945 | struct nfs4_exception exception = { |
| 7946 | .interruptible = true, |
| 7947 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7948 | int status; |
| 7949 | |
| 7950 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7951 | (unsigned long long)server->fsid.major, |
| 7952 | (unsigned long long)server->fsid.minor, |
| 7953 | clp->cl_hostname); |
| 7954 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7955 | |
| 7956 | do { |
| 7957 | status = ops->get_locations(inode, locations, page, cred); |
| 7958 | if (status != -NFS4ERR_DELAY) |
| 7959 | break; |
| 7960 | nfs4_handle_exception(server, status, &exception); |
| 7961 | } while (exception.retry); |
| 7962 | return status; |
| 7963 | } |
| 7964 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7965 | /* |
| 7966 | * This operation also signals the server that this client is |
| 7967 | * performing "lease moved" recovery. The server can stop |
| 7968 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7969 | * is appended to this compound to identify the client ID which is |
| 7970 | * performing recovery. |
| 7971 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7972 | 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] | 7973 | { |
| 7974 | struct nfs_server *server = NFS_SERVER(inode); |
| 7975 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7976 | struct rpc_clnt *clnt = server->client; |
| 7977 | struct nfs4_fsid_present_arg args = { |
| 7978 | .fh = NFS_FH(inode), |
| 7979 | .clientid = clp->cl_clientid, |
| 7980 | .renew = 1, /* append RENEW */ |
| 7981 | }; |
| 7982 | struct nfs4_fsid_present_res res = { |
| 7983 | .renew = 1, |
| 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 | unsigned long now = jiffies; |
| 7992 | int status; |
| 7993 | |
| 7994 | res.fh = nfs_alloc_fhandle(); |
| 7995 | if (res.fh == NULL) |
| 7996 | return -ENOMEM; |
| 7997 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7998 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7999 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 8000 | &args.seq_args, &res.seq_res); |
| 8001 | nfs_free_fhandle(res.fh); |
| 8002 | if (status) |
| 8003 | return status; |
| 8004 | |
| 8005 | do_renew_lease(clp, now); |
| 8006 | return 0; |
| 8007 | } |
| 8008 | |
| 8009 | #ifdef CONFIG_NFS_V4_1 |
| 8010 | |
| 8011 | /* |
| 8012 | * This operation also signals the server that this client is |
| 8013 | * performing "lease moved" recovery. The server can stop asserting |
| 8014 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 8015 | * this operation is identified in the SEQUENCE operation in this |
| 8016 | * compound. |
| 8017 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8018 | 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] | 8019 | { |
| 8020 | struct nfs_server *server = NFS_SERVER(inode); |
| 8021 | struct rpc_clnt *clnt = server->client; |
| 8022 | struct nfs4_fsid_present_arg args = { |
| 8023 | .fh = NFS_FH(inode), |
| 8024 | }; |
| 8025 | struct nfs4_fsid_present_res res = { |
| 8026 | }; |
| 8027 | struct rpc_message msg = { |
| 8028 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 8029 | .rpc_argp = &args, |
| 8030 | .rpc_resp = &res, |
| 8031 | .rpc_cred = cred, |
| 8032 | }; |
| 8033 | int status; |
| 8034 | |
| 8035 | res.fh = nfs_alloc_fhandle(); |
| 8036 | if (res.fh == NULL) |
| 8037 | return -ENOMEM; |
| 8038 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8039 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8040 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 8041 | &args.seq_args, &res.seq_res); |
| 8042 | nfs_free_fhandle(res.fh); |
| 8043 | if (status == NFS4_OK && |
| 8044 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 8045 | status = -NFS4ERR_LEASE_MOVED; |
| 8046 | return status; |
| 8047 | } |
| 8048 | |
| 8049 | #endif /* CONFIG_NFS_V4_1 */ |
| 8050 | |
| 8051 | /** |
| 8052 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 8053 | * @inode: inode on FSID to check |
| 8054 | * @cred: credential to use for this operation |
| 8055 | * |
| 8056 | * Server indicates whether the FSID is present, moved, or not |
| 8057 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 8058 | * condition for this client ID. |
| 8059 | * |
| 8060 | * Returns NFS4_OK if the FSID is present on this server, |
| 8061 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 8062 | * NFS4ERR code if some error occurred on the server, or a |
| 8063 | * negative errno if a local failure occurred. |
| 8064 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8065 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8066 | { |
| 8067 | struct nfs_server *server = NFS_SERVER(inode); |
| 8068 | struct nfs_client *clp = server->nfs_client; |
| 8069 | const struct nfs4_mig_recovery_ops *ops = |
| 8070 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8071 | struct nfs4_exception exception = { |
| 8072 | .interruptible = true, |
| 8073 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8074 | int status; |
| 8075 | |
| 8076 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 8077 | (unsigned long long)server->fsid.major, |
| 8078 | (unsigned long long)server->fsid.minor, |
| 8079 | clp->cl_hostname); |
| 8080 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 8081 | |
| 8082 | do { |
| 8083 | status = ops->fsid_present(inode, cred); |
| 8084 | if (status != -NFS4ERR_DELAY) |
| 8085 | break; |
| 8086 | nfs4_handle_exception(server, status, &exception); |
| 8087 | } while (exception.retry); |
| 8088 | return status; |
| 8089 | } |
| 8090 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 8091 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8092 | * If 'use_integrity' is true and the state managment nfs_client |
| 8093 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 8094 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 8095 | * Considerations sections. Otherwise, just use the user cred with the |
| 8096 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 8097 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8098 | 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] | 8099 | { |
| 8100 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8101 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 8102 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8103 | struct nfs4_secinfo_arg args = { |
| 8104 | .dir_fh = NFS_FH(dir), |
| 8105 | .name = name, |
| 8106 | }; |
| 8107 | struct nfs4_secinfo_res res = { |
| 8108 | .flavors = flavors, |
| 8109 | }; |
| 8110 | struct rpc_message msg = { |
| 8111 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 8112 | .rpc_argp = &args, |
| 8113 | .rpc_resp = &res, |
| 8114 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8115 | struct nfs4_call_sync_data data = { |
| 8116 | .seq_server = NFS_SERVER(dir), |
| 8117 | .seq_args = &args.seq_args, |
| 8118 | .seq_res = &res.seq_res, |
| 8119 | }; |
| 8120 | struct rpc_task_setup task_setup = { |
| 8121 | .rpc_client = clnt, |
| 8122 | .rpc_message = &msg, |
| 8123 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 8124 | .callback_data = &data, |
| 8125 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 8126 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8127 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8128 | |
| 8129 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8130 | clnt = clp->cl_rpcclient; |
| 8131 | task_setup.rpc_client = clnt; |
| 8132 | |
| 8133 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8134 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8135 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8136 | |
| 8137 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8138 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8139 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 8140 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 8141 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8142 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8143 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8144 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8145 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8146 | return status; |
| 8147 | } |
| 8148 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 8149 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 8150 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8151 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8152 | struct nfs4_exception exception = { |
| 8153 | .interruptible = true, |
| 8154 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8155 | int err; |
| 8156 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8157 | err = -NFS4ERR_WRONGSEC; |
| 8158 | |
| 8159 | /* try to use integrity protection with machine cred */ |
| 8160 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 8161 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 8162 | |
| 8163 | /* |
| 8164 | * if unable to use integrity protection, or SECINFO with |
| 8165 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8166 | * disallowed by spec, but exists in deployed servers) use |
| 8167 | * the current filesystem's rpc_client and the user cred. |
| 8168 | */ |
| 8169 | if (err == -NFS4ERR_WRONGSEC) |
| 8170 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 8171 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 8172 | trace_nfs4_secinfo(dir, name, err); |
| 8173 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8174 | &exception); |
| 8175 | } while (exception.retry); |
| 8176 | return err; |
| 8177 | } |
| 8178 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8179 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8180 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8181 | * Check the exchange flags returned by the server for invalid flags, having |
| 8182 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 8183 | * DS flags set. |
| 8184 | */ |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8185 | static int nfs4_check_cl_exchange_flags(u32 flags, u32 version) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8186 | { |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8187 | if (version >= 2 && (flags & ~EXCHGID4_2_FLAG_MASK_R)) |
| 8188 | goto out_inval; |
| 8189 | else if (version < 2 && (flags & ~EXCHGID4_FLAG_MASK_R)) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8190 | goto out_inval; |
| 8191 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 8192 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 8193 | goto out_inval; |
| 8194 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 8195 | goto out_inval; |
| 8196 | return NFS_OK; |
| 8197 | out_inval: |
| 8198 | return -NFS4ERR_INVAL; |
| 8199 | } |
| 8200 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8201 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 8202 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 8203 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8204 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 8205 | if (a->server_scope_sz != b->server_scope_sz) |
| 8206 | return false; |
| 8207 | 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] | 8208 | } |
| 8209 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8210 | static void |
| 8211 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 8212 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8213 | 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] | 8214 | 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] | 8215 | struct nfs_client *clp = args->client; |
| 8216 | |
| 8217 | switch (task->tk_status) { |
| 8218 | case -NFS4ERR_BADSESSION: |
| 8219 | case -NFS4ERR_DEADSESSION: |
| 8220 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8221 | task->tk_status); |
| 8222 | } |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8223 | if (args->dir == NFS4_CDFC4_FORE_OR_BOTH && |
| 8224 | res->dir != NFS4_CDFS4_BOTH) { |
| 8225 | rpc_task_close_connection(task); |
| 8226 | if (args->retries++ < MAX_BIND_CONN_TO_SESSION_RETRIES) |
| 8227 | rpc_restart_call(task); |
| 8228 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8229 | } |
| 8230 | |
| 8231 | 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] | 8232 | .rpc_call_done = nfs4_bind_one_conn_to_session_done, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8233 | }; |
| 8234 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8235 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8236 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8237 | * |
| 8238 | * The 4.1 client currently uses the same TCP connection for the |
| 8239 | * fore and backchannel. |
| 8240 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8241 | static |
| 8242 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 8243 | struct rpc_xprt *xprt, |
| 8244 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8245 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8246 | { |
| 8247 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8248 | struct nfs41_bind_conn_to_session_args args = { |
| 8249 | .client = clp, |
| 8250 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8251 | .retries = 0, |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8252 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8253 | struct nfs41_bind_conn_to_session_res res; |
| 8254 | struct rpc_message msg = { |
| 8255 | .rpc_proc = |
| 8256 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8257 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8258 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 8259 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8260 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8261 | struct rpc_task_setup task_setup_data = { |
| 8262 | .rpc_client = clnt, |
| 8263 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8264 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8265 | .rpc_message = &msg, |
| 8266 | .flags = RPC_TASK_TIMEOUT, |
| 8267 | }; |
| 8268 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8269 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8270 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 8271 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 8272 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8273 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8274 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 8275 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 8276 | args.dir = NFS4_CDFC4_FORE; |
| 8277 | |
| 8278 | task = rpc_run_task(&task_setup_data); |
| 8279 | if (!IS_ERR(task)) { |
| 8280 | status = task->tk_status; |
| 8281 | rpc_put_task(task); |
| 8282 | } else |
| 8283 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8284 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8285 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8286 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8287 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 8288 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8289 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8290 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8291 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8292 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 8293 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8294 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8295 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8296 | 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] | 8297 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 8298 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8299 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8300 | } |
| 8301 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8302 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8303 | return status; |
| 8304 | } |
| 8305 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8306 | struct rpc_bind_conn_calldata { |
| 8307 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8308 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8309 | }; |
| 8310 | |
| 8311 | static int |
| 8312 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 8313 | struct rpc_xprt *xprt, |
| 8314 | void *calldata) |
| 8315 | { |
| 8316 | struct rpc_bind_conn_calldata *p = calldata; |
| 8317 | |
| 8318 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 8319 | } |
| 8320 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8321 | 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] | 8322 | { |
| 8323 | struct rpc_bind_conn_calldata data = { |
| 8324 | .clp = clp, |
| 8325 | .cred = cred, |
| 8326 | }; |
| 8327 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 8328 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 8329 | } |
| 8330 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8331 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8332 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 8333 | * 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] | 8334 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8335 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 8336 | .how = SP4_MACH_CRED, |
| 8337 | .enforce.u.words = { |
| 8338 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8339 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8340 | 1 << (OP_CREATE_SESSION - 32) | |
| 8341 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8342 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8343 | }, |
| 8344 | .allow.u.words = { |
| 8345 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8346 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8347 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8348 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8349 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8350 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8351 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8352 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8353 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8354 | 1 << (OP_FREE_STATEID - 32) | |
| 8355 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8356 | } |
| 8357 | }; |
| 8358 | |
| 8359 | /* |
| 8360 | * Select the state protection mode for client `clp' given the server results |
| 8361 | * from exchange_id in `sp'. |
| 8362 | * |
| 8363 | * Returns 0 on success, negative errno otherwise. |
| 8364 | */ |
| 8365 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8366 | struct nfs41_state_protection *sp) |
| 8367 | { |
| 8368 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8369 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8370 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8371 | 1 << (OP_CREATE_SESSION - 32) | |
| 8372 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8373 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8374 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8375 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8376 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8377 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8378 | |
| 8379 | if (sp->how == SP4_MACH_CRED) { |
| 8380 | /* Print state protect result */ |
| 8381 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8382 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8383 | if (test_bit(i, sp->enforce.u.longs)) |
| 8384 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8385 | if (test_bit(i, sp->allow.u.longs)) |
| 8386 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8387 | } |
| 8388 | |
| 8389 | /* make sure nothing is on enforce list that isn't supported */ |
| 8390 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8391 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8392 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8393 | ret = -EINVAL; |
| 8394 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8395 | } |
| 8396 | } |
| 8397 | |
| 8398 | /* |
| 8399 | * Minimal mode - state operations are allowed to use machine |
| 8400 | * credential. Note this already happens by default, so the |
| 8401 | * client doesn't have to do anything more than the negotiation. |
| 8402 | * |
| 8403 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8404 | * we're already using the machine cred for exchange_id |
| 8405 | * and will never use a different cred. |
| 8406 | */ |
| 8407 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8408 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8409 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8410 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8411 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8412 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8413 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8414 | } else { |
| 8415 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8416 | ret = -EINVAL; |
| 8417 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8418 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8419 | |
| 8420 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8421 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8422 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8423 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8424 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8425 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8426 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8427 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8428 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8429 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8430 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8431 | } |
| 8432 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8433 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8434 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8435 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8436 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8437 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8438 | |
| 8439 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8440 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8441 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8442 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8443 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8444 | |
| 8445 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8446 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8447 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8448 | } |
| 8449 | |
| 8450 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8451 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8452 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8453 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8454 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8455 | out: |
| 8456 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8457 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8458 | } |
| 8459 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8460 | struct nfs41_exchange_id_data { |
| 8461 | struct nfs41_exchange_id_res res; |
| 8462 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8463 | }; |
| 8464 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8465 | static void nfs4_exchange_id_release(void *data) |
| 8466 | { |
| 8467 | struct nfs41_exchange_id_data *cdata = |
| 8468 | (struct nfs41_exchange_id_data *)data; |
| 8469 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8470 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8471 | kfree(cdata->res.impl_id); |
| 8472 | kfree(cdata->res.server_scope); |
| 8473 | kfree(cdata->res.server_owner); |
| 8474 | kfree(cdata); |
| 8475 | } |
| 8476 | |
| 8477 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8478 | .rpc_release = nfs4_exchange_id_release, |
| 8479 | }; |
| 8480 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8481 | /* |
| 8482 | * _nfs4_proc_exchange_id() |
| 8483 | * |
| 8484 | * Wrapper for EXCHANGE_ID operation. |
| 8485 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8486 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8487 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8488 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8489 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8490 | struct rpc_message msg = { |
| 8491 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8492 | .rpc_cred = cred, |
| 8493 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8494 | struct rpc_task_setup task_setup_data = { |
| 8495 | .rpc_client = clp->cl_rpcclient, |
| 8496 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8497 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8498 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8499 | }; |
| 8500 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8501 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8502 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8503 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8504 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8505 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8506 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8507 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8508 | if (!calldata) |
| 8509 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8510 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8511 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8512 | |
| 8513 | status = nfs4_init_uniform_client_string(clp); |
| 8514 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8515 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8516 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8517 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8518 | GFP_NOFS); |
| 8519 | status = -ENOMEM; |
| 8520 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8521 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8522 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8523 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8524 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8525 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8526 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8527 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8528 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8529 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8530 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8531 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8532 | switch (sp4_how) { |
| 8533 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8534 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8535 | break; |
| 8536 | |
| 8537 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8538 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8539 | break; |
| 8540 | |
| 8541 | default: |
| 8542 | /* unsupported! */ |
| 8543 | WARN_ON_ONCE(1); |
| 8544 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8545 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8546 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8547 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8548 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8549 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8550 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8551 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8552 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8553 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8554 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8555 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8556 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8557 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8558 | #endif |
| 8559 | msg.rpc_argp = &calldata->args; |
| 8560 | msg.rpc_resp = &calldata->res; |
| 8561 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8562 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8563 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8564 | |
| 8565 | out_impl_id: |
| 8566 | kfree(calldata->res.impl_id); |
| 8567 | out_server_scope: |
| 8568 | kfree(calldata->res.server_scope); |
| 8569 | out_server_owner: |
| 8570 | kfree(calldata->res.server_owner); |
| 8571 | out_calldata: |
| 8572 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8573 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8574 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8575 | return ERR_PTR(status); |
| 8576 | } |
| 8577 | |
| 8578 | /* |
| 8579 | * _nfs4_proc_exchange_id() |
| 8580 | * |
| 8581 | * Wrapper for EXCHANGE_ID operation. |
| 8582 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8583 | 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] | 8584 | u32 sp4_how) |
| 8585 | { |
| 8586 | struct rpc_task *task; |
| 8587 | struct nfs41_exchange_id_args *argp; |
| 8588 | struct nfs41_exchange_id_res *resp; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8589 | unsigned long now = jiffies; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8590 | int status; |
| 8591 | |
| 8592 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8593 | if (IS_ERR(task)) |
| 8594 | return PTR_ERR(task); |
| 8595 | |
| 8596 | argp = task->tk_msg.rpc_argp; |
| 8597 | resp = task->tk_msg.rpc_resp; |
| 8598 | status = task->tk_status; |
| 8599 | if (status != 0) |
| 8600 | goto out; |
| 8601 | |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8602 | status = nfs4_check_cl_exchange_flags(resp->flags, |
| 8603 | clp->cl_mvops->minor_version); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8604 | if (status != 0) |
| 8605 | goto out; |
| 8606 | |
| 8607 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8608 | if (status != 0) |
| 8609 | goto out; |
| 8610 | |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8611 | do_renew_lease(clp, now); |
| 8612 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8613 | clp->cl_clientid = resp->clientid; |
| 8614 | clp->cl_exchange_flags = resp->flags; |
| 8615 | clp->cl_seqid = resp->seqid; |
| 8616 | /* Client ID is not confirmed */ |
| 8617 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8618 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8619 | &clp->cl_session->session_state); |
| 8620 | |
| 8621 | if (clp->cl_serverscope != NULL && |
| 8622 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8623 | resp->server_scope)) { |
| 8624 | dprintk("%s: server_scope mismatch detected\n", |
| 8625 | __func__); |
| 8626 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8627 | } |
| 8628 | |
| 8629 | swap(clp->cl_serverowner, resp->server_owner); |
| 8630 | swap(clp->cl_serverscope, resp->server_scope); |
| 8631 | swap(clp->cl_implid, resp->impl_id); |
| 8632 | |
| 8633 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8634 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8635 | sizeof(clp->cl_confirm.data)); |
| 8636 | out: |
| 8637 | trace_nfs4_exchange_id(clp, status); |
| 8638 | rpc_put_task(task); |
| 8639 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8640 | } |
| 8641 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8642 | /* |
| 8643 | * nfs4_proc_exchange_id() |
| 8644 | * |
| 8645 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8646 | * |
| 8647 | * Since the clientid has expired, all compounds using sessions |
| 8648 | * associated with the stale clientid will be returning |
| 8649 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8650 | * be in some phase of session reset. |
| 8651 | * |
| 8652 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8653 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8654 | 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] | 8655 | { |
| 8656 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8657 | int status; |
| 8658 | |
| 8659 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8660 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8661 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8662 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8663 | if (!status) |
| 8664 | return 0; |
| 8665 | } |
| 8666 | |
| 8667 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8668 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8669 | } |
| 8670 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8671 | /** |
| 8672 | * nfs4_test_session_trunk |
| 8673 | * |
| 8674 | * This is an add_xprt_test() test function called from |
| 8675 | * rpc_clnt_setup_test_and_add_xprt. |
| 8676 | * |
| 8677 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8678 | * and is dereferrenced in nfs4_exchange_id_release |
| 8679 | * |
| 8680 | * Upon success, add the new transport to the rpc_clnt |
| 8681 | * |
| 8682 | * @clnt: struct rpc_clnt to get new transport |
| 8683 | * @xprt: the rpc_xprt to test |
| 8684 | * @data: call data for _nfs4_proc_exchange_id. |
| 8685 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8686 | 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] | 8687 | void *data) |
| 8688 | { |
| 8689 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8690 | struct rpc_task *task; |
| 8691 | int status; |
| 8692 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8693 | u32 sp4_how; |
| 8694 | |
| 8695 | dprintk("--> %s try %s\n", __func__, |
| 8696 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8697 | |
| 8698 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8699 | |
| 8700 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8701 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8702 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8703 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8704 | |
| 8705 | status = task->tk_status; |
| 8706 | if (status == 0) |
| 8707 | status = nfs4_detect_session_trunking(adata->clp, |
| 8708 | task->tk_msg.rpc_resp, xprt); |
| 8709 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8710 | if (status == 0) |
| 8711 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8712 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8713 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8714 | } |
| 8715 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8716 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8717 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8718 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8719 | { |
| 8720 | struct rpc_message msg = { |
| 8721 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8722 | .rpc_argp = clp, |
| 8723 | .rpc_cred = cred, |
| 8724 | }; |
| 8725 | int status; |
| 8726 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8727 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8728 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8729 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8730 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8731 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8732 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8733 | return status; |
| 8734 | } |
| 8735 | |
| 8736 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8737 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8738 | { |
| 8739 | unsigned int loop; |
| 8740 | int ret; |
| 8741 | |
| 8742 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8743 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8744 | switch (ret) { |
| 8745 | case -NFS4ERR_DELAY: |
| 8746 | case -NFS4ERR_CLIENTID_BUSY: |
| 8747 | ssleep(1); |
| 8748 | break; |
| 8749 | default: |
| 8750 | return ret; |
| 8751 | } |
| 8752 | } |
| 8753 | return 0; |
| 8754 | } |
| 8755 | |
| 8756 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8757 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8758 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8759 | int ret = 0; |
| 8760 | |
| 8761 | if (clp->cl_mvops->minor_version < 1) |
| 8762 | goto out; |
| 8763 | if (clp->cl_exchange_flags == 0) |
| 8764 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8765 | if (clp->cl_preserve_clid) |
| 8766 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8767 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8768 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8769 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8770 | switch (ret) { |
| 8771 | case 0: |
| 8772 | case -NFS4ERR_STALE_CLIENTID: |
| 8773 | clp->cl_exchange_flags = 0; |
| 8774 | } |
| 8775 | out: |
| 8776 | return ret; |
| 8777 | } |
| 8778 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8779 | #endif /* CONFIG_NFS_V4_1 */ |
| 8780 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8781 | struct nfs4_get_lease_time_data { |
| 8782 | struct nfs4_get_lease_time_args *args; |
| 8783 | struct nfs4_get_lease_time_res *res; |
| 8784 | struct nfs_client *clp; |
| 8785 | }; |
| 8786 | |
| 8787 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8788 | void *calldata) |
| 8789 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8790 | struct nfs4_get_lease_time_data *data = |
| 8791 | (struct nfs4_get_lease_time_data *)calldata; |
| 8792 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8793 | /* just setup sequence, do not trigger session recovery |
| 8794 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8795 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8796 | &data->args->la_seq_args, |
| 8797 | &data->res->lr_seq_res, |
| 8798 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8799 | } |
| 8800 | |
| 8801 | /* |
| 8802 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8803 | * from sequence operation or clientid errors. |
| 8804 | */ |
| 8805 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8806 | { |
| 8807 | struct nfs4_get_lease_time_data *data = |
| 8808 | (struct nfs4_get_lease_time_data *)calldata; |
| 8809 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8810 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8811 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8812 | switch (task->tk_status) { |
| 8813 | case -NFS4ERR_DELAY: |
| 8814 | case -NFS4ERR_GRACE: |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8815 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8816 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 8817 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8818 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8819 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8820 | return; |
| 8821 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8822 | } |
| 8823 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8824 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8825 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8826 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8827 | }; |
| 8828 | |
| 8829 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8830 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8831 | struct nfs4_get_lease_time_args args; |
| 8832 | struct nfs4_get_lease_time_res res = { |
| 8833 | .lr_fsinfo = fsinfo, |
| 8834 | }; |
| 8835 | struct nfs4_get_lease_time_data data = { |
| 8836 | .args = &args, |
| 8837 | .res = &res, |
| 8838 | .clp = clp, |
| 8839 | }; |
| 8840 | struct rpc_message msg = { |
| 8841 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8842 | .rpc_argp = &args, |
| 8843 | .rpc_resp = &res, |
| 8844 | }; |
| 8845 | struct rpc_task_setup task_setup = { |
| 8846 | .rpc_client = clp->cl_rpcclient, |
| 8847 | .rpc_message = &msg, |
| 8848 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8849 | .callback_data = &data, |
| 8850 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8851 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8852 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8853 | 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] | 8854 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8855 | } |
| 8856 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8857 | #ifdef CONFIG_NFS_V4_1 |
| 8858 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8859 | /* |
| 8860 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8861 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8862 | * use them. |
| 8863 | * |
| 8864 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8865 | * always set csa_cachethis to FALSE because the current implementation |
| 8866 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8867 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8868 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8869 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8870 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8871 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8872 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8873 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8874 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8875 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8876 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8877 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8878 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8879 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8880 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8881 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8882 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8883 | |
| 8884 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8885 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8886 | __func__, |
| 8887 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8888 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8889 | |
| 8890 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8891 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8892 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8893 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8894 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8895 | 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] | 8896 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8897 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8898 | |
| 8899 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8900 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8901 | __func__, |
| 8902 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8903 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8904 | args->bc_attrs.max_reqs); |
| 8905 | } |
| 8906 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8907 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8908 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8909 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8910 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8911 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8912 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8913 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8914 | return -EINVAL; |
| 8915 | /* |
| 8916 | * Our requested max_ops is the minimum we need; we're not |
| 8917 | * prepared to break up compounds into smaller pieces than that. |
| 8918 | * So, no point even trying to continue if the server won't |
| 8919 | * cooperate: |
| 8920 | */ |
| 8921 | if (rcvd->max_ops < sent->max_ops) |
| 8922 | return -EINVAL; |
| 8923 | if (rcvd->max_reqs == 0) |
| 8924 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8925 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8926 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8927 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8928 | } |
| 8929 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8930 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8931 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8932 | { |
| 8933 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8934 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8935 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8936 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8937 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8938 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8939 | return -EINVAL; |
| 8940 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8941 | return -EINVAL; |
| 8942 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8943 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8944 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8945 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8946 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8947 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8948 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8949 | return 0; |
| 8950 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8951 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8952 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8953 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8954 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8955 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8956 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8957 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8958 | if (ret) |
| 8959 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8960 | return nfs4_verify_back_channel_attrs(args, res); |
| 8961 | } |
| 8962 | |
| 8963 | static void nfs4_update_session(struct nfs4_session *session, |
| 8964 | struct nfs41_create_session_res *res) |
| 8965 | { |
| 8966 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8967 | /* Mark client id and session as being confirmed */ |
| 8968 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8969 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8970 | session->flags = res->flags; |
| 8971 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8972 | if (res->flags & SESSION4_BACK_CHAN) |
| 8973 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8974 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8975 | } |
| 8976 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8977 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8978 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8979 | { |
| 8980 | struct nfs4_session *session = clp->cl_session; |
| 8981 | struct nfs41_create_session_args args = { |
| 8982 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8983 | .clientid = clp->cl_clientid, |
| 8984 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8985 | .cb_program = NFS4_CALLBACK, |
| 8986 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8987 | struct nfs41_create_session_res res; |
| 8988 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8989 | struct rpc_message msg = { |
| 8990 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8991 | .rpc_argp = &args, |
| 8992 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8993 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8994 | }; |
| 8995 | int status; |
| 8996 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8997 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8998 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8999 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9000 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9001 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9002 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9003 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 9004 | switch (status) { |
| 9005 | case -NFS4ERR_STALE_CLIENTID: |
| 9006 | case -NFS4ERR_DELAY: |
| 9007 | case -ETIMEDOUT: |
| 9008 | case -EACCES: |
| 9009 | case -EAGAIN: |
| 9010 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 9011 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 9012 | |
| 9013 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 9014 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9015 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9016 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9017 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9018 | if (status) |
| 9019 | goto out; |
| 9020 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9021 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9022 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9023 | return status; |
| 9024 | } |
| 9025 | |
| 9026 | /* |
| 9027 | * Issues a CREATE_SESSION operation to the server. |
| 9028 | * It is the responsibility of the caller to verify the session is |
| 9029 | * expired before calling this routine. |
| 9030 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9031 | 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] | 9032 | { |
| 9033 | int status; |
| 9034 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9035 | struct nfs4_session *session = clp->cl_session; |
| 9036 | |
| 9037 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 9038 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9039 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9040 | if (status) |
| 9041 | goto out; |
| 9042 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 9043 | /* Init or reset the session slot tables */ |
| 9044 | status = nfs4_setup_session_slot_tables(session); |
| 9045 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9046 | if (status) |
| 9047 | goto out; |
| 9048 | |
| 9049 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 9050 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 9051 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9052 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9053 | return status; |
| 9054 | } |
| 9055 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9056 | /* |
| 9057 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 9058 | * The caller must serialize access to this routine. |
| 9059 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9060 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9061 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9062 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9063 | struct rpc_message msg = { |
| 9064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 9065 | .rpc_argp = session, |
| 9066 | .rpc_cred = cred, |
| 9067 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9068 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9069 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9070 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 9071 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 9072 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9073 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9074 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9075 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9076 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9077 | |
| 9078 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 9079 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9080 | "Session has been destroyed regardless...\n", status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9081 | return status; |
| 9082 | } |
| 9083 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 9084 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9085 | * Renew the cl_session lease. |
| 9086 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9087 | struct nfs4_sequence_data { |
| 9088 | struct nfs_client *clp; |
| 9089 | struct nfs4_sequence_args args; |
| 9090 | struct nfs4_sequence_res res; |
| 9091 | }; |
| 9092 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9093 | static void nfs41_sequence_release(void *data) |
| 9094 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9095 | struct nfs4_sequence_data *calldata = data; |
| 9096 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9097 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9098 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9099 | nfs4_schedule_state_renewal(clp); |
| 9100 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9101 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9102 | } |
| 9103 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9104 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9105 | { |
| 9106 | switch(task->tk_status) { |
| 9107 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9108 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 9109 | return -EAGAIN; |
| 9110 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9111 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9112 | } |
| 9113 | return 0; |
| 9114 | } |
| 9115 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9116 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9117 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9118 | struct nfs4_sequence_data *calldata = data; |
| 9119 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9120 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9121 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 9122 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9123 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9124 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9125 | if (task->tk_status < 0) { |
| 9126 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9127 | if (refcount_read(&clp->cl_count) == 1) |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 9128 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9129 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9130 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 9131 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9132 | return; |
| 9133 | } |
| 9134 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9135 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9136 | } |
| 9137 | |
| 9138 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 9139 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9140 | struct nfs4_sequence_data *calldata = data; |
| 9141 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9142 | struct nfs4_sequence_args *args; |
| 9143 | struct nfs4_sequence_res *res; |
| 9144 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9145 | args = task->tk_msg.rpc_argp; |
| 9146 | res = task->tk_msg.rpc_resp; |
| 9147 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9148 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9149 | } |
| 9150 | |
| 9151 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 9152 | .rpc_call_done = nfs41_sequence_call_done, |
| 9153 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9154 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9155 | }; |
| 9156 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9157 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9158 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9159 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9160 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9161 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9162 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9163 | struct rpc_message msg = { |
| 9164 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 9165 | .rpc_cred = cred, |
| 9166 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9167 | struct rpc_task_setup task_setup_data = { |
| 9168 | .rpc_client = clp->cl_rpcclient, |
| 9169 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9170 | .callback_ops = &nfs41_sequence_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9171 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT | RPC_TASK_MOVEABLE, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9172 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9173 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9174 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9175 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9176 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9177 | goto out_err; |
| 9178 | |
| 9179 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 9180 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9181 | if (calldata == NULL) |
| 9182 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9183 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9184 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9185 | msg.rpc_argp = &calldata->args; |
| 9186 | msg.rpc_resp = &calldata->res; |
| 9187 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9188 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9189 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9190 | ret = rpc_run_task(&task_setup_data); |
| 9191 | if (IS_ERR(ret)) |
| 9192 | goto out_err; |
| 9193 | return ret; |
| 9194 | out_put_clp: |
| 9195 | nfs_put_client(clp); |
| 9196 | out_err: |
| 9197 | nfs41_release_slot(slot); |
| 9198 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9199 | } |
| 9200 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9201 | 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] | 9202 | { |
| 9203 | struct rpc_task *task; |
| 9204 | int ret = 0; |
| 9205 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 9206 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 9207 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9208 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9209 | if (IS_ERR(task)) |
| 9210 | ret = PTR_ERR(task); |
| 9211 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 9212 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9213 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9214 | return ret; |
| 9215 | } |
| 9216 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9217 | 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] | 9218 | { |
| 9219 | struct rpc_task *task; |
| 9220 | int ret; |
| 9221 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9222 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9223 | if (IS_ERR(task)) { |
| 9224 | ret = PTR_ERR(task); |
| 9225 | goto out; |
| 9226 | } |
| 9227 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 9228 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9229 | ret = task->tk_status; |
| 9230 | rpc_put_task(task); |
| 9231 | out: |
| 9232 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9233 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9234 | } |
| 9235 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9236 | struct nfs4_reclaim_complete_data { |
| 9237 | struct nfs_client *clp; |
| 9238 | struct nfs41_reclaim_complete_args arg; |
| 9239 | struct nfs41_reclaim_complete_res res; |
| 9240 | }; |
| 9241 | |
| 9242 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 9243 | { |
| 9244 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9245 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9246 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9247 | &calldata->arg.seq_args, |
| 9248 | &calldata->res.seq_res, |
| 9249 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9250 | } |
| 9251 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9252 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9253 | { |
| 9254 | switch(task->tk_status) { |
| 9255 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 9256 | wake_up_all(&clp->cl_lock_waitq); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9257 | fallthrough; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9258 | case -NFS4ERR_COMPLETE_ALREADY: |
| 9259 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 9260 | break; |
| 9261 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9262 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9263 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 9264 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9265 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9266 | case -NFS4ERR_BADSESSION: |
| 9267 | case -NFS4ERR_DEADSESSION: |
| 9268 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9269 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9270 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9271 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9272 | } |
| 9273 | return 0; |
| 9274 | } |
| 9275 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9276 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 9277 | { |
| 9278 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9279 | struct nfs_client *clp = calldata->clp; |
| 9280 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 9281 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9282 | if (!nfs41_sequence_done(task, res)) |
| 9283 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9284 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9285 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9286 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 9287 | rpc_restart_call_prepare(task); |
| 9288 | return; |
| 9289 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9290 | } |
| 9291 | |
| 9292 | static void nfs4_free_reclaim_complete_data(void *data) |
| 9293 | { |
| 9294 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9295 | |
| 9296 | kfree(calldata); |
| 9297 | } |
| 9298 | |
| 9299 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 9300 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 9301 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 9302 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 9303 | }; |
| 9304 | |
| 9305 | /* |
| 9306 | * Issue a global reclaim complete. |
| 9307 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9308 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9309 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9310 | { |
| 9311 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9312 | struct rpc_message msg = { |
| 9313 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9314 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9315 | }; |
| 9316 | struct rpc_task_setup task_setup_data = { |
| 9317 | .rpc_client = clp->cl_rpcclient, |
| 9318 | .rpc_message = &msg, |
| 9319 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9320 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9321 | }; |
| 9322 | int status = -ENOMEM; |
| 9323 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 9324 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9325 | if (calldata == NULL) |
| 9326 | goto out; |
| 9327 | calldata->clp = clp; |
| 9328 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9329 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9330 | 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] | 9331 | msg.rpc_argp = &calldata->arg; |
| 9332 | msg.rpc_resp = &calldata->res; |
| 9333 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9334 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9335 | out: |
| 9336 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9337 | return status; |
| 9338 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9339 | |
| 9340 | static void |
| 9341 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9342 | { |
| 9343 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9344 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9345 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9346 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9347 | &lgp->res.seq_res, task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9348 | } |
| 9349 | |
| 9350 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9351 | { |
| 9352 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9353 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9354 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9355 | } |
| 9356 | |
| 9357 | static int |
| 9358 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9359 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9360 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9361 | struct inode *inode = lgp->args.inode; |
| 9362 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4e89bc | 2021-07-02 17:24:22 -0400 | [diff] [blame] | 9363 | struct pnfs_layout_hdr *lo = lgp->lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9364 | int nfs4err = task->tk_status; |
| 9365 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9366 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9367 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9368 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9369 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9370 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9371 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9372 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9373 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9374 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9375 | |
| 9376 | /* |
| 9377 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9378 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9379 | * retry go inband. |
| 9380 | */ |
| 9381 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9382 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9383 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9384 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9385 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9386 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9387 | */ |
| 9388 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9389 | status = -EOVERFLOW; |
| 9390 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9391 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9392 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9393 | * (or clients) writing to the same RAID stripe except when |
| 9394 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9395 | * |
| 9396 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9397 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9398 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9399 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9400 | if (lgp->args.minlength == 0) { |
| 9401 | status = -EOVERFLOW; |
| 9402 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9403 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9404 | status = -EBUSY; |
| 9405 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9406 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9407 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9408 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9409 | case -NFS4ERR_DELEG_REVOKED: |
| 9410 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9411 | case -NFS4ERR_EXPIRED: |
| 9412 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9413 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9414 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9415 | /* If the open stateid was bad, then recover it. */ |
| 9416 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9417 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9418 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9419 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9420 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9421 | break; |
| 9422 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9423 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9424 | /* |
| 9425 | * Mark the bad layout state as invalid, then retry |
| 9426 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9427 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9428 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9429 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9430 | pnfs_free_lseg_list(&head); |
| 9431 | status = -EAGAIN; |
| 9432 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9433 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9434 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9435 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9436 | if (!status) { |
| 9437 | if (exception->retry) |
| 9438 | status = -EAGAIN; |
| 9439 | else |
| 9440 | status = err; |
| 9441 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9442 | out: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9443 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9444 | } |
| 9445 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9446 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9447 | { |
| 9448 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9449 | return nfs_page_array_len(0, max_resp_sz); |
| 9450 | } |
| 9451 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9452 | static void nfs4_layoutget_release(void *calldata) |
| 9453 | { |
| 9454 | struct nfs4_layoutget *lgp = calldata; |
| 9455 | |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9456 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9457 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9458 | } |
| 9459 | |
| 9460 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9461 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9462 | .rpc_call_done = nfs4_layoutget_done, |
| 9463 | .rpc_release = nfs4_layoutget_release, |
| 9464 | }; |
| 9465 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9466 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9467 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9468 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9469 | struct inode *inode = lgp->args.inode; |
| 9470 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9471 | struct rpc_task *task; |
| 9472 | struct rpc_message msg = { |
| 9473 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9474 | .rpc_argp = &lgp->args, |
| 9475 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9476 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9477 | }; |
| 9478 | struct rpc_task_setup task_setup_data = { |
| 9479 | .rpc_client = server->client, |
| 9480 | .rpc_message = &msg, |
| 9481 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9482 | .callback_data = lgp, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9483 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF | |
| 9484 | RPC_TASK_MOVEABLE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9485 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9486 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9487 | struct nfs4_exception exception = { |
| 9488 | .inode = inode, |
| 9489 | .timeout = *timeout, |
| 9490 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9491 | int status = 0; |
| 9492 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9493 | 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] | 9494 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9495 | task = rpc_run_task(&task_setup_data); |
Xiyu Yang | 6e47666 | 2020-04-25 21:04:40 +0800 | [diff] [blame] | 9496 | |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9497 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9498 | if (status != 0) |
| 9499 | goto out; |
| 9500 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9501 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9502 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9503 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9504 | } else if (lgp->res.layoutp->len == 0) { |
| 9505 | status = -EAGAIN; |
| 9506 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9507 | } else |
| 9508 | lseg = pnfs_layout_process(lgp); |
| 9509 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9510 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9511 | &lgp->args.range, |
| 9512 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9513 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9514 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9515 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9516 | rpc_put_task(task); |
| 9517 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9518 | if (status) |
| 9519 | return ERR_PTR(status); |
| 9520 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9521 | } |
| 9522 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9523 | static void |
| 9524 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9525 | { |
| 9526 | struct nfs4_layoutreturn *lrp = calldata; |
| 9527 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9528 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9529 | &lrp->args.seq_args, |
| 9530 | &lrp->res.seq_res, |
| 9531 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9532 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9533 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9534 | } |
| 9535 | |
| 9536 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9537 | { |
| 9538 | struct nfs4_layoutreturn *lrp = calldata; |
| 9539 | struct nfs_server *server; |
| 9540 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9541 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9542 | return; |
| 9543 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9544 | /* |
| 9545 | * Was there an RPC level error? Assume the call succeeded, |
| 9546 | * and that we need to release the layout |
| 9547 | */ |
| 9548 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9549 | lrp->res.lrs_present = 0; |
| 9550 | return; |
| 9551 | } |
| 9552 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9553 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9554 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9555 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9556 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9557 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9558 | lrp->args.inode)) |
| 9559 | goto out_restart; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9560 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9561 | default: |
| 9562 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9563 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9564 | case 0: |
| 9565 | break; |
| 9566 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9567 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9568 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9569 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9570 | } |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9571 | return; |
| 9572 | out_restart: |
| 9573 | task->tk_status = 0; |
| 9574 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9575 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9576 | } |
| 9577 | |
| 9578 | static void nfs4_layoutreturn_release(void *calldata) |
| 9579 | { |
| 9580 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9581 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9582 | |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9583 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9584 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9585 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9586 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9587 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9588 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9589 | nfs_iput_and_deactive(lrp->inode); |
Trond Myklebust | 44ea8df | 2020-04-02 15:37:02 -0400 | [diff] [blame] | 9590 | put_cred(lrp->cred); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9591 | kfree(calldata); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9592 | } |
| 9593 | |
| 9594 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9595 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9596 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9597 | .rpc_release = nfs4_layoutreturn_release, |
| 9598 | }; |
| 9599 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9600 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9601 | { |
| 9602 | struct rpc_task *task; |
| 9603 | struct rpc_message msg = { |
| 9604 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9605 | .rpc_argp = &lrp->args, |
| 9606 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9607 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9608 | }; |
| 9609 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9610 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9611 | .rpc_message = &msg, |
| 9612 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9613 | .callback_data = lrp, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9614 | .flags = RPC_TASK_MOVEABLE, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9615 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9616 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9617 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9618 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9619 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9620 | &task_setup_data.rpc_client, &msg); |
| 9621 | |
Trond Myklebust | c3aba89 | 2021-06-01 11:35:56 -0400 | [diff] [blame] | 9622 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9623 | if (!sync) { |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9624 | if (!lrp->inode) { |
| 9625 | nfs4_layoutreturn_release(lrp); |
| 9626 | return -EAGAIN; |
| 9627 | } |
| 9628 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9629 | } |
Trond Myklebust | c3aba89 | 2021-06-01 11:35:56 -0400 | [diff] [blame] | 9630 | if (!lrp->inode) |
| 9631 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, |
| 9632 | 1); |
| 9633 | else |
| 9634 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, |
| 9635 | 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9636 | task = rpc_run_task(&task_setup_data); |
| 9637 | if (IS_ERR(task)) |
| 9638 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9639 | if (sync) |
| 9640 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9641 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9642 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9643 | rpc_put_task(task); |
| 9644 | return status; |
| 9645 | } |
| 9646 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9647 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9648 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9649 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9650 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9651 | { |
| 9652 | struct nfs4_getdeviceinfo_args args = { |
| 9653 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9654 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9655 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9656 | }; |
| 9657 | struct nfs4_getdeviceinfo_res res = { |
| 9658 | .pdev = pdev, |
| 9659 | }; |
| 9660 | struct rpc_message msg = { |
| 9661 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9662 | .rpc_argp = &args, |
| 9663 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9664 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9665 | }; |
| 9666 | int status; |
| 9667 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9668 | 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] | 9669 | if (res.notification & ~args.notify_types) |
| 9670 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9671 | if (res.notification != args.notify_types) |
| 9672 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9673 | |
Trond Myklebust | cac1d3a | 2020-12-16 16:31:26 -0500 | [diff] [blame] | 9674 | trace_nfs4_getdeviceinfo(server, &pdev->dev_id, status); |
| 9675 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9676 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9677 | |
| 9678 | return status; |
| 9679 | } |
| 9680 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9681 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9682 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9683 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9684 | { |
| 9685 | struct nfs4_exception exception = { }; |
| 9686 | int err; |
| 9687 | |
| 9688 | do { |
| 9689 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9690 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9691 | &exception); |
| 9692 | } while (exception.retry); |
| 9693 | return err; |
| 9694 | } |
| 9695 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9696 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9697 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9698 | { |
| 9699 | struct nfs4_layoutcommit_data *data = calldata; |
| 9700 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9701 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9702 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9703 | &data->args.seq_args, |
| 9704 | &data->res.seq_res, |
| 9705 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9706 | } |
| 9707 | |
| 9708 | static void |
| 9709 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9710 | { |
| 9711 | struct nfs4_layoutcommit_data *data = calldata; |
| 9712 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9713 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9714 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9715 | return; |
| 9716 | |
| 9717 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9718 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9719 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9720 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9721 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9722 | task->tk_status = 0; |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame] | 9723 | break; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9724 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9725 | break; |
| 9726 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9727 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9728 | rpc_restart_call_prepare(task); |
| 9729 | return; |
| 9730 | } |
| 9731 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9732 | } |
| 9733 | |
| 9734 | static void nfs4_layoutcommit_release(void *calldata) |
| 9735 | { |
| 9736 | struct nfs4_layoutcommit_data *data = calldata; |
| 9737 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9738 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9739 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9740 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9741 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9742 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9743 | kfree(data); |
| 9744 | } |
| 9745 | |
| 9746 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9747 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9748 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9749 | .rpc_release = nfs4_layoutcommit_release, |
| 9750 | }; |
| 9751 | |
| 9752 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9753 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9754 | { |
| 9755 | struct rpc_message msg = { |
| 9756 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9757 | .rpc_argp = &data->args, |
| 9758 | .rpc_resp = &data->res, |
| 9759 | .rpc_cred = data->cred, |
| 9760 | }; |
| 9761 | struct rpc_task_setup task_setup_data = { |
| 9762 | .task = &data->task, |
| 9763 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9764 | .rpc_message = &msg, |
| 9765 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9766 | .callback_data = data, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9767 | .flags = RPC_TASK_MOVEABLE, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9768 | }; |
| 9769 | struct rpc_task *task; |
| 9770 | int status = 0; |
| 9771 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9772 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9773 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9774 | data->args.lastbytewritten, |
| 9775 | data->args.inode->i_ino); |
| 9776 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9777 | if (!sync) { |
| 9778 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9779 | if (data->inode == NULL) { |
| 9780 | nfs4_layoutcommit_release(data); |
| 9781 | return -EAGAIN; |
| 9782 | } |
| 9783 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9784 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9785 | 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] | 9786 | task = rpc_run_task(&task_setup_data); |
| 9787 | if (IS_ERR(task)) |
| 9788 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9789 | if (sync) |
| 9790 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9791 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9792 | dprintk("%s: status %d\n", __func__, status); |
| 9793 | rpc_put_task(task); |
| 9794 | return status; |
| 9795 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9796 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9797 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9798 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9799 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9800 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9801 | static int |
| 9802 | _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] | 9803 | struct nfs_fsinfo *info, |
| 9804 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9805 | { |
| 9806 | struct nfs41_secinfo_no_name_args args = { |
| 9807 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9808 | }; |
| 9809 | struct nfs4_secinfo_res res = { |
| 9810 | .flavors = flavors, |
| 9811 | }; |
| 9812 | struct rpc_message msg = { |
| 9813 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9814 | .rpc_argp = &args, |
| 9815 | .rpc_resp = &res, |
| 9816 | }; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9817 | struct nfs4_call_sync_data data = { |
| 9818 | .seq_server = server, |
| 9819 | .seq_args = &args.seq_args, |
| 9820 | .seq_res = &res.seq_res, |
| 9821 | }; |
| 9822 | struct rpc_task_setup task_setup = { |
| 9823 | .rpc_client = server->client, |
| 9824 | .rpc_message = &msg, |
| 9825 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9826 | .callback_data = &data, |
| 9827 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9828 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9829 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9830 | int status; |
| 9831 | |
| 9832 | if (use_integrity) { |
Colin Ian King | 48bb6ec | 2020-06-10 00:22:57 +0100 | [diff] [blame] | 9833 | task_setup.rpc_client = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9834 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9835 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9836 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9837 | } |
| 9838 | |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9839 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9840 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9841 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9842 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9843 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9844 | |
| 9845 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9846 | } |
| 9847 | |
| 9848 | static int |
| 9849 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9850 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9851 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9852 | struct nfs4_exception exception = { |
| 9853 | .interruptible = true, |
| 9854 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9855 | int err; |
| 9856 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9857 | /* first try using integrity protection */ |
| 9858 | err = -NFS4ERR_WRONGSEC; |
| 9859 | |
| 9860 | /* try to use integrity protection with machine cred */ |
| 9861 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9862 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9863 | flavors, true); |
| 9864 | |
| 9865 | /* |
| 9866 | * if unable to use integrity protection, or SECINFO with |
| 9867 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9868 | * disallowed by spec, but exists in deployed servers) use |
| 9869 | * the current filesystem's rpc_client and the user cred. |
| 9870 | */ |
| 9871 | if (err == -NFS4ERR_WRONGSEC) |
| 9872 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9873 | flavors, false); |
| 9874 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9875 | switch (err) { |
| 9876 | case 0: |
| 9877 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9878 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9879 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9880 | default: |
| 9881 | err = nfs4_handle_exception(server, err, &exception); |
| 9882 | } |
| 9883 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9884 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9885 | return err; |
| 9886 | } |
| 9887 | |
| 9888 | static int |
| 9889 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9890 | struct nfs_fsinfo *info) |
| 9891 | { |
| 9892 | int err; |
| 9893 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9894 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9895 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9896 | struct nfs4_secinfo4 *secinfo; |
| 9897 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9898 | |
| 9899 | page = alloc_page(GFP_KERNEL); |
| 9900 | if (!page) { |
| 9901 | err = -ENOMEM; |
| 9902 | goto out; |
| 9903 | } |
| 9904 | |
| 9905 | flavors = page_address(page); |
| 9906 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9907 | |
| 9908 | /* |
| 9909 | * Fall back on "guess and check" method if |
| 9910 | * the server doesn't support SECINFO_NO_NAME |
| 9911 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9912 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9913 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9914 | goto out_freepage; |
| 9915 | } |
| 9916 | if (err) |
| 9917 | goto out_freepage; |
| 9918 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9919 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9920 | secinfo = &flavors->flavors[i]; |
| 9921 | |
| 9922 | switch (secinfo->flavor) { |
| 9923 | case RPC_AUTH_NULL: |
| 9924 | case RPC_AUTH_UNIX: |
| 9925 | case RPC_AUTH_GSS: |
| 9926 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9927 | &secinfo->flavor_info); |
| 9928 | break; |
| 9929 | default: |
| 9930 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9931 | break; |
| 9932 | } |
| 9933 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9934 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9935 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9936 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9937 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9938 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9939 | info, flavor); |
| 9940 | if (!err) |
| 9941 | break; |
| 9942 | } |
| 9943 | } |
| 9944 | |
| 9945 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9946 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9947 | |
| 9948 | out_freepage: |
| 9949 | put_page(page); |
| 9950 | if (err == -EACCES) |
| 9951 | return -EPERM; |
| 9952 | out: |
| 9953 | return err; |
| 9954 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9955 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9956 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9957 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9958 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9959 | { |
| 9960 | int status; |
| 9961 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9962 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9963 | }; |
| 9964 | struct nfs41_test_stateid_res res; |
| 9965 | struct rpc_message msg = { |
| 9966 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9967 | .rpc_argp = &args, |
| 9968 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9969 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9970 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9971 | struct rpc_clnt *rpc_client = server->client; |
| 9972 | |
| 9973 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9974 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9975 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9976 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9977 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9978 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9979 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9980 | if (status != NFS_OK) { |
| 9981 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9982 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9983 | } |
| 9984 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9985 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9986 | } |
| 9987 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9988 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9989 | int err, struct nfs4_exception *exception) |
| 9990 | { |
| 9991 | exception->retry = 0; |
| 9992 | switch(err) { |
| 9993 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9994 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9995 | nfs4_handle_exception(server, err, exception); |
| 9996 | break; |
| 9997 | case -NFS4ERR_BADSESSION: |
| 9998 | case -NFS4ERR_BADSLOT: |
| 9999 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 10000 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 10001 | case -NFS4ERR_DEADSESSION: |
| 10002 | nfs4_do_handle_exception(server, err, exception); |
| 10003 | } |
| 10004 | } |
| 10005 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10006 | /** |
| 10007 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 10008 | * |
| 10009 | * @server: server / transport on which to perform the operation |
| 10010 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10011 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10012 | * |
| 10013 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 10014 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 10015 | * failed or the state ID is not currently valid. |
| 10016 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10017 | static int nfs41_test_stateid(struct nfs_server *server, |
| 10018 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10019 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10020 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 10021 | struct nfs4_exception exception = { |
| 10022 | .interruptible = true, |
| 10023 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10024 | int err; |
| 10025 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10026 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10027 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10028 | } while (exception.retry); |
| 10029 | return err; |
| 10030 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10031 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10032 | struct nfs_free_stateid_data { |
| 10033 | struct nfs_server *server; |
| 10034 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10035 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10036 | }; |
| 10037 | |
| 10038 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 10039 | { |
| 10040 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 10041 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10042 | &data->args.seq_args, |
| 10043 | &data->res.seq_res, |
| 10044 | task); |
| 10045 | } |
| 10046 | |
| 10047 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 10048 | { |
| 10049 | struct nfs_free_stateid_data *data = calldata; |
| 10050 | |
| 10051 | nfs41_sequence_done(task, &data->res.seq_res); |
| 10052 | |
| 10053 | switch (task->tk_status) { |
| 10054 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 10055 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10056 | rpc_restart_call_prepare(task); |
| 10057 | } |
| 10058 | } |
| 10059 | |
| 10060 | static void nfs41_free_stateid_release(void *calldata) |
| 10061 | { |
Scott Mayhew | 576acc2 | 2021-11-03 06:24:40 -0400 | [diff] [blame] | 10062 | struct nfs_free_stateid_data *data = calldata; |
| 10063 | struct nfs_client *clp = data->server->nfs_client; |
| 10064 | |
| 10065 | nfs_put_client(clp); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10066 | kfree(calldata); |
| 10067 | } |
| 10068 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10069 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10070 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 10071 | .rpc_call_done = nfs41_free_stateid_done, |
| 10072 | .rpc_release = nfs41_free_stateid_release, |
| 10073 | }; |
| 10074 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10075 | /** |
| 10076 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 10077 | * |
| 10078 | * @server: server / transport on which to perform the operation |
| 10079 | * @stateid: state ID to release |
| 10080 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 10081 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10082 | * |
| 10083 | * Note: this function is always asynchronous. |
| 10084 | */ |
| 10085 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10086 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10087 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10088 | bool privileged) |
| 10089 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10090 | struct rpc_message msg = { |
| 10091 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10092 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10093 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10094 | struct rpc_task_setup task_setup = { |
| 10095 | .rpc_client = server->client, |
| 10096 | .rpc_message = &msg, |
| 10097 | .callback_ops = &nfs41_free_stateid_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 10098 | .flags = RPC_TASK_ASYNC | RPC_TASK_MOVEABLE, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10099 | }; |
| 10100 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10101 | struct rpc_task *task; |
Scott Mayhew | 576acc2 | 2021-11-03 06:24:40 -0400 | [diff] [blame] | 10102 | struct nfs_client *clp = server->nfs_client; |
| 10103 | |
| 10104 | if (!refcount_inc_not_zero(&clp->cl_count)) |
| 10105 | return -EIO; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10106 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10107 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 10108 | &task_setup.rpc_client, &msg); |
| 10109 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10110 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10111 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 10112 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10113 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10114 | data->server = server; |
| 10115 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 10116 | |
| 10117 | task_setup.callback_data = data; |
| 10118 | |
| 10119 | msg.rpc_argp = &data->args; |
| 10120 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10121 | 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] | 10122 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10123 | if (IS_ERR(task)) |
| 10124 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10125 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10126 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10127 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10128 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 10129 | static void |
| 10130 | 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] | 10131 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10132 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10133 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10134 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10135 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10136 | } |
| 10137 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10138 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 10139 | const nfs4_stateid *s2) |
| 10140 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 10141 | if (s1->type != s2->type) |
| 10142 | return false; |
| 10143 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10144 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10145 | return false; |
| 10146 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10147 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10148 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10149 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 10150 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10151 | } |
| 10152 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 10153 | #endif /* CONFIG_NFS_V4_1 */ |
| 10154 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10155 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 10156 | const nfs4_stateid *s2) |
| 10157 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10158 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10159 | } |
| 10160 | |
| 10161 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10162 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10163 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10164 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10165 | .recover_open = nfs4_open_reclaim, |
| 10166 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10167 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10168 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10169 | }; |
| 10170 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10171 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10172 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10173 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 10174 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 10175 | .recover_open = nfs4_open_reclaim, |
| 10176 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10177 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 10178 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10179 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10180 | }; |
| 10181 | #endif /* CONFIG_NFS_V4_1 */ |
| 10182 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10183 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10184 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10185 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 10186 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10187 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10188 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10189 | }; |
| 10190 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10191 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10192 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10193 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 10194 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 10195 | .recover_open = nfs41_open_expired, |
| 10196 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10197 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10198 | }; |
| 10199 | #endif /* CONFIG_NFS_V4_1 */ |
| 10200 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10201 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10202 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10203 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10204 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10205 | }; |
| 10206 | |
| 10207 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10208 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10209 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10210 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10211 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10212 | }; |
| 10213 | #endif |
| 10214 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10215 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10216 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10217 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10218 | }; |
| 10219 | |
| 10220 | #if defined(CONFIG_NFS_V4_1) |
| 10221 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10222 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10223 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10224 | }; |
| 10225 | #endif /* CONFIG_NFS_V4_1 */ |
| 10226 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10227 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 10228 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10229 | .init_caps = NFS_CAP_READDIRPLUS |
| 10230 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10231 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10232 | .init_client = nfs40_init_client, |
| 10233 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10234 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10235 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10236 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10237 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10238 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10239 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10240 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 10241 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 10242 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10243 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10244 | }; |
| 10245 | |
| 10246 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10247 | static struct nfs_seqid * |
| 10248 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 10249 | { |
| 10250 | return NULL; |
| 10251 | } |
| 10252 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10253 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 10254 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10255 | .init_caps = NFS_CAP_READDIRPLUS |
| 10256 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 10257 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 10258 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10259 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 10260 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10261 | .init_client = nfs41_init_client, |
| 10262 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10263 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10264 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10265 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10266 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10267 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10268 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10269 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10270 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10271 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10272 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10273 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10274 | }; |
| 10275 | #endif |
| 10276 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10277 | #if defined(CONFIG_NFS_V4_2) |
| 10278 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 10279 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10280 | .init_caps = NFS_CAP_READDIRPLUS |
| 10281 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10282 | | NFS_CAP_POSIX_LOCK |
| 10283 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 10284 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10285 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 10286 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 10287 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 10288 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 10289 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 10290 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 10291 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 10292 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 10293 | | NFS_CAP_CLONE |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 10294 | | NFS_CAP_LAYOUTERROR |
| 10295 | | NFS_CAP_READ_PLUS, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10296 | .init_client = nfs41_init_client, |
| 10297 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10298 | .match_stateid = nfs41_match_stateid, |
| 10299 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10300 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10301 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10302 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10303 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10304 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10305 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10306 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10307 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 10308 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10309 | }; |
| 10310 | #endif |
| 10311 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10312 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 10313 | [0] = &nfs_v4_0_minor_ops, |
| 10314 | #if defined(CONFIG_NFS_V4_1) |
| 10315 | [1] = &nfs_v4_1_minor_ops, |
| 10316 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10317 | #if defined(CONFIG_NFS_V4_2) |
| 10318 | [2] = &nfs_v4_2_minor_ops, |
| 10319 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10320 | }; |
| 10321 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 10322 | 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] | 10323 | { |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10324 | ssize_t error, error2, error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10325 | |
| 10326 | error = generic_listxattr(dentry, list, size); |
| 10327 | if (error < 0) |
| 10328 | return error; |
| 10329 | if (list) { |
| 10330 | list += error; |
| 10331 | size -= error; |
| 10332 | } |
| 10333 | |
| 10334 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10335 | if (error2 < 0) |
| 10336 | return error2; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10337 | |
| 10338 | if (list) { |
| 10339 | list += error2; |
| 10340 | size -= error2; |
| 10341 | } |
| 10342 | |
| 10343 | error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); |
| 10344 | if (error3 < 0) |
| 10345 | return error3; |
| 10346 | |
| 10347 | return error + error2 + error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10348 | } |
| 10349 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10350 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10351 | .create = nfs_create, |
| 10352 | .lookup = nfs_lookup, |
| 10353 | .atomic_open = nfs_atomic_open, |
| 10354 | .link = nfs_link, |
| 10355 | .unlink = nfs_unlink, |
| 10356 | .symlink = nfs_symlink, |
| 10357 | .mkdir = nfs_mkdir, |
| 10358 | .rmdir = nfs_rmdir, |
| 10359 | .mknod = nfs_mknod, |
| 10360 | .rename = nfs_rename, |
| 10361 | .permission = nfs_permission, |
| 10362 | .getattr = nfs_getattr, |
| 10363 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10364 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10365 | }; |
| 10366 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10367 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10368 | .permission = nfs_permission, |
| 10369 | .getattr = nfs_getattr, |
| 10370 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10371 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10372 | }; |
| 10373 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10374 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10375 | .version = 4, /* protocol version */ |
| 10376 | .dentry_ops = &nfs4_dentry_operations, |
| 10377 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10378 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10379 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10380 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10381 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10382 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10383 | .getattr = nfs4_proc_getattr, |
| 10384 | .setattr = nfs4_proc_setattr, |
| 10385 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10386 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10387 | .access = nfs4_proc_access, |
| 10388 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10389 | .create = nfs4_proc_create, |
| 10390 | .remove = nfs4_proc_remove, |
| 10391 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10392 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10393 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10394 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10395 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10396 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10397 | .link = nfs4_proc_link, |
| 10398 | .symlink = nfs4_proc_symlink, |
| 10399 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10400 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10401 | .readdir = nfs4_proc_readdir, |
| 10402 | .mknod = nfs4_proc_mknod, |
| 10403 | .statfs = nfs4_proc_statfs, |
| 10404 | .fsinfo = nfs4_proc_fsinfo, |
| 10405 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10406 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10407 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10408 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10409 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10410 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10411 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10412 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10413 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10414 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10415 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10416 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10417 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10418 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10419 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10420 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10421 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10422 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10423 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10424 | .create_server = nfs4_create_server, |
| 10425 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10426 | }; |
| 10427 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10428 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10429 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10430 | .list = nfs4_xattr_list_nfs4_acl, |
| 10431 | .get = nfs4_xattr_get_nfs4_acl, |
| 10432 | .set = nfs4_xattr_set_nfs4_acl, |
| 10433 | }; |
| 10434 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10435 | #ifdef CONFIG_NFS_V4_2 |
| 10436 | static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { |
| 10437 | .prefix = XATTR_USER_PREFIX, |
| 10438 | .get = nfs4_xattr_get_nfs4_user, |
| 10439 | .set = nfs4_xattr_set_nfs4_user, |
| 10440 | }; |
| 10441 | #endif |
| 10442 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10443 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10444 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10445 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10446 | &nfs4_xattr_nfs4_label_handler, |
| 10447 | #endif |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10448 | #ifdef CONFIG_NFS_V4_2 |
| 10449 | &nfs4_xattr_nfs4_user_handler, |
| 10450 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10451 | NULL |
| 10452 | }; |