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 |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 111 | |
| 112 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 113 | static inline struct nfs4_label * |
| 114 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 115 | struct iattr *sattr, struct nfs4_label *label) |
| 116 | { |
| 117 | int err; |
| 118 | |
| 119 | if (label == NULL) |
| 120 | return NULL; |
| 121 | |
| 122 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 123 | return NULL; |
| 124 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 125 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
Vivek Goyal | 15bf323 | 2021-10-12 09:23:07 -0400 | [diff] [blame] | 126 | &dentry->d_name, NULL, |
| 127 | (void **)&label->label, &label->len); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 128 | if (err == 0) |
| 129 | return label; |
| 130 | |
| 131 | return NULL; |
| 132 | } |
| 133 | static inline void |
| 134 | nfs4_label_release_security(struct nfs4_label *label) |
| 135 | { |
| 136 | if (label) |
| 137 | security_release_secctx(label->label, label->len); |
| 138 | } |
| 139 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 140 | { |
| 141 | if (label) |
| 142 | return server->attr_bitmask; |
| 143 | |
| 144 | return server->attr_bitmask_nl; |
| 145 | } |
| 146 | #else |
| 147 | static inline struct nfs4_label * |
| 148 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 149 | struct iattr *sattr, struct nfs4_label *l) |
| 150 | { return NULL; } |
| 151 | static inline void |
| 152 | nfs4_label_release_security(struct nfs4_label *label) |
| 153 | { return; } |
| 154 | static inline u32 * |
| 155 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 156 | { return server->attr_bitmask; } |
| 157 | #endif |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 160 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 162 | if (err >= -1000) |
| 163 | return err; |
| 164 | switch (err) { |
| 165 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 166 | case -NFS4ERR_LAYOUTTRYLATER: |
| 167 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 168 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 169 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 170 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 171 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 172 | case -NFS4ERR_BADOWNER: |
| 173 | case -NFS4ERR_BADNAME: |
| 174 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 175 | case -NFS4ERR_SHARE_DENIED: |
| 176 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 177 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 178 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 179 | case -NFS4ERR_FILE_OPEN: |
| 180 | return -EBUSY; |
Trond Myklebust | 9fff59e | 2020-11-02 20:11:32 -0500 | [diff] [blame] | 181 | case -NFS4ERR_NOT_SAME: |
| 182 | return -ENOTSYNC; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 183 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 185 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 186 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 188 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* |
| 192 | * This is our standard bitmap for GETATTR requests. |
| 193 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 194 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | FATTR4_WORD0_TYPE |
| 196 | | FATTR4_WORD0_CHANGE |
| 197 | | FATTR4_WORD0_SIZE |
| 198 | | FATTR4_WORD0_FSID |
| 199 | | FATTR4_WORD0_FILEID, |
| 200 | FATTR4_WORD1_MODE |
| 201 | | FATTR4_WORD1_NUMLINKS |
| 202 | | FATTR4_WORD1_OWNER |
| 203 | | FATTR4_WORD1_OWNER_GROUP |
| 204 | | FATTR4_WORD1_RAWDEV |
| 205 | | FATTR4_WORD1_SPACE_USED |
| 206 | | FATTR4_WORD1_TIME_ACCESS |
| 207 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 208 | | FATTR4_WORD1_TIME_MODIFY |
| 209 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 210 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 211 | FATTR4_WORD2_SECURITY_LABEL |
| 212 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 215 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 216 | FATTR4_WORD0_TYPE |
| 217 | | FATTR4_WORD0_CHANGE |
| 218 | | FATTR4_WORD0_SIZE |
| 219 | | FATTR4_WORD0_FSID |
| 220 | | FATTR4_WORD0_FILEID, |
| 221 | FATTR4_WORD1_MODE |
| 222 | | FATTR4_WORD1_NUMLINKS |
| 223 | | FATTR4_WORD1_OWNER |
| 224 | | FATTR4_WORD1_OWNER_GROUP |
| 225 | | FATTR4_WORD1_RAWDEV |
| 226 | | FATTR4_WORD1_SPACE_USED |
| 227 | | FATTR4_WORD1_TIME_ACCESS |
| 228 | | FATTR4_WORD1_TIME_METADATA |
| 229 | | FATTR4_WORD1_TIME_MODIFY, |
| 230 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 231 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 232 | | FATTR4_WORD2_SECURITY_LABEL |
| 233 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 234 | }; |
| 235 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 236 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 237 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 238 | | FATTR4_WORD0_FILEID, |
| 239 | }; |
| 240 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 241 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | FATTR4_WORD0_FILES_AVAIL |
| 243 | | FATTR4_WORD0_FILES_FREE |
| 244 | | FATTR4_WORD0_FILES_TOTAL, |
| 245 | FATTR4_WORD1_SPACE_AVAIL |
| 246 | | FATTR4_WORD1_SPACE_FREE |
| 247 | | FATTR4_WORD1_SPACE_TOTAL |
| 248 | }; |
| 249 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 250 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | FATTR4_WORD0_MAXLINK |
| 252 | | FATTR4_WORD0_MAXNAME, |
| 253 | 0 |
| 254 | }; |
| 255 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 256 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | | FATTR4_WORD0_MAXREAD |
| 258 | | FATTR4_WORD0_MAXWRITE |
| 259 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 260 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 261 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 262 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 263 | | FATTR4_WORD2_CLONE_BLKSIZE |
Trond Myklebust | 7f08a33 | 2021-03-26 09:50:19 -0400 | [diff] [blame] | 264 | | FATTR4_WORD2_CHANGE_ATTR_TYPE |
Frank van der Linden | b78ef84 | 2020-06-23 22:38:55 +0000 | [diff] [blame] | 265 | | FATTR4_WORD2_XATTR_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | }; |
| 267 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 268 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 269 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 270 | | FATTR4_WORD0_SIZE |
| 271 | | FATTR4_WORD0_FSID |
| 272 | | FATTR4_WORD0_FILEID |
| 273 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 274 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | | FATTR4_WORD1_OWNER_GROUP |
| 276 | | FATTR4_WORD1_RAWDEV |
| 277 | | FATTR4_WORD1_SPACE_USED |
| 278 | | FATTR4_WORD1_TIME_ACCESS |
| 279 | | FATTR4_WORD1_TIME_METADATA |
| 280 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 281 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 282 | }; |
| 283 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 284 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 285 | struct inode *inode, unsigned long flags) |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 286 | { |
| 287 | unsigned long cache_validity; |
| 288 | |
| 289 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 290 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 291 | return; |
| 292 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 293 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity) | flags; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 294 | |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 295 | /* Remove the attributes over which we have full control */ |
| 296 | dst[1] &= ~FATTR4_WORD1_RAWDEV; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 297 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 298 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 299 | |
| 300 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 301 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 302 | |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 303 | if (!(cache_validity & NFS_INO_INVALID_MODE)) |
| 304 | dst[1] &= ~FATTR4_WORD1_MODE; |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 305 | if (!(cache_validity & NFS_INO_INVALID_OTHER)) |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 306 | dst[1] &= ~(FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 307 | } |
| 308 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 309 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | struct nfs4_readdir_arg *readdir) |
| 311 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 312 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 313 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 316 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | readdir->cookie = 0; |
| 322 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 323 | if (cookie == 2) |
| 324 | return; |
| 325 | |
| 326 | /* |
| 327 | * NFSv4 servers do not return entries for '.' and '..' |
| 328 | * Therefore, we fake these entries here. We let '.' |
| 329 | * have cookie 0 and '..' have cookie 1. Note that |
| 330 | * when talking to the server, we always send cookie 0 |
| 331 | * instead of 1 or 2. |
| 332 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 333 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
| 335 | if (cookie == 0) { |
| 336 | *p++ = xdr_one; /* next */ |
| 337 | *p++ = xdr_zero; /* cookie, first word */ |
| 338 | *p++ = xdr_one; /* cookie, second word */ |
| 339 | *p++ = xdr_one; /* entry len */ |
| 340 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 341 | p++; |
| 342 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 343 | *p++ = htonl(attrs); /* bitmap */ |
| 344 | *p++ = htonl(12); /* attribute buffer length */ |
| 345 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 346 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | *p++ = xdr_one; /* next */ |
| 350 | *p++ = xdr_zero; /* cookie, first word */ |
| 351 | *p++ = xdr_two; /* cookie, second word */ |
| 352 | *p++ = xdr_two; /* entry len */ |
| 353 | memcpy(p, "..\0\0", 4); /* entry */ |
| 354 | p++; |
| 355 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 356 | *p++ = htonl(attrs); /* bitmap */ |
| 357 | *p++ = htonl(12); /* attribute buffer length */ |
| 358 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 359 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | readdir->pgbase = (char *)p - (char *)start; |
| 362 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 363 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 366 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 367 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 368 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 369 | { |
| 370 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 371 | |
| 372 | ops->test_and_free_expired(server, stateid, cred); |
| 373 | } |
| 374 | |
| 375 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 376 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 377 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 378 | { |
| 379 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 380 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 381 | } |
| 382 | |
| 383 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 384 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 385 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 386 | { |
| 387 | nfs4_stateid tmp; |
| 388 | |
| 389 | nfs4_stateid_copy(&tmp, stateid); |
| 390 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 391 | } |
| 392 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 393 | static long nfs4_update_delay(long *timeout) |
| 394 | { |
| 395 | long ret; |
| 396 | if (!timeout) |
| 397 | return NFS4_POLL_RETRY_MAX; |
| 398 | if (*timeout <= 0) |
| 399 | *timeout = NFS4_POLL_RETRY_MIN; |
| 400 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 401 | *timeout = NFS4_POLL_RETRY_MAX; |
| 402 | ret = *timeout; |
| 403 | *timeout <<= 1; |
| 404 | return ret; |
| 405 | } |
| 406 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 407 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 408 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 409 | might_sleep(); |
| 410 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 411 | freezable_schedule_timeout_killable_unsafe( |
| 412 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 413 | if (!__fatal_signal_pending(current)) |
| 414 | return 0; |
| 415 | return -EINTR; |
| 416 | } |
| 417 | |
| 418 | static int nfs4_delay_interruptible(long *timeout) |
| 419 | { |
| 420 | might_sleep(); |
| 421 | |
He Zhe | 59679d9 | 2020-07-06 17:52:24 +0800 | [diff] [blame] | 422 | freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 423 | if (!signal_pending(current)) |
| 424 | return 0; |
| 425 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 426 | } |
| 427 | |
| 428 | static int nfs4_delay(long *timeout, bool interruptible) |
| 429 | { |
| 430 | if (interruptible) |
| 431 | return nfs4_delay_interruptible(timeout); |
| 432 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 433 | } |
| 434 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 435 | static const nfs4_stateid * |
| 436 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 437 | { |
| 438 | if (!stateid) |
| 439 | return NULL; |
| 440 | switch (stateid->type) { |
| 441 | case NFS4_OPEN_STATEID_TYPE: |
| 442 | case NFS4_LOCK_STATEID_TYPE: |
| 443 | case NFS4_DELEGATION_STATEID_TYPE: |
| 444 | return stateid; |
| 445 | default: |
| 446 | break; |
| 447 | } |
| 448 | return NULL; |
| 449 | } |
| 450 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 451 | /* This is the error handling routine for processes that are allowed |
| 452 | * to sleep. |
| 453 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 454 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 455 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 456 | { |
| 457 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 458 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 459 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 460 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 461 | int ret = errorcode; |
| 462 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 463 | exception->delay = 0; |
| 464 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 465 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 466 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 467 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 468 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 469 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 470 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 471 | switch(errorcode) { |
| 472 | case 0: |
| 473 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 474 | case -NFS4ERR_BADHANDLE: |
| 475 | case -ESTALE: |
| 476 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 477 | pnfs_destroy_layout(NFS_I(inode)); |
| 478 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 479 | case -NFS4ERR_DELEG_REVOKED: |
| 480 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 481 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 482 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame] | 483 | case -NFS4ERR_PARTNER_NO_AUTH: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 484 | if (inode != NULL && stateid != NULL) { |
| 485 | nfs_inode_find_state_and_recover(inode, |
| 486 | stateid); |
| 487 | goto wait_on_recovery; |
| 488 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 489 | fallthrough; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 490 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 491 | if (inode) { |
| 492 | int err; |
| 493 | |
| 494 | err = nfs_async_inode_return_delegation(inode, |
| 495 | stateid); |
| 496 | if (err == 0) |
| 497 | goto wait_on_recovery; |
| 498 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 499 | exception->retry = 1; |
| 500 | break; |
| 501 | } |
| 502 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 503 | if (state == NULL) |
| 504 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 505 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 506 | if (ret < 0) |
| 507 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 508 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 509 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 510 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 511 | nfs4_schedule_lease_recovery(clp); |
| 512 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 513 | case -NFS4ERR_MOVED: |
| 514 | ret = nfs4_schedule_migration_recovery(server); |
| 515 | if (ret < 0) |
| 516 | break; |
| 517 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 518 | case -NFS4ERR_LEASE_MOVED: |
| 519 | nfs4_schedule_lease_moved_recovery(clp); |
| 520 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 521 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 522 | case -NFS4ERR_BADSESSION: |
| 523 | case -NFS4ERR_BADSLOT: |
| 524 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 525 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 526 | case -NFS4ERR_DEADSESSION: |
| 527 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 528 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 529 | /* Handled in nfs41_sequence_process() */ |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 530 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 531 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 532 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 533 | if (exception->timeout > HZ) { |
| 534 | /* We have retried a decent amount, time to |
| 535 | * fail |
| 536 | */ |
| 537 | ret = -EBUSY; |
| 538 | break; |
| 539 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 540 | fallthrough; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 541 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 542 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 543 | fallthrough; |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 544 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 545 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 546 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 547 | exception->delay = 1; |
| 548 | return 0; |
| 549 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 550 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 551 | case -NFS4ERR_OLD_STATEID: |
| 552 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 553 | break; |
| 554 | case -NFS4ERR_BADOWNER: |
| 555 | /* The following works around a Linux server bug! */ |
| 556 | case -NFS4ERR_BADNAME: |
| 557 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 558 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 559 | exception->retry = 1; |
| 560 | printk(KERN_WARNING "NFS: v4 server %s " |
| 561 | "does not accept raw " |
| 562 | "uid/gids. " |
| 563 | "Reenabling the idmapper.\n", |
| 564 | server->nfs_client->cl_hostname); |
| 565 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 566 | } |
| 567 | /* We failed to handle the error */ |
| 568 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 569 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 570 | exception->recovering = 1; |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | /* This is the error handling routine for processes that are allowed |
| 575 | * to sleep. |
| 576 | */ |
| 577 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 578 | { |
| 579 | struct nfs_client *clp = server->nfs_client; |
| 580 | int ret; |
| 581 | |
| 582 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 583 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 584 | ret = nfs4_delay(&exception->timeout, |
| 585 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 586 | goto out_retry; |
| 587 | } |
| 588 | if (exception->recovering) { |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 589 | if (exception->task_is_privileged) |
| 590 | return -EDEADLOCK; |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 591 | ret = nfs4_wait_clnt_recover(clp); |
| 592 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 593 | return -EIO; |
| 594 | goto out_retry; |
| 595 | } |
| 596 | return ret; |
| 597 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 598 | if (ret == 0) |
| 599 | exception->retry = 1; |
| 600 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 601 | } |
| 602 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 603 | static int |
| 604 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 605 | int errorcode, struct nfs4_exception *exception) |
| 606 | { |
| 607 | struct nfs_client *clp = server->nfs_client; |
| 608 | int ret; |
| 609 | |
| 610 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 611 | if (exception->delay) { |
| 612 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 613 | goto out_retry; |
| 614 | } |
| 615 | if (exception->recovering) { |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 616 | if (exception->task_is_privileged) |
| 617 | return -EDEADLOCK; |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 618 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 619 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 620 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 621 | goto out_retry; |
| 622 | } |
| 623 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 624 | ret = -EIO; |
| 625 | return ret; |
| 626 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 627 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 628 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 629 | /* |
| 630 | * For NFS4ERR_MOVED, the client transport will need to |
| 631 | * be recomputed after migration recovery has completed. |
| 632 | */ |
| 633 | if (errorcode == -NFS4ERR_MOVED) |
| 634 | rpc_task_release_transport(task); |
| 635 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 636 | return ret; |
| 637 | } |
| 638 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 639 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 640 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 641 | struct nfs4_state *state, long *timeout) |
| 642 | { |
| 643 | struct nfs4_exception exception = { |
| 644 | .state = state, |
| 645 | }; |
| 646 | |
| 647 | if (task->tk_status >= 0) |
| 648 | return 0; |
| 649 | if (timeout) |
| 650 | exception.timeout = *timeout; |
| 651 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 652 | task->tk_status, |
| 653 | &exception); |
| 654 | if (exception.delay && timeout) |
| 655 | *timeout = exception.timeout; |
| 656 | if (exception.retry) |
| 657 | return -EAGAIN; |
| 658 | return 0; |
| 659 | } |
| 660 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 661 | /* |
| 662 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 663 | * or 'false' otherwise. |
| 664 | */ |
| 665 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 666 | { |
| 667 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 668 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 669 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 670 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 671 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | spin_lock(&clp->cl_lock); |
| 674 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 675 | clp->cl_last_renewal = timestamp; |
| 676 | spin_unlock(&clp->cl_lock); |
| 677 | } |
| 678 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 679 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 680 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 681 | struct nfs_client *clp = server->nfs_client; |
| 682 | |
| 683 | if (!nfs4_has_session(clp)) |
| 684 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 685 | } |
| 686 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 687 | struct nfs4_call_sync_data { |
| 688 | const struct nfs_server *seq_server; |
| 689 | struct nfs4_sequence_args *seq_args; |
| 690 | struct nfs4_sequence_res *seq_res; |
| 691 | }; |
| 692 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 693 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 694 | struct nfs4_sequence_res *res, int cache_reply, |
| 695 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 696 | { |
| 697 | args->sa_slot = NULL; |
| 698 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 699 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 700 | |
| 701 | res->sr_slot = NULL; |
| 702 | } |
| 703 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 704 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 705 | { |
| 706 | struct nfs4_slot *slot = res->sr_slot; |
| 707 | struct nfs4_slot_table *tbl; |
| 708 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 709 | tbl = slot->table; |
| 710 | spin_lock(&tbl->slot_tbl_lock); |
| 711 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 712 | nfs4_free_slot(tbl, slot); |
| 713 | spin_unlock(&tbl->slot_tbl_lock); |
| 714 | |
| 715 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | static int nfs40_sequence_done(struct rpc_task *task, |
| 719 | struct nfs4_sequence_res *res) |
| 720 | { |
| 721 | if (res->sr_slot != NULL) |
| 722 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 723 | return 1; |
| 724 | } |
| 725 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 726 | #if defined(CONFIG_NFS_V4_1) |
| 727 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 728 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 729 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 730 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 731 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 732 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 733 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 734 | if (!slot) |
| 735 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 736 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 737 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 738 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 739 | /* Bump the slot sequence number */ |
| 740 | if (slot->seq_done) |
| 741 | slot->seq_nr++; |
| 742 | slot->seq_done = 0; |
| 743 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 744 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 745 | /* Be nice to the server: try to ensure that the last transmitted |
| 746 | * value for highest_user_slotid <= target_highest_slotid |
| 747 | */ |
| 748 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 749 | send_new_highest_used_slotid = true; |
| 750 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 751 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 752 | send_new_highest_used_slotid = false; |
| 753 | goto out_unlock; |
| 754 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 755 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 756 | |
| 757 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 758 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 759 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 760 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 761 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 762 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 763 | if (waitqueue_active(&tbl->slot_waitq)) |
| 764 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 765 | } |
| 766 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 767 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 768 | { |
| 769 | nfs41_release_slot(res->sr_slot); |
| 770 | res->sr_slot = NULL; |
| 771 | } |
| 772 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 773 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 774 | u32 seqnr) |
| 775 | { |
| 776 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 777 | slot->seq_nr_highest_sent = seqnr; |
| 778 | } |
| 779 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 780 | u32 seqnr) |
| 781 | { |
| 782 | slot->seq_nr_highest_sent = seqnr; |
| 783 | slot->seq_nr_last_acked = seqnr; |
| 784 | } |
| 785 | |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 786 | static void nfs4_probe_sequence(struct nfs_client *client, const struct cred *cred, |
| 787 | struct nfs4_slot *slot) |
| 788 | { |
| 789 | struct rpc_task *task = _nfs41_proc_sequence(client, cred, slot, true); |
| 790 | if (!IS_ERR(task)) |
| 791 | rpc_put_task_async(task); |
| 792 | } |
| 793 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 794 | static int nfs41_sequence_process(struct rpc_task *task, |
| 795 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 796 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 797 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 798 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 799 | struct nfs_client *clp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 800 | int status; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 801 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 802 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 803 | if (slot == NULL) |
| 804 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 805 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 806 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 807 | goto out; |
| 808 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 809 | session = slot->table->session; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 810 | clp = session->clp; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 811 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 812 | trace_nfs4_sequence_done(session, res); |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 813 | |
| 814 | status = res->sr_status; |
| 815 | if (task->tk_status == -NFS4ERR_DEADSESSION) |
| 816 | status = -NFS4ERR_DEADSESSION; |
| 817 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 818 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 819 | switch (status) { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 820 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 821 | /* Mark this sequence number as having been acked */ |
| 822 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 823 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 824 | slot->seq_done = 1; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 825 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 826 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 827 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 828 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 829 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 830 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 831 | case 1: |
| 832 | /* |
| 833 | * sr_status remains 1 if an RPC level error occurred. |
| 834 | * The server may or may not have processed the sequence |
| 835 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 836 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 837 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 838 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 839 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 840 | case -NFS4ERR_DELAY: |
| 841 | /* The server detected a resend of the RPC call and |
| 842 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 843 | * of RFC5661. |
| 844 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 845 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 846 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 847 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 848 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 849 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 850 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 851 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 852 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 853 | /* |
| 854 | * The server thinks we tried to replay a request. |
| 855 | * Retry the call after bumping the sequence ID. |
| 856 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 857 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 858 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 859 | case -NFS4ERR_BADSLOT: |
| 860 | /* |
| 861 | * The slot id we used was probably retired. Try again |
| 862 | * using a different slot id. |
| 863 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 864 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 865 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 866 | goto retry_nowait; |
| 867 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 868 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 869 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 870 | * Were one or more calls using this slot interrupted? |
| 871 | * If the server never received the request, then our |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 872 | * transmitted slot sequence number may be too high. However, |
| 873 | * if the server did receive the request then it might |
| 874 | * accidentally give us a reply with a mismatched operation. |
| 875 | * We can sort this out by sending a lone sequence operation |
| 876 | * to the server on the same slot. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 877 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 878 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 879 | slot->seq_nr--; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 880 | if (task->tk_msg.rpc_proc != &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE]) { |
| 881 | nfs4_probe_sequence(clp, task->tk_msg.rpc_cred, slot); |
| 882 | res->sr_slot = NULL; |
| 883 | } |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 884 | goto retry_nowait; |
| 885 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 886 | /* |
| 887 | * RFC5661: |
| 888 | * A retry might be sent while the original request is |
| 889 | * still in progress on the replier. The replier SHOULD |
| 890 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 891 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 892 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 893 | * |
| 894 | * Restart the search after a delay. |
| 895 | */ |
| 896 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 897 | goto out_retry; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 898 | case -NFS4ERR_BADSESSION: |
| 899 | case -NFS4ERR_DEADSESSION: |
| 900 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 901 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 902 | default: |
| 903 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 904 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 905 | } |
| 906 | out: |
| 907 | /* The session may be reset by one of the error handlers. */ |
| 908 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 909 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 910 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 911 | session_recover: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 912 | nfs4_schedule_session_recovery(session, status); |
| 913 | dprintk("%s ERROR: %d Reset session\n", __func__, status); |
| 914 | nfs41_sequence_free_slot(res); |
| 915 | goto out; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 916 | retry_new_seq: |
| 917 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 918 | retry_nowait: |
| 919 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 920 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 921 | task->tk_status = 0; |
| 922 | ret = 0; |
| 923 | } |
| 924 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 925 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 926 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 927 | goto out; |
| 928 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 929 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 930 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 931 | |
| 932 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 933 | { |
| 934 | if (!nfs41_sequence_process(task, res)) |
| 935 | return 0; |
| 936 | if (res->sr_slot != NULL) |
| 937 | nfs41_sequence_free_slot(res); |
| 938 | return 1; |
| 939 | |
| 940 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 941 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 942 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 943 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 944 | { |
| 945 | if (res->sr_slot == NULL) |
| 946 | return 1; |
| 947 | if (res->sr_slot->table->session != NULL) |
| 948 | return nfs41_sequence_process(task, res); |
| 949 | return nfs40_sequence_done(task, res); |
| 950 | } |
| 951 | |
| 952 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 953 | { |
| 954 | if (res->sr_slot != NULL) { |
| 955 | if (res->sr_slot->table->session != NULL) |
| 956 | nfs41_sequence_free_slot(res); |
| 957 | else |
| 958 | nfs40_sequence_free_slot(res); |
| 959 | } |
| 960 | } |
| 961 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 962 | 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] | 963 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 964 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 965 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 966 | if (!res->sr_slot->table->session) |
| 967 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 968 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 969 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 970 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 971 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 972 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 973 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 974 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 975 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 976 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 977 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 978 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 979 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 980 | } |
| 981 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 982 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 983 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 984 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 985 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 986 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 987 | } |
| 988 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 989 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 990 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 991 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 992 | }; |
| 993 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 994 | #else /* !CONFIG_NFS_V4_1 */ |
| 995 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 996 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 997 | { |
| 998 | return nfs40_sequence_done(task, res); |
| 999 | } |
| 1000 | |
| 1001 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1002 | { |
| 1003 | if (res->sr_slot != NULL) |
| 1004 | nfs40_sequence_free_slot(res); |
| 1005 | } |
| 1006 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1007 | int nfs4_sequence_done(struct rpc_task *task, |
| 1008 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1009 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1010 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1011 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1012 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1013 | |
| 1014 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1015 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1016 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 1017 | { |
| 1018 | res->sr_timestamp = jiffies; |
| 1019 | res->sr_status_flags = 0; |
| 1020 | res->sr_status = 1; |
| 1021 | } |
| 1022 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1023 | static |
| 1024 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 1025 | struct nfs4_sequence_res *res, |
| 1026 | struct nfs4_slot *slot) |
| 1027 | { |
| 1028 | if (!slot) |
| 1029 | return; |
| 1030 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 1031 | args->sa_slot = slot; |
| 1032 | |
| 1033 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1037 | struct nfs4_sequence_args *args, |
| 1038 | struct nfs4_sequence_res *res, |
| 1039 | struct rpc_task *task) |
| 1040 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1041 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1042 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1043 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1044 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1045 | /* slot already allocated? */ |
| 1046 | if (res->sr_slot != NULL) |
| 1047 | goto out_start; |
| 1048 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1049 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1050 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1051 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1052 | spin_lock(&tbl->slot_tbl_lock); |
| 1053 | /* The state manager will wait until the slot table is empty */ |
| 1054 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1055 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1056 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1057 | slot = nfs4_alloc_slot(tbl); |
| 1058 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1059 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1060 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1061 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1062 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1063 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1064 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1065 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1066 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1067 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1068 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1069 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1070 | rpc_call_start(task); |
| 1071 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1072 | out_sleep_timeout: |
| 1073 | /* Try again in 1/4 second */ |
| 1074 | if (args->sa_privileged) |
| 1075 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1076 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1077 | else |
| 1078 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1079 | NULL, jiffies + (HZ >> 2)); |
| 1080 | spin_unlock(&tbl->slot_tbl_lock); |
| 1081 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1082 | out_sleep: |
| 1083 | if (args->sa_privileged) |
| 1084 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1085 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1086 | else |
| 1087 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1088 | spin_unlock(&tbl->slot_tbl_lock); |
| 1089 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1090 | } |
| 1091 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1092 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1093 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1094 | { |
| 1095 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1096 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1097 | data->seq_args, data->seq_res, task); |
| 1098 | } |
| 1099 | |
| 1100 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1101 | { |
| 1102 | struct nfs4_call_sync_data *data = calldata; |
| 1103 | nfs4_sequence_done(task, data->seq_res); |
| 1104 | } |
| 1105 | |
| 1106 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1107 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1108 | .rpc_call_done = nfs40_call_sync_done, |
| 1109 | }; |
| 1110 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1111 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1112 | { |
| 1113 | int ret; |
| 1114 | struct rpc_task *task; |
| 1115 | |
| 1116 | task = rpc_run_task(task_setup); |
| 1117 | if (IS_ERR(task)) |
| 1118 | return PTR_ERR(task); |
| 1119 | |
| 1120 | ret = task->tk_status; |
| 1121 | rpc_put_task(task); |
| 1122 | return ret; |
| 1123 | } |
| 1124 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1125 | static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
| 1126 | struct nfs_server *server, |
| 1127 | struct rpc_message *msg, |
| 1128 | struct nfs4_sequence_args *args, |
| 1129 | struct nfs4_sequence_res *res, |
| 1130 | unsigned short task_flags) |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1131 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1132 | struct nfs_client *clp = server->nfs_client; |
| 1133 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1134 | .seq_server = server, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1135 | .seq_args = args, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1136 | .seq_res = res, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1137 | }; |
| 1138 | struct rpc_task_setup task_setup = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1139 | .rpc_client = clnt, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1140 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1141 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1142 | .callback_data = &data, |
| 1143 | .flags = task_flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1144 | }; |
| 1145 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1146 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1147 | } |
| 1148 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1149 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 1150 | struct nfs_server *server, |
| 1151 | struct rpc_message *msg, |
| 1152 | struct nfs4_sequence_args *args, |
| 1153 | struct nfs4_sequence_res *res) |
| 1154 | { |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 1155 | unsigned short task_flags = 0; |
| 1156 | |
| 1157 | if (server->nfs_client->cl_minorversion) |
| 1158 | task_flags = RPC_TASK_MOVEABLE; |
| 1159 | return nfs4_do_call_sync(clnt, server, msg, args, res, task_flags); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1163 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1164 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1165 | struct rpc_message *msg, |
| 1166 | struct nfs4_sequence_args *args, |
| 1167 | struct nfs4_sequence_res *res, |
| 1168 | int cache_reply) |
| 1169 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1170 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1171 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1174 | static void |
| 1175 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1176 | { |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 1177 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 1178 | NFS_INO_INVALID_CTIME | |
| 1179 | NFS_INO_INVALID_NLINK); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1180 | inc_nlink(inode); |
| 1181 | } |
| 1182 | |
| 1183 | static void |
Trond Myklebust | 1301e42 | 2021-04-01 14:57:56 -0400 | [diff] [blame] | 1184 | nfs4_inc_nlink(struct inode *inode) |
| 1185 | { |
| 1186 | spin_lock(&inode->i_lock); |
| 1187 | nfs4_inc_nlink_locked(inode); |
| 1188 | spin_unlock(&inode->i_lock); |
| 1189 | } |
| 1190 | |
| 1191 | static void |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1192 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1193 | { |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 1194 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 1195 | NFS_INO_INVALID_CTIME | |
| 1196 | NFS_INO_INVALID_NLINK); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1197 | drop_nlink(inode); |
| 1198 | } |
| 1199 | |
| 1200 | static void |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1201 | nfs4_update_changeattr_locked(struct inode *inode, |
| 1202 | struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1203 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1205 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1206 | u64 change_attr = inode_peek_iversion_raw(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 1208 | cache_validity |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME; |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1209 | if (S_ISDIR(inode->i_mode)) |
| 1210 | cache_validity |= NFS_INO_INVALID_DATA; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1211 | |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1212 | switch (NFS_SERVER(inode)->change_attr_type) { |
| 1213 | case NFS4_CHANGE_TYPE_IS_UNDEFINED: |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1214 | if (cinfo->after == change_attr) |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1215 | goto out; |
| 1216 | break; |
| 1217 | default: |
| 1218 | if ((s64)(change_attr - cinfo->after) >= 0) |
| 1219 | goto out; |
| 1220 | } |
| 1221 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1222 | inode_set_iversion_raw(inode, cinfo->after); |
Trond Myklebust | 20cf7d4 | 2021-06-25 15:49:31 -0400 | [diff] [blame] | 1223 | if (!cinfo->atomic || cinfo->before != change_attr) { |
| 1224 | if (S_ISDIR(inode->i_mode)) |
| 1225 | nfs_force_lookup_revalidate(inode); |
| 1226 | |
| 1227 | if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) |
| 1228 | cache_validity |= |
| 1229 | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL | |
| 1230 | NFS_INO_INVALID_SIZE | NFS_INO_INVALID_OTHER | |
| 1231 | NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_NLINK | |
| 1232 | NFS_INO_INVALID_MODE | NFS_INO_INVALID_XATTR | |
| 1233 | NFS_INO_REVAL_PAGECACHE; |
| 1234 | nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); |
| 1235 | } |
| 1236 | nfsi->attrtimeo_timestamp = jiffies; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1237 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1238 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1239 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
Trond Myklebust | 6f9be83 | 2021-03-26 11:01:19 -0400 | [diff] [blame] | 1240 | out: |
| 1241 | nfs_set_cache_invalid(inode, cache_validity); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1242 | } |
| 1243 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1244 | void |
| 1245 | nfs4_update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1246 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1247 | { |
| 1248 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1249 | nfs4_update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | spin_unlock(&dir->i_lock); |
| 1251 | } |
| 1252 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1253 | struct nfs4_open_createattrs { |
| 1254 | struct nfs4_label *label; |
| 1255 | struct iattr *sattr; |
| 1256 | const __u32 verf[2]; |
| 1257 | }; |
| 1258 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1259 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1260 | int err, struct nfs4_exception *exception) |
| 1261 | { |
| 1262 | if (err != -EINVAL) |
| 1263 | return false; |
| 1264 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1265 | return false; |
| 1266 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1267 | exception->retry = 1; |
| 1268 | return true; |
| 1269 | } |
| 1270 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1271 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1272 | { |
| 1273 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1274 | } |
| 1275 | |
| 1276 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1277 | { |
| 1278 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1279 | |
| 1280 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1281 | } |
| 1282 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1283 | static u32 |
| 1284 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1285 | fmode_t fmode, int openflags) |
| 1286 | { |
| 1287 | u32 res = 0; |
| 1288 | |
| 1289 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1290 | case FMODE_READ: |
| 1291 | res = NFS4_SHARE_ACCESS_READ; |
| 1292 | break; |
| 1293 | case FMODE_WRITE: |
| 1294 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1295 | break; |
| 1296 | case FMODE_READ|FMODE_WRITE: |
| 1297 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1298 | } |
| 1299 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1300 | goto out; |
| 1301 | /* Want no delegation if we're using O_DIRECT */ |
| 1302 | if (openflags & O_DIRECT) |
| 1303 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1304 | out: |
| 1305 | return res; |
| 1306 | } |
| 1307 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1308 | static enum open_claim_type4 |
| 1309 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1310 | enum open_claim_type4 claim) |
| 1311 | { |
| 1312 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1313 | return claim; |
| 1314 | switch (claim) { |
| 1315 | default: |
| 1316 | return claim; |
| 1317 | case NFS4_OPEN_CLAIM_FH: |
| 1318 | return NFS4_OPEN_CLAIM_NULL; |
| 1319 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1320 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1321 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1322 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1323 | } |
| 1324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
| 1326 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1327 | { |
| 1328 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1329 | p->o_res.seqid = p->o_arg.seqid; |
| 1330 | p->c_res.seqid = p->c_arg.seqid; |
| 1331 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1332 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1333 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1334 | 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] | 1335 | } |
| 1336 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1337 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1338 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1339 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1340 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1341 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1342 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1343 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1344 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1345 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1346 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1347 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1348 | struct nfs4_opendata *p; |
| 1349 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1350 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1351 | if (p == NULL) |
| 1352 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1353 | |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1354 | p->f_attr.label = nfs4_label_alloc(server, gfp_mask); |
| 1355 | if (IS_ERR(p->f_attr.label)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1356 | goto err_free_p; |
| 1357 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1358 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1359 | if (IS_ERR(p->a_label)) |
| 1360 | goto err_free_f; |
| 1361 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1362 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1363 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1364 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1365 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1366 | nfs_sb_active(dentry->d_sb); |
| 1367 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1368 | p->dir = parent; |
| 1369 | p->owner = sp; |
| 1370 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1371 | p->o_arg.open_flags = flags; |
| 1372 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1373 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1374 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1375 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1376 | if (flags & O_CREAT) { |
| 1377 | p->o_arg.umask = current_umask(); |
| 1378 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1379 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1380 | p->o_arg.u.attrs = &p->attrs; |
| 1381 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1382 | |
| 1383 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1384 | sizeof(p->o_arg.u.verifier.data)); |
| 1385 | } |
| 1386 | } |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 1387 | /* ask server to check for all possible rights as results |
| 1388 | * are cached */ |
| 1389 | switch (p->o_arg.claim) { |
| 1390 | default: |
| 1391 | break; |
| 1392 | case NFS4_OPEN_CLAIM_NULL: |
| 1393 | case NFS4_OPEN_CLAIM_FH: |
| 1394 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1395 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE | |
| 1396 | NFS4_ACCESS_EXECUTE; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1397 | #ifdef CONFIG_NFS_V4_2 |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 1398 | if (!(server->caps & NFS_CAP_XATTR)) |
| 1399 | break; |
| 1400 | p->o_arg.access |= NFS4_ACCESS_XAREAD | NFS4_ACCESS_XAWRITE | |
| 1401 | NFS4_ACCESS_XALIST; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1402 | #endif |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1403 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1404 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1405 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1406 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1407 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1408 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1409 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1410 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1411 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1412 | case NFS4_OPEN_CLAIM_NULL: |
| 1413 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1414 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1415 | p->o_arg.fh = NFS_FH(dir); |
| 1416 | break; |
| 1417 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1418 | case NFS4_OPEN_CLAIM_FH: |
| 1419 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1420 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1421 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1422 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1423 | p->c_arg.fh = &p->o_res.fh; |
| 1424 | p->c_arg.stateid = &p->o_res.stateid; |
| 1425 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1426 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1427 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1428 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1429 | |
| 1430 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1431 | nfs4_label_free(p->a_label); |
| 1432 | err_free_f: |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1433 | nfs4_label_free(p->f_attr.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1434 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1435 | kfree(p); |
| 1436 | err: |
| 1437 | dput(parent); |
| 1438 | return NULL; |
| 1439 | } |
| 1440 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1441 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1442 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1443 | struct nfs4_opendata *p = container_of(kref, |
| 1444 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1445 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1446 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1447 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1448 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1449 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1450 | if (p->state != NULL) |
| 1451 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1452 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1453 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1454 | nfs4_label_free(p->a_label); |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 1455 | nfs4_label_free(p->f_attr.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1456 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1457 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1458 | dput(p->dentry); |
| 1459 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1460 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1461 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1462 | kfree(p); |
| 1463 | } |
| 1464 | |
| 1465 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1466 | { |
| 1467 | if (p != NULL) |
| 1468 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1469 | } |
| 1470 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1471 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1472 | fmode_t fmode) |
| 1473 | { |
| 1474 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1475 | case FMODE_READ|FMODE_WRITE: |
| 1476 | return state->n_rdwr != 0; |
| 1477 | case FMODE_WRITE: |
| 1478 | return state->n_wronly != 0; |
| 1479 | case FMODE_READ: |
| 1480 | return state->n_rdonly != 0; |
| 1481 | } |
| 1482 | WARN_ON_ONCE(1); |
| 1483 | return false; |
| 1484 | } |
| 1485 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1486 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1487 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1488 | { |
| 1489 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1490 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1491 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1492 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1493 | switch (claim) { |
| 1494 | case NFS4_OPEN_CLAIM_NULL: |
| 1495 | case NFS4_OPEN_CLAIM_FH: |
| 1496 | goto out; |
| 1497 | default: |
| 1498 | break; |
| 1499 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1500 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1501 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1502 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1503 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1504 | break; |
| 1505 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1506 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1507 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1508 | break; |
| 1509 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1510 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1511 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1512 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1513 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1514 | return ret; |
| 1515 | } |
| 1516 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1517 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1518 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1519 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1520 | if (delegation == NULL) |
| 1521 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1522 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1523 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1524 | switch (claim) { |
| 1525 | case NFS4_OPEN_CLAIM_NULL: |
| 1526 | case NFS4_OPEN_CLAIM_FH: |
| 1527 | break; |
| 1528 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1529 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1530 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1531 | fallthrough; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1532 | default: |
| 1533 | return 0; |
| 1534 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1535 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1536 | return 1; |
| 1537 | } |
| 1538 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1539 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1540 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1541 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1542 | case FMODE_WRITE: |
| 1543 | state->n_wronly++; |
| 1544 | break; |
| 1545 | case FMODE_READ: |
| 1546 | state->n_rdonly++; |
| 1547 | break; |
| 1548 | case FMODE_READ|FMODE_WRITE: |
| 1549 | state->n_rdwr++; |
| 1550 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1551 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1552 | } |
| 1553 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1554 | #ifdef CONFIG_NFS_V4_1 |
| 1555 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1556 | { |
| 1557 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1558 | return true; |
| 1559 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1560 | return true; |
| 1561 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1562 | return true; |
| 1563 | return false; |
| 1564 | } |
| 1565 | #endif /* CONFIG_NFS_V4_1 */ |
| 1566 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1567 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1568 | { |
| 1569 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1570 | wake_up_all(&state->waitq); |
| 1571 | } |
| 1572 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1573 | 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] | 1574 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1575 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1576 | bool need_recover = false; |
| 1577 | |
| 1578 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1579 | need_recover = true; |
| 1580 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1581 | need_recover = true; |
| 1582 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1583 | need_recover = true; |
| 1584 | if (need_recover) |
| 1585 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1586 | } |
| 1587 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1588 | /* |
| 1589 | * Check for whether or not the caller may update the open stateid |
| 1590 | * to the value passed in by stateid. |
| 1591 | * |
| 1592 | * Note: This function relies heavily on the server implementing |
| 1593 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1594 | * correctly. |
| 1595 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1596 | * are then incremented on every state transition. |
| 1597 | */ |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1598 | static bool nfs_stateid_is_sequential(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1599 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1600 | { |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1601 | if (test_bit(NFS_OPEN_STATE, &state->flags)) { |
| 1602 | /* The common case - we're updating to a new sequence number */ |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1603 | if (nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1604 | if (nfs4_stateid_is_next(&state->open_stateid, stateid)) |
| 1605 | return true; |
| 1606 | return false; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1607 | } |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1608 | /* The server returned a new stateid */ |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1609 | } |
Trond Myklebust | 01d29f8 | 2021-10-26 21:56:40 -0400 | [diff] [blame] | 1610 | /* This is the first OPEN in this generation */ |
| 1611 | if (stateid->seqid == cpu_to_be32(1)) |
| 1612 | return true; |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1613 | return false; |
| 1614 | } |
| 1615 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1616 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1617 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1618 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1619 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1620 | if (state->n_wronly) |
| 1621 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1622 | if (state->n_rdonly) |
| 1623 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1624 | if (state->n_rdwr) |
| 1625 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1626 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1627 | } |
| 1628 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1629 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1630 | nfs4_stateid *stateid, fmode_t fmode) |
| 1631 | { |
| 1632 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1633 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1634 | case FMODE_WRITE: |
| 1635 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1636 | break; |
| 1637 | case FMODE_READ: |
| 1638 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1639 | break; |
| 1640 | case 0: |
| 1641 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1642 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1643 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1644 | } |
| 1645 | if (stateid == NULL) |
| 1646 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1647 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1648 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1649 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1650 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1651 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1652 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1653 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1654 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1655 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1656 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1657 | out: |
| 1658 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1659 | } |
| 1660 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1661 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1662 | nfs4_stateid *arg_stateid, |
| 1663 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1664 | { |
| 1665 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1666 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1667 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1668 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1669 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1670 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1671 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1672 | } |
| 1673 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1674 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1675 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1676 | __must_hold(&state->owner->so_lock) |
| 1677 | __must_hold(&state->seqlock) |
| 1678 | __must_hold(RCU) |
| 1679 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1680 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1681 | DEFINE_WAIT(wait); |
| 1682 | int status = 0; |
| 1683 | for (;;) { |
| 1684 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1685 | if (nfs_stateid_is_sequential(state, stateid)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1686 | break; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1687 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1688 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1689 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1690 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1691 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1692 | break; |
| 1693 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1694 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1695 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1696 | /* |
| 1697 | * Ensure we process the state changes in the same order |
| 1698 | * in which the server processed them by delaying the |
| 1699 | * update of the stateid until we are in sequence. |
| 1700 | */ |
| 1701 | write_sequnlock(&state->seqlock); |
| 1702 | spin_unlock(&state->owner->so_lock); |
| 1703 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1704 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1705 | |
zhouchuangao | bb00238 | 2021-05-09 19:34:37 -0700 | [diff] [blame] | 1706 | if (!fatal_signal_pending(current)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1707 | if (schedule_timeout(5*HZ) == 0) |
| 1708 | status = -EAGAIN; |
| 1709 | else |
| 1710 | status = 0; |
| 1711 | } else |
| 1712 | status = -EINTR; |
| 1713 | finish_wait(&state->waitq, &wait); |
| 1714 | rcu_read_lock(); |
| 1715 | spin_lock(&state->owner->so_lock); |
| 1716 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1717 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1718 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1719 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1720 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1721 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1722 | nfs_test_and_clear_all_open_stateid(state); |
| 1723 | } |
| 1724 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1725 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1726 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1727 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1728 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1729 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1730 | } |
| 1731 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1732 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1733 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1734 | fmode_t fmode, |
| 1735 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1737 | /* |
| 1738 | * Protect the call to nfs4_state_set_mode_locked and |
| 1739 | * serialise the stateid update |
| 1740 | */ |
| 1741 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1742 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1743 | switch (fmode) { |
| 1744 | case FMODE_READ: |
| 1745 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1746 | break; |
| 1747 | case FMODE_WRITE: |
| 1748 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1749 | break; |
| 1750 | case FMODE_READ|FMODE_WRITE: |
| 1751 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1752 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1753 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1754 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1755 | } |
| 1756 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1757 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1758 | { |
| 1759 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1760 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1761 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1762 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1763 | } |
| 1764 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1765 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1766 | const nfs4_stateid *deleg_stateid, |
| 1767 | fmode_t fmode) |
| 1768 | { |
| 1769 | /* |
| 1770 | * Protect the call to nfs4_state_set_mode_locked and |
| 1771 | * serialise the stateid update |
| 1772 | */ |
| 1773 | write_seqlock(&state->seqlock); |
| 1774 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1775 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1776 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1779 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1780 | { |
| 1781 | write_seqlock(&state->seqlock); |
| 1782 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1783 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1784 | write_sequnlock(&state->seqlock); |
| 1785 | } |
| 1786 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1787 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1788 | const nfs4_stateid *open_stateid, |
| 1789 | const nfs4_stateid *delegation, |
| 1790 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1791 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1792 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1793 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1794 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1795 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1796 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1797 | int ret = 0; |
| 1798 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1799 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1800 | |
| 1801 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1802 | spin_lock(&state->owner->so_lock); |
| 1803 | if (open_stateid != NULL) { |
| 1804 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1805 | ret = 1; |
| 1806 | } |
| 1807 | |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1808 | deleg_cur = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1809 | if (deleg_cur == NULL) |
| 1810 | goto no_delegation; |
| 1811 | |
| 1812 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1813 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1814 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1815 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1816 | goto no_delegation_unlock; |
| 1817 | |
| 1818 | if (delegation == NULL) |
| 1819 | delegation = &deleg_cur->stateid; |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1820 | else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1821 | goto no_delegation_unlock; |
| 1822 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1823 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1824 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1825 | ret = 1; |
| 1826 | no_delegation_unlock: |
| 1827 | spin_unlock(&deleg_cur->lock); |
| 1828 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1829 | if (ret) |
| 1830 | update_open_stateflags(state, fmode); |
| 1831 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1832 | rcu_read_unlock(); |
| 1833 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1834 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1835 | nfs4_schedule_state_manager(clp); |
| 1836 | if (freeme.type != 0) |
| 1837 | nfs4_test_and_free_stateid(server, &freeme, |
| 1838 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1839 | |
| 1840 | return ret; |
| 1841 | } |
| 1842 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1843 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1844 | const nfs4_stateid *stateid) |
| 1845 | { |
| 1846 | struct nfs4_state *state = lsp->ls_state; |
| 1847 | bool ret = false; |
| 1848 | |
| 1849 | spin_lock(&state->state_lock); |
| 1850 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1851 | goto out_noupdate; |
| 1852 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1853 | goto out_noupdate; |
| 1854 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1855 | ret = true; |
| 1856 | out_noupdate: |
| 1857 | spin_unlock(&state->state_lock); |
| 1858 | return ret; |
| 1859 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1860 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1861 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1862 | { |
| 1863 | struct nfs_delegation *delegation; |
| 1864 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1865 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1866 | rcu_read_lock(); |
Trond Myklebust | 40e6aa1 | 2019-10-27 13:38:45 -0400 | [diff] [blame] | 1867 | delegation = nfs4_get_valid_delegation(inode); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1868 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1869 | rcu_read_unlock(); |
| 1870 | return; |
| 1871 | } |
| 1872 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1873 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1874 | } |
| 1875 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1876 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1877 | { |
| 1878 | struct nfs4_state *state = opendata->state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1879 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1880 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1881 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1882 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1883 | nfs4_stateid stateid; |
| 1884 | int ret = -EAGAIN; |
| 1885 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1886 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1887 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1888 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1889 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1890 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1891 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1892 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1893 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1894 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 1895 | delegation = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1896 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1897 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1898 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1899 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1900 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1901 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1902 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1903 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1904 | if (!opendata->is_recover) { |
| 1905 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1906 | if (ret != 0) |
| 1907 | goto out; |
| 1908 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1909 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1910 | |
| 1911 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1912 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1913 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1914 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1915 | out: |
| 1916 | return ERR_PTR(ret); |
| 1917 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1918 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1919 | return state; |
| 1920 | } |
| 1921 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1922 | static void |
| 1923 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1924 | { |
| 1925 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1926 | struct nfs_delegation *delegation; |
| 1927 | int delegation_flags = 0; |
| 1928 | |
| 1929 | rcu_read_lock(); |
| 1930 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1931 | if (delegation) |
| 1932 | delegation_flags = delegation->flags; |
| 1933 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1934 | switch (data->o_arg.claim) { |
| 1935 | default: |
| 1936 | break; |
| 1937 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1938 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1939 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1940 | "returning a delegation for " |
| 1941 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1942 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1943 | return; |
| 1944 | } |
| 1945 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1946 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1947 | data->owner->so_cred, |
| 1948 | data->o_res.delegation_type, |
| 1949 | &data->o_res.delegation, |
| 1950 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1951 | else |
| 1952 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1953 | data->owner->so_cred, |
| 1954 | data->o_res.delegation_type, |
| 1955 | &data->o_res.delegation, |
| 1956 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1957 | |
| 1958 | if (data->o_res.do_recall) |
| 1959 | nfs_async_inode_return_delegation(state->inode, |
| 1960 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | /* |
| 1964 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1965 | * and update the nfs4_state. |
| 1966 | */ |
| 1967 | static struct nfs4_state * |
| 1968 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1969 | { |
| 1970 | struct inode *inode = data->state->inode; |
| 1971 | struct nfs4_state *state = data->state; |
| 1972 | int ret; |
| 1973 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1974 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1975 | if (data->rpc_status) |
| 1976 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1977 | /* cached opens have already been processed */ |
| 1978 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1979 | } |
| 1980 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1981 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1982 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1983 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1984 | |
| 1985 | if (data->o_res.delegation_type != 0) |
| 1986 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1987 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1988 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1989 | NULL, data->o_arg.fmode)) |
| 1990 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1991 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1992 | |
| 1993 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1994 | } |
| 1995 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1996 | static struct inode * |
| 1997 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1998 | { |
| 1999 | struct inode *inode; |
| 2000 | |
| 2001 | switch (data->o_arg.claim) { |
| 2002 | case NFS4_OPEN_CLAIM_NULL: |
| 2003 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 2004 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 2005 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 2006 | return ERR_PTR(-EAGAIN); |
| 2007 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
Anna Schumaker | cf7ab00 | 2021-10-22 13:11:11 -0400 | [diff] [blame] | 2008 | &data->f_attr); |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 2009 | break; |
| 2010 | default: |
| 2011 | inode = d_inode(data->dentry); |
| 2012 | ihold(inode); |
| 2013 | nfs_refresh_inode(inode, &data->f_attr); |
| 2014 | } |
| 2015 | return inode; |
| 2016 | } |
| 2017 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2018 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2019 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 2020 | { |
| 2021 | struct nfs4_state *state; |
| 2022 | struct inode *inode; |
| 2023 | |
| 2024 | inode = nfs4_opendata_get_inode(data); |
| 2025 | if (IS_ERR(inode)) |
| 2026 | return ERR_CAST(inode); |
| 2027 | if (data->state != NULL && data->state->inode == inode) { |
| 2028 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2029 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2030 | } else |
| 2031 | state = nfs4_get_open_state(inode, data->owner); |
| 2032 | iput(inode); |
| 2033 | if (state == NULL) |
| 2034 | state = ERR_PTR(-ENOMEM); |
| 2035 | return state; |
| 2036 | } |
| 2037 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2038 | static struct nfs4_state * |
| 2039 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2040 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2041 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2042 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2043 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2044 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2045 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2046 | goto out; |
| 2047 | } |
| 2048 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2049 | state = nfs4_opendata_find_nfs4_state(data); |
| 2050 | if (IS_ERR(state)) |
| 2051 | goto out; |
| 2052 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2053 | if (data->o_res.delegation_type != 0) |
| 2054 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 2055 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 2056 | NULL, data->o_arg.fmode)) { |
| 2057 | nfs4_put_open_state(state); |
| 2058 | state = ERR_PTR(-EAGAIN); |
| 2059 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2060 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 2061 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2062 | return state; |
| 2063 | } |
| 2064 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2065 | static struct nfs4_state * |
| 2066 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2067 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2068 | struct nfs4_state *ret; |
| 2069 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2070 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2071 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2072 | else |
| 2073 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2074 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2075 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2076 | } |
| 2077 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2078 | static struct nfs_open_context * |
| 2079 | 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] | 2080 | { |
| 2081 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2082 | struct nfs_open_context *ctx; |
| 2083 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2084 | rcu_read_lock(); |
| 2085 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2086 | if (ctx->state != state) |
| 2087 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2088 | if ((ctx->mode & mode) != mode) |
| 2089 | continue; |
| 2090 | if (!get_nfs_open_context(ctx)) |
| 2091 | continue; |
| 2092 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2093 | return ctx; |
| 2094 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2095 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2096 | return ERR_PTR(-ENOENT); |
| 2097 | } |
| 2098 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2099 | static struct nfs_open_context * |
| 2100 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2101 | { |
| 2102 | struct nfs_open_context *ctx; |
| 2103 | |
| 2104 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2105 | if (!IS_ERR(ctx)) |
| 2106 | return ctx; |
| 2107 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2108 | if (!IS_ERR(ctx)) |
| 2109 | return ctx; |
| 2110 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2111 | } |
| 2112 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2113 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2114 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2115 | { |
| 2116 | struct nfs4_opendata *opendata; |
| 2117 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2118 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2119 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2120 | if (opendata == NULL) |
| 2121 | return ERR_PTR(-ENOMEM); |
| 2122 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2123 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2124 | return opendata; |
| 2125 | } |
| 2126 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2127 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2128 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2129 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2130 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2131 | int ret; |
| 2132 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2133 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2134 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2135 | opendata->o_arg.open_flags = 0; |
| 2136 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2137 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2138 | NFS_SB(opendata->dentry->d_sb), |
| 2139 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2140 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2141 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2142 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2143 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2144 | if (ret != 0) |
| 2145 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2146 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2147 | if (IS_ERR(newstate)) |
| 2148 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2149 | if (newstate != opendata->state) |
| 2150 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2151 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2152 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2156 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2157 | int ret; |
| 2158 | |
| 2159 | /* memory barrier prior to reading state->n_* */ |
| 2160 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2161 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2162 | if (ret != 0) |
| 2163 | return ret; |
| 2164 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2165 | if (ret != 0) |
| 2166 | return ret; |
| 2167 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2168 | if (ret != 0) |
| 2169 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2170 | /* |
| 2171 | * We may have performed cached opens for all three recoveries. |
| 2172 | * Check if we need to update the current stateid. |
| 2173 | */ |
| 2174 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2175 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2176 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 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_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2179 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2180 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2181 | return 0; |
| 2182 | } |
| 2183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | /* |
| 2185 | * OPEN_RECLAIM: |
| 2186 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2188 | 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] | 2189 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2190 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2191 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2192 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | int status; |
| 2194 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2195 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2196 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2197 | if (IS_ERR(opendata)) |
| 2198 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2199 | rcu_read_lock(); |
| 2200 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2201 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2202 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2203 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2204 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2205 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2206 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | return status; |
| 2208 | } |
| 2209 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2210 | 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] | 2211 | { |
| 2212 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2213 | struct nfs4_exception exception = { }; |
| 2214 | int err; |
| 2215 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2216 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2217 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2218 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2219 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2220 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2221 | break; |
| 2222 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | } while (exception.retry); |
| 2224 | return err; |
| 2225 | } |
| 2226 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2227 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2228 | { |
| 2229 | struct nfs_open_context *ctx; |
| 2230 | int ret; |
| 2231 | |
| 2232 | ctx = nfs4_state_find_open_context(state); |
| 2233 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2234 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2235 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2236 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2237 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2238 | put_nfs_open_context(ctx); |
| 2239 | return ret; |
| 2240 | } |
| 2241 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2242 | 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] | 2243 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2244 | switch (err) { |
| 2245 | default: |
| 2246 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2247 | "%d.\n", __func__, err); |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame] | 2248 | fallthrough; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2249 | case 0: |
| 2250 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2251 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2252 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2253 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2254 | break; |
| 2255 | case -NFS4ERR_BADSESSION: |
| 2256 | case -NFS4ERR_BADSLOT: |
| 2257 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2258 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2259 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2260 | return -EAGAIN; |
| 2261 | case -NFS4ERR_STALE_CLIENTID: |
| 2262 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2263 | /* Don't recall a delegation if it was lost */ |
| 2264 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2265 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2266 | case -NFS4ERR_MOVED: |
| 2267 | nfs4_schedule_migration_recovery(server); |
| 2268 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2269 | case -NFS4ERR_LEASE_MOVED: |
| 2270 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2271 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2272 | case -NFS4ERR_DELEG_REVOKED: |
| 2273 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2274 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2275 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2276 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2277 | nfs_inode_find_state_and_recover(state->inode, |
| 2278 | stateid); |
| 2279 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2280 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2281 | case -NFS4ERR_DELAY: |
| 2282 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2283 | ssleep(1); |
| 2284 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2285 | case -ENOMEM: |
| 2286 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2287 | if (fl) { |
| 2288 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2289 | if (lsp) |
| 2290 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2291 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2292 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | return err; |
| 2295 | } |
| 2296 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2297 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2298 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2299 | { |
| 2300 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2301 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2302 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2303 | |
| 2304 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2305 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2306 | if (IS_ERR(opendata)) |
| 2307 | return PTR_ERR(opendata); |
| 2308 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2309 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2310 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2311 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2312 | goto out; |
| 2313 | } |
| 2314 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2315 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2316 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2317 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2318 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2319 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2320 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2321 | if (err) |
| 2322 | goto out; |
| 2323 | } |
| 2324 | nfs_state_clear_delegation(state); |
| 2325 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2326 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2327 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2328 | } |
| 2329 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2330 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2331 | { |
| 2332 | struct nfs4_opendata *data = calldata; |
| 2333 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2334 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2335 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2336 | } |
| 2337 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2338 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2339 | { |
| 2340 | struct nfs4_opendata *data = calldata; |
| 2341 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2342 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2343 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2344 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2345 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2346 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2347 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2348 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2349 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2350 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | static void nfs4_open_confirm_release(void *calldata) |
| 2354 | { |
| 2355 | struct nfs4_opendata *data = calldata; |
| 2356 | struct nfs4_state *state = NULL; |
| 2357 | |
| 2358 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2359 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2360 | goto out_free; |
| 2361 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2362 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2363 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2364 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2365 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2366 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2367 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2368 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2372 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2373 | .rpc_call_done = nfs4_open_confirm_done, |
| 2374 | .rpc_release = nfs4_open_confirm_release, |
| 2375 | }; |
| 2376 | |
| 2377 | /* |
| 2378 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2379 | */ |
| 2380 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2381 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2382 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2383 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2384 | struct rpc_message msg = { |
| 2385 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2386 | .rpc_argp = &data->c_arg, |
| 2387 | .rpc_resp = &data->c_res, |
| 2388 | .rpc_cred = data->owner->so_cred, |
| 2389 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2390 | struct rpc_task_setup task_setup_data = { |
| 2391 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2392 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2393 | .callback_ops = &nfs4_open_confirm_ops, |
| 2394 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2395 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2396 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2397 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | int status; |
| 2399 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2400 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2401 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2402 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2403 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2404 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2405 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2406 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2407 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2408 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2409 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2410 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2411 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2412 | smp_wmb(); |
| 2413 | } else |
| 2414 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2415 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | return status; |
| 2417 | } |
| 2418 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2419 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2421 | struct nfs4_opendata *data = calldata; |
| 2422 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2423 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2424 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2425 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2426 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2427 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2428 | /* |
| 2429 | * Check if we still need to send an OPEN call, or if we can use |
| 2430 | * a delegation instead. |
| 2431 | */ |
| 2432 | if (data->state != NULL) { |
| 2433 | struct nfs_delegation *delegation; |
| 2434 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2435 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2436 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2437 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2438 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 2439 | delegation = nfs4_get_valid_delegation(data->state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2440 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2441 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2442 | rcu_read_unlock(); |
| 2443 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2444 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2445 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2446 | switch (claim) { |
| 2447 | default: |
| 2448 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2449 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2450 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2451 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2452 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2453 | fallthrough; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2454 | case NFS4_OPEN_CLAIM_FH: |
| 2455 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2456 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2457 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2458 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2459 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2460 | &data->o_res.seq_res, |
| 2461 | task) != 0) |
| 2462 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2463 | |
| 2464 | /* Set the create mode (note dependency on the session type) */ |
| 2465 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2466 | if (data->o_arg.open_flags & O_EXCL) { |
Trond Myklebust | a1e7f30 | 2021-07-14 13:00:58 -0400 | [diff] [blame] | 2467 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2468 | if (clp->cl_mvops->minor_version == 0) { |
| 2469 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2470 | /* don't put an ACCESS op in OPEN compound if O_EXCL, |
| 2471 | * because ACCESS will return permission denied for |
| 2472 | * all bits until close */ |
| 2473 | data->o_res.access_request = data->o_arg.access = 0; |
| 2474 | } else if (nfs4_has_persistent_session(clp)) |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2475 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2476 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2477 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2478 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2479 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2480 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2481 | out_no_action: |
| 2482 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2483 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2484 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2485 | } |
| 2486 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2487 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2488 | { |
| 2489 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2491 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2492 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2493 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2494 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2495 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2496 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2497 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2498 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2499 | case S_IFREG: |
| 2500 | break; |
| 2501 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2502 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2503 | break; |
| 2504 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2505 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2506 | break; |
| 2507 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2508 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2509 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2510 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2511 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2512 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2513 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2514 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2515 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2516 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2517 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2518 | static void nfs4_open_release(void *calldata) |
| 2519 | { |
| 2520 | struct nfs4_opendata *data = calldata; |
| 2521 | struct nfs4_state *state = NULL; |
| 2522 | |
| 2523 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2524 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2525 | goto out_free; |
| 2526 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2527 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2528 | goto out_free; |
| 2529 | /* In case we need an open_confirm, no cleanup! */ |
| 2530 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2531 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2532 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2533 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2534 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2535 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2536 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2540 | .rpc_call_prepare = nfs4_open_prepare, |
| 2541 | .rpc_call_done = nfs4_open_done, |
| 2542 | .rpc_release = nfs4_open_release, |
| 2543 | }; |
| 2544 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2545 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2546 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2547 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2548 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2549 | struct nfs_server *server = NFS_SERVER(dir); |
| 2550 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2551 | struct nfs_openres *o_res = &data->o_res; |
| 2552 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2553 | struct rpc_message msg = { |
| 2554 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2555 | .rpc_argp = o_arg, |
| 2556 | .rpc_resp = o_res, |
| 2557 | .rpc_cred = data->owner->so_cred, |
| 2558 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2559 | struct rpc_task_setup task_setup_data = { |
| 2560 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2561 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2562 | .callback_ops = &nfs4_open_ops, |
| 2563 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2564 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2565 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2566 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2567 | int status; |
| 2568 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 2569 | if (server->nfs_client->cl_minorversion) |
| 2570 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
| 2571 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2572 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2573 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2574 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2575 | data->cancelled = false; |
| 2576 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2577 | if (!ctx) { |
| 2578 | 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] | 2579 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2580 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2581 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2582 | 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] | 2583 | pnfs_lgopen_prepare(data, ctx); |
| 2584 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2585 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2586 | if (IS_ERR(task)) |
| 2587 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2588 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2589 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2590 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2591 | smp_wmb(); |
| 2592 | } else |
| 2593 | status = data->rpc_status; |
| 2594 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2595 | |
| 2596 | return status; |
| 2597 | } |
| 2598 | |
| 2599 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2600 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2601 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2602 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2603 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2604 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2605 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2606 | if (status != 0 || !data->rpc_done) |
| 2607 | return status; |
| 2608 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2609 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2610 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2611 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2612 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2613 | |
| 2614 | return status; |
| 2615 | } |
| 2616 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2617 | /* |
| 2618 | * Additional permission checks in order to distinguish between an |
| 2619 | * open for read, and an open for execute. This works around the |
| 2620 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2621 | * the same. |
| 2622 | * Note that in the non-execute case, we want to turn off permission |
| 2623 | * checking if we just created a new file (POSIX open() semantics). |
| 2624 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2625 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2626 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2627 | struct nfs4_state *state, fmode_t fmode, |
| 2628 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2629 | { |
| 2630 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2631 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2632 | |
| 2633 | /* access call failed or for some reason the server doesn't |
| 2634 | * support any access modes -- defer access call until later */ |
| 2635 | if (opendata->o_res.access_supported == 0) |
| 2636 | return 0; |
| 2637 | |
| 2638 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2639 | /* |
| 2640 | * Use openflags to check for exec, because fmode won't |
| 2641 | * always have FMODE_EXEC set when file open for exec. |
| 2642 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2643 | if (openflags & __FMODE_EXEC) { |
| 2644 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2645 | if (S_ISDIR(state->inode->i_mode)) |
| 2646 | mask = NFS4_ACCESS_LOOKUP; |
| 2647 | else |
| 2648 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2649 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2650 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2651 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2652 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
NeilBrown | 73fbb3f | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 2653 | nfs_access_add_cache(state->inode, &cache, cred); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2654 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2655 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2656 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2657 | return 0; |
| 2658 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2659 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2660 | } |
| 2661 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2662 | /* |
| 2663 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2664 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2665 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2666 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2667 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2668 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2669 | struct nfs_server *server = NFS_SERVER(dir); |
| 2670 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2671 | struct nfs_openres *o_res = &data->o_res; |
| 2672 | int status; |
| 2673 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2674 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2675 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2676 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2677 | if (status != 0) { |
| 2678 | if (status == -NFS4ERR_BADNAME && |
| 2679 | !(o_arg->open_flags & O_CREAT)) |
| 2680 | return -ENOENT; |
| 2681 | return status; |
| 2682 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2683 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2684 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2685 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2686 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2687 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2688 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2689 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2690 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2691 | if (data->file_created || |
| 2692 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 2693 | nfs4_update_changeattr(dir, &o_res->cinfo, |
| 2694 | o_res->f_attr->time_start, |
| 2695 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2696 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2697 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2698 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2700 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2702 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2704 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2705 | nfs4_sequence_free_slot(&o_res->seq_res); |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 2706 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2707 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2708 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | /* |
| 2712 | * OPEN_EXPIRED: |
| 2713 | * reclaim state on the server after a network partition. |
| 2714 | * Assumes caller holds the appropriate lock |
| 2715 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2716 | 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] | 2717 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2718 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2719 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2721 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2722 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2723 | if (IS_ERR(opendata)) |
| 2724 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2725 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2726 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2727 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2728 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2729 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2732 | 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] | 2733 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2734 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2735 | struct nfs4_exception exception = { }; |
| 2736 | int err; |
| 2737 | |
| 2738 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2739 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2740 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2741 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2742 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2743 | switch (err) { |
| 2744 | default: |
| 2745 | goto out; |
| 2746 | case -NFS4ERR_GRACE: |
| 2747 | case -NFS4ERR_DELAY: |
| 2748 | nfs4_handle_exception(server, err, &exception); |
| 2749 | err = 0; |
| 2750 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2751 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2752 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2753 | return err; |
| 2754 | } |
| 2755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2757 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2759 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2761 | ctx = nfs4_state_find_open_context(state); |
| 2762 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2763 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2764 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2765 | put_nfs_open_context(ctx); |
| 2766 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | } |
| 2768 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2769 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2770 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2771 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2772 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2773 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2777 | { |
| 2778 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2779 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2783 | { |
| 2784 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2785 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2786 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2787 | return nfs4_open_expired(sp, state); |
| 2788 | } |
| 2789 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2790 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2791 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2792 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2793 | { |
| 2794 | return -NFS4ERR_BAD_STATEID; |
| 2795 | } |
| 2796 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2797 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2798 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2799 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2800 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2801 | { |
| 2802 | int status; |
| 2803 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2804 | switch (stateid->type) { |
| 2805 | default: |
| 2806 | break; |
| 2807 | case NFS4_INVALID_STATEID_TYPE: |
| 2808 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2809 | return -NFS4ERR_BAD_STATEID; |
| 2810 | case NFS4_REVOKED_STATEID_TYPE: |
| 2811 | goto out_free; |
| 2812 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2813 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2814 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2815 | switch (status) { |
| 2816 | case -NFS4ERR_EXPIRED: |
| 2817 | case -NFS4ERR_ADMIN_REVOKED: |
| 2818 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2819 | break; |
| 2820 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2821 | return status; |
| 2822 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2823 | out_free: |
| 2824 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2825 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2826 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2827 | } |
| 2828 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2829 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2830 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2831 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2832 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2833 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2834 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2835 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2836 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2837 | /* Get the delegation credential for use by test/free_stateid */ |
| 2838 | rcu_read_lock(); |
| 2839 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2840 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2841 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2842 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2843 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2844 | } |
| 2845 | |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2846 | spin_lock(&delegation->lock); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2847 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2848 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2849 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2850 | &delegation->flags)) { |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2851 | spin_unlock(&delegation->lock); |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2852 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2853 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2854 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2855 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2856 | if (delegation->cred) |
| 2857 | cred = get_cred(delegation->cred); |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2858 | spin_unlock(&delegation->lock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2859 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2860 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2861 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2862 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2863 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2864 | else |
| 2865 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2866 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2867 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2868 | return ret; |
| 2869 | } |
| 2870 | |
| 2871 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2872 | { |
| 2873 | nfs4_stateid tmp; |
| 2874 | |
| 2875 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2876 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2877 | &tmp, NULL) && |
| 2878 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2879 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2880 | else |
| 2881 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2885 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2886 | * |
| 2887 | * @state: NFSv4 state for an inode |
| 2888 | * |
| 2889 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2890 | * Otherwise a negative NFS4ERR value is returned. |
| 2891 | */ |
| 2892 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2893 | { |
| 2894 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2895 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2896 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2897 | |
| 2898 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2899 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2900 | |
| 2901 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2902 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2903 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2904 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2905 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2906 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2907 | spin_unlock(&state->state_lock); |
| 2908 | |
| 2909 | nfs4_put_lock_state(prev); |
| 2910 | prev = lsp; |
| 2911 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2912 | status = nfs41_test_and_free_expired_stateid(server, |
| 2913 | &lsp->ls_stateid, |
| 2914 | cred); |
| 2915 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2916 | if (status == -NFS4ERR_EXPIRED || |
| 2917 | status == -NFS4ERR_BAD_STATEID) { |
| 2918 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2919 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2920 | if (!recover_lost_locks) |
| 2921 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2922 | } else if (status != NFS_OK) { |
| 2923 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2924 | nfs4_put_lock_state(prev); |
| 2925 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2926 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2927 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2928 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2929 | } |
| 2930 | spin_unlock(&state->state_lock); |
| 2931 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2932 | out: |
| 2933 | return ret; |
| 2934 | } |
| 2935 | |
| 2936 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2937 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2938 | * |
| 2939 | * @state: NFSv4 state for an inode |
| 2940 | * |
| 2941 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2942 | * Otherwise a negative NFS4ERR value is returned. |
| 2943 | */ |
| 2944 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2945 | { |
| 2946 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2947 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2948 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2949 | int status; |
| 2950 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2951 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2952 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2953 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2954 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2955 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2956 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2957 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2958 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2959 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2960 | if (nfs_open_stateid_recover_openmode(state)) |
| 2961 | return -NFS4ERR_OPENMODE; |
| 2962 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2966 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2967 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2968 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2969 | status = nfs41_check_delegation_stateid(state); |
| 2970 | if (status != NFS_OK) |
| 2971 | return status; |
| 2972 | nfs41_delegation_recover_stateid(state); |
| 2973 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2974 | status = nfs41_check_expired_locks(state); |
| 2975 | if (status != NFS_OK) |
| 2976 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2977 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2978 | if (status != NFS_OK) |
| 2979 | status = nfs4_open_expired(sp, state); |
| 2980 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2981 | } |
| 2982 | #endif |
| 2983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2985 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2986 | * fields corresponding to attributes that were used to store the verifier. |
| 2987 | * Make sure we clobber those fields in the later setattr call |
| 2988 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2989 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2990 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2991 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2992 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2993 | __u32 attrset[3]; |
| 2994 | unsigned ret; |
| 2995 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2996 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2997 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2998 | attrset[i] = opendata->o_res.attrset[i]; |
| 2999 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 3000 | attrset[i] &= ~bitmask[i]; |
| 3001 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3002 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3003 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 3004 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3005 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3006 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 3007 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 3008 | ret |= ATTR_ATIME_SET; |
| 3009 | else |
| 3010 | ret |= ATTR_ATIME; |
| 3011 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3012 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3013 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 3014 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 3015 | ret |= ATTR_MTIME_SET; |
| 3016 | else |
| 3017 | ret |= ATTR_MTIME; |
| 3018 | } |
| 3019 | |
| 3020 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 3021 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3022 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3023 | } |
| 3024 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3025 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3026 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3027 | { |
| 3028 | struct nfs4_state_owner *sp = opendata->owner; |
| 3029 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3030 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3031 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3032 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3033 | struct inode *dir = d_inode(opendata->dir); |
| 3034 | unsigned long dir_verifier; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3035 | unsigned int seq; |
| 3036 | int ret; |
| 3037 | |
| 3038 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3039 | dir_verifier = nfs_save_change_attribute(dir); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3040 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 3041 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 3042 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3043 | goto out; |
| 3044 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 3045 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3046 | ret = PTR_ERR(state); |
| 3047 | if (IS_ERR(state)) |
| 3048 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 3049 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3050 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 3051 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 3052 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 3053 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3054 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3055 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3056 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3057 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3058 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3059 | alias = d_exact_alias(dentry, state->inode); |
| 3060 | if (!alias) |
| 3061 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 3062 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 3063 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3064 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3065 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3066 | } |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | switch(opendata->o_arg.claim) { |
| 3070 | default: |
| 3071 | break; |
| 3072 | case NFS4_OPEN_CLAIM_NULL: |
| 3073 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 3074 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 3075 | if (!opendata->rpc_done) |
| 3076 | break; |
| 3077 | if (opendata->o_res.delegation_type != 0) |
| 3078 | dir_verifier = nfs_save_change_attribute(dir); |
| 3079 | nfs_set_verifier(dentry, dir_verifier); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3080 | } |
| 3081 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 3082 | /* Parse layoutget results before we check for access */ |
| 3083 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 3084 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3085 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 3086 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3087 | if (ret != 0) |
| 3088 | goto out; |
| 3089 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3090 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3091 | nfs_inode_attach_open_context(ctx); |
| 3092 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3093 | nfs4_schedule_stateid_recovery(server, state); |
| 3094 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3095 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3096 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3097 | if (!opendata->cancelled) |
| 3098 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3099 | return ret; |
| 3100 | } |
| 3101 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3102 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3103 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3105 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3106 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3107 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3108 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3109 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | { |
| 3111 | struct nfs4_state_owner *sp; |
| 3112 | struct nfs4_state *state = NULL; |
| 3113 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3114 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3115 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3116 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3117 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3118 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3119 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3120 | struct iattr *sattr = c->sattr; |
| 3121 | struct nfs4_label *label = c->label; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3122 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | |
| 3124 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3126 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3127 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3129 | goto out_err; |
| 3130 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3131 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3132 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3133 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3134 | if (d_really_is_positive(dentry)) |
| 3135 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3136 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3137 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3138 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3139 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3140 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3141 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3142 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3144 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3145 | if (!opendata->f_attr.mdsthreshold) { |
| 3146 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3147 | if (!opendata->f_attr.mdsthreshold) |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3148 | goto err_opendata_put; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3149 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3150 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3151 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3152 | if (d_really_is_positive(dentry)) |
| 3153 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3154 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3155 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3156 | if (status != 0) |
Anna Schumaker | 76baa2b | 2021-10-22 13:11:06 -0400 | [diff] [blame] | 3157 | goto err_opendata_put; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3158 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3159 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3160 | 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] | 3161 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3162 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3163 | /* |
| 3164 | * send create attributes which was not set by open |
| 3165 | * with an extra setattr. |
| 3166 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3167 | if (attrs || label) { |
| 3168 | unsigned ia_old = sattr->ia_valid; |
| 3169 | |
| 3170 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3171 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3172 | status = nfs4_do_setattr(state->inode, cred, |
| 3173 | opendata->o_res.f_attr, sattr, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 3174 | ctx, label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3175 | if (status == 0) { |
| 3176 | nfs_setattr_update_inode(state->inode, sattr, |
| 3177 | opendata->o_res.f_attr); |
Anna Schumaker | dd225cb | 2021-10-22 13:11:12 -0400 | [diff] [blame] | 3178 | nfs_setsecurity(state->inode, opendata->o_res.f_attr); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3179 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3180 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3181 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3182 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3183 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3184 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3185 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3186 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3187 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3188 | opendata->f_attr.mdsthreshold = NULL; |
| 3189 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3190 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3191 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3194 | err_opendata_put: |
| 3195 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3196 | err_put_state_owner: |
| 3197 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | return status; |
| 3200 | } |
| 3201 | |
| 3202 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3203 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3204 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3205 | int flags, |
| 3206 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3207 | struct nfs4_label *label, |
| 3208 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3210 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3211 | struct nfs4_exception exception = { |
| 3212 | .interruptible = true, |
| 3213 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3215 | struct nfs4_open_createattrs c = { |
| 3216 | .label = label, |
| 3217 | .sattr = sattr, |
| 3218 | .verf = { |
| 3219 | [0] = (__u32)jiffies, |
| 3220 | [1] = (__u32)current->pid, |
| 3221 | }, |
| 3222 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | int status; |
| 3224 | |
| 3225 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3226 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3227 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3228 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | if (status == 0) |
| 3230 | break; |
| 3231 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3232 | * book-keeping w.r.t. state-changing operations |
| 3233 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3234 | * It is actually a sign of a bug on the client or on the server. |
| 3235 | * |
| 3236 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3237 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | * have unhashed the old state_owner for us, and that we can |
| 3239 | * therefore safely retry using a new one. We should still warn |
| 3240 | * the user though... |
| 3241 | */ |
| 3242 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3243 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3244 | " returned a bad sequence-id error!\n", |
| 3245 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | exception.retry = 1; |
| 3247 | continue; |
| 3248 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3249 | /* |
| 3250 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3251 | * state before it received the OPEN_CONFIRM. |
| 3252 | * Recover by retrying the request as per the discussion |
| 3253 | * on Page 181 of RFC3530. |
| 3254 | */ |
| 3255 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3256 | exception.retry = 1; |
| 3257 | continue; |
| 3258 | } |
Robert Milkowski | 924491f | 2020-01-28 08:37:47 +0000 | [diff] [blame] | 3259 | if (status == -NFS4ERR_EXPIRED) { |
| 3260 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 3261 | exception.retry = 1; |
| 3262 | continue; |
| 3263 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3264 | if (status == -EAGAIN) { |
| 3265 | /* We must have found a delegation */ |
| 3266 | exception.retry = 1; |
| 3267 | continue; |
| 3268 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3269 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3270 | continue; |
| 3271 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | status, &exception)); |
| 3273 | } while (exception.retry); |
| 3274 | return res; |
| 3275 | } |
| 3276 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3277 | static int _nfs4_do_setattr(struct inode *inode, |
| 3278 | struct nfs_setattrargs *arg, |
| 3279 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3280 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3281 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3282 | { |
| 3283 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3284 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3285 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3286 | .rpc_argp = arg, |
| 3287 | .rpc_resp = res, |
| 3288 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3289 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3290 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3291 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3292 | bool truncate; |
| 3293 | int status; |
| 3294 | |
| 3295 | nfs_fattr_init(res->fattr); |
| 3296 | |
| 3297 | /* Servers should only apply open mode checks for file size changes */ |
| 3298 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3299 | if (!truncate) { |
| 3300 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3301 | goto zero_stateid; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3302 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3303 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3304 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3305 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3306 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3307 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3308 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3309 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3310 | l_ctx = nfs_get_lock_context(ctx); |
| 3311 | if (IS_ERR(l_ctx)) |
| 3312 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3313 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3314 | &arg->stateid, &delegation_cred); |
| 3315 | nfs_put_lock_context(l_ctx); |
| 3316 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3317 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3318 | else if (status == -EAGAIN) |
| 3319 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3320 | } else { |
| 3321 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3322 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3323 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3324 | if (delegation_cred) |
| 3325 | msg.rpc_cred = delegation_cred; |
| 3326 | |
| 3327 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3328 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3329 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3330 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3331 | renew_lease(server, timestamp); |
| 3332 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3333 | return status; |
| 3334 | } |
| 3335 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3336 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3337 | struct nfs_fattr *fattr, struct iattr *sattr, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 3338 | struct nfs_open_context *ctx, struct nfs4_label *ilabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3340 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3341 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3342 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3343 | struct nfs_setattrargs arg = { |
| 3344 | .fh = NFS_FH(inode), |
| 3345 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3347 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3348 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3349 | }; |
| 3350 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | .fattr = fattr, |
| 3352 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3353 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3354 | struct nfs4_exception exception = { |
| 3355 | .state = state, |
| 3356 | .inode = inode, |
| 3357 | .stateid = &arg.stateid, |
| 3358 | }; |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3359 | unsigned long adjust_flags = NFS_INO_INVALID_CHANGE; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3360 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 3362 | if (sattr->ia_valid & (ATTR_MODE | ATTR_KILL_SUID | ATTR_KILL_SGID)) |
| 3363 | adjust_flags |= NFS_INO_INVALID_MODE; |
| 3364 | if (sattr->ia_valid & (ATTR_UID | ATTR_GID)) |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3365 | adjust_flags |= NFS_INO_INVALID_OTHER; |
| 3366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | do { |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 3368 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label), |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 3369 | inode, adjust_flags); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3370 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3371 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3372 | switch (err) { |
| 3373 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3374 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3375 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3376 | "applying open mode checks to " |
| 3377 | "a SETATTR that is not " |
| 3378 | "changing file size.\n", |
| 3379 | server->nfs_client->cl_hostname); |
| 3380 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3381 | if (state && !(state->state & FMODE_WRITE)) { |
| 3382 | err = -EBADF; |
| 3383 | if (sattr->ia_valid & ATTR_OPEN) |
| 3384 | err = -EACCES; |
| 3385 | goto out; |
| 3386 | } |
| 3387 | } |
| 3388 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3390 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | return err; |
| 3392 | } |
| 3393 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3394 | static bool |
| 3395 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3396 | { |
| 3397 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3398 | return false; |
| 3399 | |
| 3400 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3401 | } |
| 3402 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3403 | /* |
| 3404 | * Update the seqid of an open stateid |
| 3405 | */ |
| 3406 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3407 | struct nfs4_state *state) |
| 3408 | { |
| 3409 | __be32 seqid_open; |
| 3410 | u32 dst_seqid; |
| 3411 | int seq; |
| 3412 | |
| 3413 | for (;;) { |
| 3414 | if (!nfs4_valid_open_stateid(state)) |
| 3415 | break; |
| 3416 | seq = read_seqbegin(&state->seqlock); |
| 3417 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3418 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3419 | if (read_seqretry(&state->seqlock, seq)) |
| 3420 | continue; |
| 3421 | break; |
| 3422 | } |
| 3423 | seqid_open = state->open_stateid.seqid; |
| 3424 | if (read_seqretry(&state->seqlock, seq)) |
| 3425 | continue; |
| 3426 | |
| 3427 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3428 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3429 | dst->seqid = seqid_open; |
| 3430 | break; |
| 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | /* |
| 3435 | * Update the seqid of an open stateid after receiving |
| 3436 | * NFS4ERR_OLD_STATEID |
| 3437 | */ |
| 3438 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3439 | struct nfs4_state *state) |
| 3440 | { |
| 3441 | __be32 seqid_open; |
| 3442 | u32 dst_seqid; |
| 3443 | bool ret; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3444 | int seq, status = -EAGAIN; |
| 3445 | DEFINE_WAIT(wait); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3446 | |
| 3447 | for (;;) { |
| 3448 | ret = false; |
| 3449 | if (!nfs4_valid_open_stateid(state)) |
| 3450 | break; |
| 3451 | seq = read_seqbegin(&state->seqlock); |
| 3452 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3453 | if (read_seqretry(&state->seqlock, seq)) |
| 3454 | continue; |
| 3455 | break; |
| 3456 | } |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3457 | |
| 3458 | write_seqlock(&state->seqlock); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3459 | seqid_open = state->open_stateid.seqid; |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3460 | |
| 3461 | dst_seqid = be32_to_cpu(dst->seqid); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3462 | |
| 3463 | /* Did another OPEN bump the state's seqid? try again: */ |
| 3464 | if ((s32)(be32_to_cpu(seqid_open) - dst_seqid) > 0) { |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3465 | dst->seqid = seqid_open; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3466 | write_sequnlock(&state->seqlock); |
| 3467 | ret = true; |
| 3468 | break; |
| 3469 | } |
| 3470 | |
| 3471 | /* server says we're behind but we haven't seen the update yet */ |
| 3472 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 3473 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 3474 | write_sequnlock(&state->seqlock); |
| 3475 | trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); |
| 3476 | |
zhouchuangao | bb00238 | 2021-05-09 19:34:37 -0700 | [diff] [blame] | 3477 | if (fatal_signal_pending(current)) |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3478 | status = -EINTR; |
| 3479 | else |
| 3480 | if (schedule_timeout(5*HZ) != 0) |
| 3481 | status = 0; |
| 3482 | |
| 3483 | finish_wait(&state->waitq, &wait); |
| 3484 | |
| 3485 | if (!status) |
| 3486 | continue; |
| 3487 | if (status == -EINTR) |
| 3488 | break; |
| 3489 | |
| 3490 | /* we slept the whole 5 seconds, we must have lost a seqid */ |
| 3491 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3492 | ret = true; |
| 3493 | break; |
| 3494 | } |
| 3495 | |
| 3496 | return ret; |
| 3497 | } |
| 3498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | struct nfs4_closedata { |
| 3500 | struct inode *inode; |
| 3501 | struct nfs4_state *state; |
| 3502 | struct nfs_closeargs arg; |
| 3503 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3504 | struct { |
| 3505 | struct nfs4_layoutreturn_args arg; |
| 3506 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3507 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3508 | u32 roc_barrier; |
| 3509 | bool roc; |
| 3510 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3511 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3512 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | }; |
| 3514 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3515 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3516 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3517 | struct nfs4_closedata *calldata = data; |
| 3518 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3519 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3520 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3521 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3522 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3523 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3524 | nfs4_put_open_state(calldata->state); |
| 3525 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3526 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3527 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3528 | kfree(calldata); |
| 3529 | } |
| 3530 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3531 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3533 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3536 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3537 | struct nfs4_exception exception = { |
| 3538 | .state = state, |
| 3539 | .inode = calldata->inode, |
| 3540 | .stateid = &calldata->arg.stateid, |
| 3541 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3543 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3544 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3545 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3546 | |
| 3547 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 3548 | if (pnfs_roc_done(task, &calldata->arg.lr_args, &calldata->res.lr_res, |
| 3549 | &calldata->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3550 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3551 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3552 | /* 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] | 3553 | * the state_owner. we keep this around to process errors |
| 3554 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | switch (task->tk_status) { |
| 3556 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3557 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3558 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3559 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3560 | case -NFS4ERR_ACCESS: |
| 3561 | if (calldata->arg.bitmask != NULL) { |
| 3562 | calldata->arg.bitmask = NULL; |
| 3563 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3564 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3565 | |
| 3566 | } |
| 3567 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3568 | case -NFS4ERR_OLD_STATEID: |
| 3569 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3570 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3571 | state)) |
| 3572 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3573 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3574 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3576 | case -NFS4ERR_EXPIRED: |
| 3577 | nfs4_free_revoked_stateid(server, |
| 3578 | &calldata->arg.stateid, |
| 3579 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3580 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3581 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3582 | if (calldata->arg.fmode == 0) |
| 3583 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3584 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3586 | task->tk_status = nfs4_async_handle_exception(task, |
| 3587 | server, task->tk_status, &exception); |
| 3588 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3589 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3591 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3592 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3593 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3594 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3595 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3596 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 3597 | dprintk("%s: ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3598 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3599 | out_restart: |
| 3600 | task->tk_status = 0; |
| 3601 | rpc_restart_call_prepare(task); |
| 3602 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3605 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3607 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3608 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3609 | struct inode *inode = calldata->inode; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3610 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3611 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3612 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3613 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3614 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3615 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3616 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3617 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3618 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3619 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3620 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3621 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3622 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3623 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3624 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3625 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3626 | if (state->n_rdonly == 0) |
| 3627 | call_close |= is_rdonly; |
| 3628 | else if (is_rdonly) |
| 3629 | calldata->arg.fmode |= FMODE_READ; |
| 3630 | if (state->n_wronly == 0) |
| 3631 | call_close |= is_wronly; |
| 3632 | else if (is_wronly) |
| 3633 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3634 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3635 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3636 | } else if (is_rdwr) |
| 3637 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3638 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3639 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3640 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3641 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3642 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3643 | |
| 3644 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3645 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3646 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3647 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3648 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3649 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3650 | nfs_release_seqid(calldata->arg.seqid); |
| 3651 | goto out_wait; |
| 3652 | } |
| 3653 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3654 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3655 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3656 | calldata->arg.lr_args = NULL; |
| 3657 | calldata->res.lr_res = NULL; |
| 3658 | } |
| 3659 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3660 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3661 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3662 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3663 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3664 | /* Close-to-open cache consistency revalidation */ |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3665 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3666 | nfs4_bitmask_set(calldata->arg.bitmask_store, |
| 3667 | server->cache_consistency_bitmask, |
Trond Myklebust | 8584728 | 2021-12-27 14:40:51 -0500 | [diff] [blame] | 3668 | inode, 0); |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 3669 | calldata->arg.bitmask = calldata->arg.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3670 | } else |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3671 | calldata->arg.bitmask = NULL; |
| 3672 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3673 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3674 | calldata->arg.share_access = |
| 3675 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3676 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3677 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3678 | if (calldata->res.fattr == NULL) |
| 3679 | calldata->arg.bitmask = NULL; |
| 3680 | else if (calldata->arg.bitmask == NULL) |
| 3681 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3682 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3683 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3684 | &calldata->arg.seq_args, |
| 3685 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3686 | task) != 0) |
| 3687 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3688 | return; |
| 3689 | out_no_action: |
| 3690 | task->tk_action = NULL; |
| 3691 | out_wait: |
| 3692 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3695 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3696 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3697 | .rpc_call_done = nfs4_close_done, |
| 3698 | .rpc_release = nfs4_free_closedata, |
| 3699 | }; |
| 3700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | /* |
| 3702 | * It is possible for data to be read/written from a mem-mapped file |
| 3703 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3704 | * This means that we can't safely call nfsv4 close on a file until |
| 3705 | * the inode is cleared. This in turn means that we are not good |
| 3706 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3707 | * share state even when we are done with one of the three share |
| 3708 | * stateid's in the inode. |
| 3709 | * |
| 3710 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3711 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3712 | 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] | 3713 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3714 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3715 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3717 | struct nfs4_state_owner *sp = state->owner; |
| 3718 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3719 | struct rpc_message msg = { |
| 3720 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3721 | .rpc_cred = state->owner->so_cred, |
| 3722 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3723 | struct rpc_task_setup task_setup_data = { |
| 3724 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3725 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3726 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3727 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 3728 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3729 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3730 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 3732 | if (server->nfs_client->cl_minorversion) |
| 3733 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
| 3734 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3735 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3736 | &task_setup_data.rpc_client, &msg); |
| 3737 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3738 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3740 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3741 | 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] | 3742 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3744 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3745 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3746 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3748 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3749 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3750 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3751 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3752 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3753 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3754 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3755 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3756 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3757 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3758 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3759 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3760 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3761 | if (calldata->lr.roc) { |
| 3762 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3763 | calldata->res.lr_res = &calldata->lr.res; |
| 3764 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3765 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3766 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3767 | msg.rpc_argp = &calldata->arg; |
| 3768 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3769 | task_setup_data.callback_data = calldata; |
| 3770 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3771 | if (IS_ERR(task)) |
| 3772 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3773 | status = 0; |
| 3774 | if (wait) |
| 3775 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3776 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3777 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3778 | out_free_calldata: |
| 3779 | kfree(calldata); |
| 3780 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3781 | nfs4_put_open_state(state); |
| 3782 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3783 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3786 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3787 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3788 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3791 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3792 | |
| 3793 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3795 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3796 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3797 | |
| 3798 | nfs4_label_release_security(label); |
| 3799 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3800 | if (IS_ERR(state)) |
| 3801 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3802 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | } |
| 3804 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3805 | 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] | 3806 | { |
| 3807 | if (ctx->state == NULL) |
| 3808 | return; |
| 3809 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3810 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3811 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3812 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3813 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3815 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3816 | #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] | 3817 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3820 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3821 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3822 | struct nfs4_server_caps_arg args = { |
| 3823 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3824 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3825 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | struct nfs4_server_caps_res res = {}; |
| 3827 | struct rpc_message msg = { |
| 3828 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3829 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | .rpc_resp = &res, |
| 3831 | }; |
| 3832 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3833 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3835 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3836 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3837 | FATTR4_WORD0_LINK_SUPPORT | |
| 3838 | FATTR4_WORD0_SYMLINK_SUPPORT | |
Trond Myklebust | 1ab5be4 | 2021-12-17 15:36:54 -0500 | [diff] [blame] | 3839 | FATTR4_WORD0_ACLSUPPORT | |
| 3840 | FATTR4_WORD0_CASE_INSENSITIVE | |
| 3841 | FATTR4_WORD0_CASE_PRESERVING; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3842 | if (minorversion) |
| 3843 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3844 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3845 | 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] | 3846 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3847 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3848 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3849 | case 0: |
| 3850 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3851 | res.attr_bitmask[2] = 0; |
| 3852 | break; |
| 3853 | case 1: |
| 3854 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3855 | break; |
| 3856 | case 2: |
| 3857 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3858 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | ce62b11 | 2018-03-05 15:01:18 -0500 | [diff] [blame] | 3860 | server->caps &= ~(NFS_CAP_ACLS | NFS_CAP_HARDLINKS | |
| 3861 | NFS_CAP_SYMLINKS| NFS_CAP_SECURITY_LABEL); |
| 3862 | server->fattr_valid = NFS_ATTR_FATTR_V4; |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3863 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3864 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | server->caps |= NFS_CAP_ACLS; |
| 3866 | if (res.has_links != 0) |
| 3867 | server->caps |= NFS_CAP_HARDLINKS; |
| 3868 | if (res.has_symlinks != 0) |
| 3869 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 1ab5be4 | 2021-12-17 15:36:54 -0500 | [diff] [blame] | 3870 | if (res.case_insensitive) |
| 3871 | server->caps |= NFS_CAP_CASE_INSENSITIVE; |
| 3872 | if (res.case_preserving) |
| 3873 | server->caps |= NFS_CAP_CASE_PRESERVING; |
Scott Mayhew | 0b4f132 | 2021-06-02 13:13:11 -0400 | [diff] [blame] | 3874 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3875 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3876 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3877 | #endif |
Olga Kornievskaia | 8a59bb9 | 2021-12-09 14:53:30 -0500 | [diff] [blame] | 3878 | if (res.attr_bitmask[0] & FATTR4_WORD0_FS_LOCATIONS) |
| 3879 | server->caps |= NFS_CAP_FS_LOCATIONS; |
Trond Myklebust | ce62b11 | 2018-03-05 15:01:18 -0500 | [diff] [blame] | 3880 | if (!(res.attr_bitmask[0] & FATTR4_WORD0_FILEID)) |
| 3881 | server->fattr_valid &= ~NFS_ATTR_FATTR_FILEID; |
| 3882 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_MODE)) |
| 3883 | server->fattr_valid &= ~NFS_ATTR_FATTR_MODE; |
| 3884 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)) |
| 3885 | server->fattr_valid &= ~NFS_ATTR_FATTR_NLINK; |
| 3886 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_OWNER)) |
| 3887 | server->fattr_valid &= ~(NFS_ATTR_FATTR_OWNER | |
| 3888 | NFS_ATTR_FATTR_OWNER_NAME); |
| 3889 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)) |
| 3890 | server->fattr_valid &= ~(NFS_ATTR_FATTR_GROUP | |
| 3891 | NFS_ATTR_FATTR_GROUP_NAME); |
| 3892 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_SPACE_USED)) |
| 3893 | server->fattr_valid &= ~NFS_ATTR_FATTR_SPACE_USED; |
| 3894 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)) |
| 3895 | server->fattr_valid &= ~NFS_ATTR_FATTR_ATIME; |
| 3896 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)) |
| 3897 | server->fattr_valid &= ~NFS_ATTR_FATTR_CTIME; |
| 3898 | if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)) |
| 3899 | server->fattr_valid &= ~NFS_ATTR_FATTR_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3900 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3901 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3902 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3903 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3904 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3905 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3906 | server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3907 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3908 | |
| 3909 | /* Avoid a regression due to buggy server */ |
| 3910 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3911 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3912 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3913 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3916 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | return status; |
| 3920 | } |
| 3921 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3922 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3924 | struct nfs4_exception exception = { |
| 3925 | .interruptible = true, |
| 3926 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | int err; |
Anna Schumaker | 01dde76 | 2021-10-14 13:55:04 -0400 | [diff] [blame] | 3928 | |
| 3929 | nfs4_server_set_init_caps(server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | do { |
| 3931 | err = nfs4_handle_exception(server, |
| 3932 | _nfs4_server_capabilities(server, fhandle), |
| 3933 | &exception); |
| 3934 | } while (exception.retry); |
| 3935 | return err; |
| 3936 | } |
| 3937 | |
Olga Kornievskaia | 4ca9f31 | 2021-12-09 14:53:35 -0500 | [diff] [blame] | 3938 | static void test_fs_location_for_trunking(struct nfs4_fs_location *location, |
| 3939 | struct nfs_client *clp, |
| 3940 | struct nfs_server *server) |
| 3941 | { |
| 3942 | int i; |
| 3943 | |
| 3944 | for (i = 0; i < location->nservers; i++) { |
| 3945 | struct nfs4_string *srv_loc = &location->servers[i]; |
| 3946 | struct sockaddr addr; |
| 3947 | size_t addrlen; |
| 3948 | struct xprt_create xprt_args = { |
| 3949 | .ident = 0, |
| 3950 | .net = clp->cl_net, |
| 3951 | }; |
| 3952 | struct nfs4_add_xprt_data xprtdata = { |
| 3953 | .clp = clp, |
| 3954 | }; |
| 3955 | struct rpc_add_xprt_test rpcdata = { |
| 3956 | .add_xprt_test = clp->cl_mvops->session_trunk, |
| 3957 | .data = &xprtdata, |
| 3958 | }; |
| 3959 | char *servername = NULL; |
| 3960 | |
| 3961 | if (!srv_loc->len) |
| 3962 | continue; |
| 3963 | |
| 3964 | addrlen = nfs_parse_server_name(srv_loc->data, srv_loc->len, |
| 3965 | &addr, sizeof(addr), |
| 3966 | clp->cl_net, server->port); |
| 3967 | if (!addrlen) |
| 3968 | return; |
| 3969 | xprt_args.dstaddr = &addr; |
| 3970 | xprt_args.addrlen = addrlen; |
| 3971 | servername = kmalloc(srv_loc->len + 1, GFP_KERNEL); |
| 3972 | if (!servername) |
| 3973 | return; |
| 3974 | memcpy(servername, srv_loc->data, srv_loc->len); |
| 3975 | servername[srv_loc->len] = '\0'; |
| 3976 | xprt_args.servername = servername; |
| 3977 | |
| 3978 | xprtdata.cred = nfs4_get_clid_cred(clp); |
| 3979 | rpc_clnt_add_xprt(clp->cl_rpcclient, &xprt_args, |
| 3980 | rpc_clnt_setup_test_and_add_xprt, |
| 3981 | &rpcdata); |
| 3982 | if (xprtdata.cred) |
| 3983 | put_cred(xprtdata.cred); |
| 3984 | kfree(servername); |
| 3985 | } |
| 3986 | } |
| 3987 | |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 3988 | static int _nfs4_discover_trunking(struct nfs_server *server, |
| 3989 | struct nfs_fh *fhandle) |
| 3990 | { |
| 3991 | struct nfs4_fs_locations *locations = NULL; |
| 3992 | struct page *page; |
| 3993 | const struct cred *cred; |
| 3994 | struct nfs_client *clp = server->nfs_client; |
| 3995 | const struct nfs4_state_maintenance_ops *ops = |
| 3996 | clp->cl_mvops->state_renewal_ops; |
Olga Kornievskaia | 4ca9f31 | 2021-12-09 14:53:35 -0500 | [diff] [blame] | 3997 | int status = -ENOMEM, i; |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 3998 | |
| 3999 | cred = ops->get_state_renewal_cred(clp); |
| 4000 | if (cred == NULL) { |
| 4001 | cred = nfs4_get_clid_cred(clp); |
| 4002 | if (cred == NULL) |
| 4003 | return -ENOKEY; |
| 4004 | } |
| 4005 | |
| 4006 | page = alloc_page(GFP_KERNEL); |
| 4007 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4008 | if (page == NULL || locations == NULL) |
| 4009 | goto out; |
| 4010 | |
| 4011 | status = nfs4_proc_get_locations(server, fhandle, locations, page, |
| 4012 | cred); |
| 4013 | if (status) |
| 4014 | goto out; |
Olga Kornievskaia | 4ca9f31 | 2021-12-09 14:53:35 -0500 | [diff] [blame] | 4015 | |
| 4016 | for (i = 0; i < locations->nlocations; i++) |
| 4017 | test_fs_location_for_trunking(&locations->locations[i], clp, |
| 4018 | server); |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 4019 | out: |
| 4020 | if (page) |
| 4021 | __free_page(page); |
| 4022 | kfree(locations); |
| 4023 | return status; |
| 4024 | } |
| 4025 | |
| 4026 | static int nfs4_discover_trunking(struct nfs_server *server, |
| 4027 | struct nfs_fh *fhandle) |
| 4028 | { |
| 4029 | struct nfs4_exception exception = { |
| 4030 | .interruptible = true, |
| 4031 | }; |
| 4032 | struct nfs_client *clp = server->nfs_client; |
| 4033 | int err = 0; |
| 4034 | |
| 4035 | if (!nfs4_has_session(clp)) |
| 4036 | goto out; |
| 4037 | do { |
| 4038 | err = nfs4_handle_exception(server, |
| 4039 | _nfs4_discover_trunking(server, fhandle), |
| 4040 | &exception); |
| 4041 | } while (exception.retry); |
| 4042 | out: |
| 4043 | return err; |
| 4044 | } |
| 4045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4047 | struct nfs_fsinfo *info) |
| 4048 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4049 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4051 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | }; |
| 4053 | struct nfs4_lookup_res res = { |
| 4054 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4055 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | .fh = fhandle, |
| 4057 | }; |
| 4058 | struct rpc_message msg = { |
| 4059 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 4060 | .rpc_argp = &args, |
| 4061 | .rpc_resp = &res, |
| 4062 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 4063 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4064 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 4065 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 4066 | /* |
| 4067 | * Process the label in the upcoming getfattr |
| 4068 | */ |
| 4069 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 4070 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4071 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4072 | 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] | 4073 | } |
| 4074 | |
| 4075 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4076 | struct nfs_fsinfo *info) |
| 4077 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4078 | struct nfs4_exception exception = { |
| 4079 | .interruptible = true, |
| 4080 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | int err; |
| 4082 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4083 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4084 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4085 | switch (err) { |
| 4086 | case 0: |
| 4087 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 4088 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4089 | default: |
| 4090 | err = nfs4_handle_exception(server, err, &exception); |
| 4091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 4093 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | return err; |
| 4095 | } |
| 4096 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4097 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4098 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 4099 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 4100 | struct rpc_auth_create_args auth_args = { |
| 4101 | .pseudoflavor = flavor, |
| 4102 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4103 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4104 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 4105 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 4106 | if (IS_ERR(auth)) |
| 4107 | return -EACCES; |
| 4108 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4109 | } |
| 4110 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4111 | /* |
| 4112 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 4113 | * |
| 4114 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 4115 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 4116 | * |
| 4117 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 4118 | * negative errno value. |
| 4119 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4120 | 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] | 4121 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4123 | /* Per 3530bis 15.33.5 */ |
| 4124 | static const rpc_authflavor_t flav_array[] = { |
| 4125 | RPC_AUTH_GSS_KRB5P, |
| 4126 | RPC_AUTH_GSS_KRB5I, |
| 4127 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 4128 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4129 | RPC_AUTH_NULL, |
| 4130 | }; |
| 4131 | int status = -EPERM; |
| 4132 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 4134 | if (server->auth_info.flavor_len > 0) { |
| 4135 | /* try each flavor specified by user */ |
| 4136 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 4137 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4138 | server->auth_info.flavors[i]); |
| 4139 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4140 | continue; |
| 4141 | break; |
| 4142 | } |
| 4143 | } else { |
| 4144 | /* no flavors specified by user, try default list */ |
| 4145 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 4146 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4147 | flav_array[i]); |
| 4148 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4149 | continue; |
| 4150 | break; |
| 4151 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4152 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4153 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4154 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 4155 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4156 | * to access the mount. It could also mean that we tried to mount |
| 4157 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 4158 | * existing mount programs don't handle -EACCES very well so it should |
| 4159 | * be mapped to -EPERM instead. |
| 4160 | */ |
| 4161 | if (status == -EACCES) |
| 4162 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4163 | return status; |
| 4164 | } |
| 4165 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4166 | /** |
| 4167 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 4168 | * @server: initialized nfs_server handle |
| 4169 | * @fhandle: we fill in the pseudo-fs root file handle |
| 4170 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4171 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4172 | * |
| 4173 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4174 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 4175 | 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] | 4176 | struct nfs_fsinfo *info, |
| 4177 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4178 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4179 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4180 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4181 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4182 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4183 | |
| 4184 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 4185 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 4186 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | if (status == 0) |
| 4189 | status = nfs4_server_capabilities(server, fhandle); |
| 4190 | if (status == 0) |
| 4191 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4192 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 4193 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | } |
| 4195 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4196 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 4197 | struct nfs_fsinfo *info) |
| 4198 | { |
| 4199 | int error; |
| 4200 | struct nfs_fattr *fattr = info->fattr; |
| 4201 | |
| 4202 | error = nfs4_server_capabilities(server, mntfh); |
| 4203 | if (error < 0) { |
| 4204 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 4205 | return error; |
| 4206 | } |
| 4207 | |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4208 | error = nfs4_proc_getattr(server, mntfh, fattr, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4209 | if (error < 0) { |
| 4210 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4211 | goto out; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4215 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4216 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4217 | |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4218 | out: |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4219 | return error; |
| 4220 | } |
| 4221 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4222 | /* |
| 4223 | * Get locations and (maybe) other attributes of a referral. |
| 4224 | * Note that we'll actually follow the referral later when |
| 4225 | * we detect fsid mismatch in inode revalidation |
| 4226 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4227 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4228 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4229 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4230 | { |
| 4231 | int status = -ENOMEM; |
| 4232 | struct page *page = NULL; |
| 4233 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4234 | |
| 4235 | page = alloc_page(GFP_KERNEL); |
| 4236 | if (page == NULL) |
| 4237 | goto out; |
| 4238 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4239 | if (locations == NULL) |
| 4240 | goto out; |
| 4241 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4242 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4243 | if (status != 0) |
| 4244 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4245 | |
| 4246 | /* |
| 4247 | * If the fsid didn't change, this is a migration event, not a |
| 4248 | * referral. Cause us to drop into the exception handler, which |
| 4249 | * will kick off migration recovery. |
| 4250 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4251 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4252 | dprintk("%s: server did not return a different fsid for" |
| 4253 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4254 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4255 | goto out; |
| 4256 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4257 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4258 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4259 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4260 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4261 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4262 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4263 | out: |
| 4264 | if (page) |
| 4265 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4266 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4267 | return status; |
| 4268 | } |
| 4269 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4270 | 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] | 4271 | struct nfs_fattr *fattr, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4273 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | struct nfs4_getattr_arg args = { |
| 4275 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4276 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | }; |
| 4278 | struct nfs4_getattr_res res = { |
| 4279 | .fattr = fattr, |
| 4280 | .server = server, |
| 4281 | }; |
| 4282 | struct rpc_message msg = { |
| 4283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4284 | .rpc_argp = &args, |
| 4285 | .rpc_resp = &res, |
| 4286 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4287 | unsigned short task_flags = 0; |
| 4288 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 4289 | if (nfs4_has_session(server->nfs_client)) |
| 4290 | task_flags = RPC_TASK_MOVEABLE; |
| 4291 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4292 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4293 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4294 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4295 | |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4296 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label), inode, 0); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4297 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4298 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4299 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4300 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4303 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4304 | struct nfs_fattr *fattr, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4306 | struct nfs4_exception exception = { |
| 4307 | .interruptible = true, |
| 4308 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | int err; |
| 4310 | do { |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 4311 | err = _nfs4_proc_getattr(server, fhandle, fattr, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4312 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4313 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | &exception); |
| 4315 | } while (exception.retry); |
| 4316 | return err; |
| 4317 | } |
| 4318 | |
| 4319 | /* |
| 4320 | * The file is not closed if it is opened due to the a request to change |
| 4321 | * the size of the file. The open call will not be needed once the |
| 4322 | * VFS layer lookup-intents are implemented. |
| 4323 | * |
| 4324 | * Close is called when the inode is destroyed. |
| 4325 | * If we haven't opened the file for O_WRONLY, we |
| 4326 | * need to in the size_change case to obtain a stateid. |
| 4327 | * |
| 4328 | * Got race? |
| 4329 | * Because OPEN is always done by name in nfsv4, it is |
| 4330 | * possible that we opened a different file by the same |
| 4331 | * name. We can recognize this race condition, but we |
| 4332 | * can't do anything about it besides returning an error. |
| 4333 | * |
| 4334 | * This will be fixed with VFS changes (lookup-intent). |
| 4335 | */ |
| 4336 | static int |
| 4337 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4338 | struct iattr *sattr) |
| 4339 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4340 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4341 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4342 | struct nfs_open_context *ctx = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | int status; |
| 4344 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4345 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4346 | sattr->ia_valid & ATTR_SIZE && |
| 4347 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4348 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4349 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4350 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4352 | /* Deal with open(O_TRUNC) */ |
| 4353 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4354 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4355 | |
| 4356 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4357 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4358 | return 0; |
| 4359 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4360 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4361 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4362 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4363 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4364 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4365 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4366 | } |
| 4367 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4368 | /* Return any delegations if we're going to change ACLs */ |
| 4369 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4370 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4371 | |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 4372 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4373 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4374 | nfs_setattr_update_inode(inode, sattr, fattr); |
Anna Schumaker | dd225cb | 2021-10-22 13:11:12 -0400 | [diff] [blame] | 4375 | nfs_setsecurity(inode, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | return status; |
| 4378 | } |
| 4379 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4380 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4381 | struct dentry *dentry, struct nfs_fh *fhandle, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4382 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4383 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4384 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4385 | int status; |
| 4386 | struct nfs4_lookup_arg args = { |
| 4387 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4388 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4389 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4390 | }; |
| 4391 | struct nfs4_lookup_res res = { |
| 4392 | .server = server, |
| 4393 | .fattr = fattr, |
| 4394 | .fh = fhandle, |
| 4395 | }; |
| 4396 | struct rpc_message msg = { |
| 4397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4398 | .rpc_argp = &args, |
| 4399 | .rpc_resp = &res, |
| 4400 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4401 | unsigned short task_flags = 0; |
| 4402 | |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 4403 | if (server->nfs_client->cl_minorversion) |
| 4404 | task_flags = RPC_TASK_MOVEABLE; |
| 4405 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4406 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4407 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4408 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4409 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4410 | args.bitmask = nfs4_bitmask(server, fattr->label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4411 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4412 | nfs_fattr_init(fattr); |
| 4413 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4414 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4415 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4416 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4417 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | dprintk("NFS reply lookup: %d\n", status); |
| 4419 | return status; |
| 4420 | } |
| 4421 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4422 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4423 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4424 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4425 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4426 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4427 | fattr->nlink = 2; |
| 4428 | } |
| 4429 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4430 | 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] | 4431 | struct dentry *dentry, struct nfs_fh *fhandle, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4432 | struct nfs_fattr *fattr) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4433 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4434 | struct nfs4_exception exception = { |
| 4435 | .interruptible = true, |
| 4436 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4437 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4438 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4439 | int err; |
| 4440 | do { |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4441 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4442 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4443 | switch (err) { |
| 4444 | case -NFS4ERR_BADNAME: |
| 4445 | err = -ENOENT; |
| 4446 | goto out; |
| 4447 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4448 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4449 | if (err == -NFS4ERR_MOVED) |
| 4450 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4451 | goto out; |
| 4452 | case -NFS4ERR_WRONGSEC: |
| 4453 | err = -EPERM; |
| 4454 | if (client != *clnt) |
| 4455 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4456 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4457 | if (IS_ERR(client)) |
| 4458 | return PTR_ERR(client); |
| 4459 | |
| 4460 | exception.retry = 1; |
| 4461 | break; |
| 4462 | default: |
| 4463 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4464 | } |
| 4465 | } while (exception.retry); |
| 4466 | |
| 4467 | out: |
| 4468 | if (err == 0) |
| 4469 | *clnt = client; |
| 4470 | else if (client != *clnt) |
| 4471 | rpc_shutdown_client(client); |
| 4472 | |
| 4473 | return err; |
| 4474 | } |
| 4475 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4476 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4477 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4479 | int status; |
| 4480 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4481 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4482 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4483 | if (client != NFS_CLIENT(dir)) { |
| 4484 | rpc_shutdown_client(client); |
| 4485 | nfs_fixup_secinfo_attributes(fattr); |
| 4486 | } |
| 4487 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | } |
| 4489 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4490 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4491 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4492 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4493 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4494 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4495 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4496 | |
Anna Schumaker | 9558a00 | 2021-10-22 13:11:04 -0400 | [diff] [blame] | 4497 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4498 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4499 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4500 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4501 | } |
| 4502 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4503 | static int _nfs4_proc_lookupp(struct inode *inode, |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4504 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4505 | { |
| 4506 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4507 | struct nfs_server *server = NFS_SERVER(inode); |
| 4508 | int status; |
| 4509 | struct nfs4_lookupp_arg args = { |
| 4510 | .bitmask = server->attr_bitmask, |
| 4511 | .fh = NFS_FH(inode), |
| 4512 | }; |
| 4513 | struct nfs4_lookupp_res res = { |
| 4514 | .server = server, |
| 4515 | .fattr = fattr, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4516 | .fh = fhandle, |
| 4517 | }; |
| 4518 | struct rpc_message msg = { |
| 4519 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4520 | .rpc_argp = &args, |
| 4521 | .rpc_resp = &res, |
| 4522 | }; |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4523 | unsigned short task_flags = 0; |
| 4524 | |
| 4525 | if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL) |
| 4526 | task_flags |= RPC_TASK_TIMEOUT; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4527 | |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4528 | args.bitmask = nfs4_bitmask(server, fattr->label); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4529 | |
| 4530 | nfs_fattr_init(fattr); |
| 4531 | |
| 4532 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4533 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4534 | &res.seq_res, task_flags); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4535 | dprintk("NFS reply lookupp: %d\n", status); |
| 4536 | return status; |
| 4537 | } |
| 4538 | |
| 4539 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4540 | struct nfs_fattr *fattr) |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4541 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4542 | struct nfs4_exception exception = { |
| 4543 | .interruptible = true, |
| 4544 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4545 | int err; |
| 4546 | do { |
Anna Schumaker | ba4bc8d | 2021-10-22 13:11:05 -0400 | [diff] [blame] | 4547 | err = _nfs4_proc_lookupp(inode, fhandle, fattr); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4548 | trace_nfs4_lookupp(inode, err); |
| 4549 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4550 | &exception); |
| 4551 | } while (exception.retry); |
| 4552 | return err; |
| 4553 | } |
| 4554 | |
NeilBrown | 73fbb3f | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 4555 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry, |
| 4556 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4558 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | struct nfs4_accessargs args = { |
| 4560 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4561 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4563 | struct nfs4_accessres res = { |
| 4564 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4565 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | struct rpc_message msg = { |
| 4567 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4568 | .rpc_argp = &args, |
| 4569 | .rpc_resp = &res, |
NeilBrown | 73fbb3f | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 4570 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4572 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4574 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4575 | res.fattr = nfs_alloc_fattr(); |
| 4576 | if (res.fattr == NULL) |
| 4577 | return -ENOMEM; |
| 4578 | args.bitmask = server->cache_consistency_bitmask; |
| 4579 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4580 | 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] | 4581 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4582 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4583 | if (res.fattr) |
| 4584 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4586 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | return status; |
| 4588 | } |
| 4589 | |
NeilBrown | 73fbb3f | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 4590 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry, |
| 4591 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4593 | struct nfs4_exception exception = { |
| 4594 | .interruptible = true, |
| 4595 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | int err; |
| 4597 | do { |
NeilBrown | 73fbb3f | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 4598 | err = _nfs4_proc_access(inode, entry, cred); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4599 | trace_nfs4_access(inode, err); |
| 4600 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | &exception); |
| 4602 | } while (exception.retry); |
| 4603 | return err; |
| 4604 | } |
| 4605 | |
| 4606 | /* |
| 4607 | * TODO: For the time being, we don't try to get any attributes |
| 4608 | * along with any of the zero-copy operations READ, READDIR, |
| 4609 | * READLINK, WRITE. |
| 4610 | * |
| 4611 | * In the case of the first three, we want to put the GETATTR |
| 4612 | * after the read-type operation -- this is because it is hard |
| 4613 | * to predict the length of a GETATTR response in v4, and thus |
| 4614 | * align the READ data correctly. This means that the GETATTR |
| 4615 | * may end up partially falling into the page cache, and we should |
| 4616 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4617 | * To do this efficiently, we need to know the total length |
| 4618 | * of data received, which doesn't seem to be available outside |
| 4619 | * of the RPC layer. |
| 4620 | * |
| 4621 | * In the case of WRITE, we also want to put the GETATTR after |
| 4622 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4623 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | * |
| 4625 | * Both of these changes to the XDR layer would in fact be quite |
| 4626 | * minor, but I decided to leave them for a subsequent patch. |
| 4627 | */ |
| 4628 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4629 | unsigned int pgbase, unsigned int pglen) |
| 4630 | { |
| 4631 | struct nfs4_readlink args = { |
| 4632 | .fh = NFS_FH(inode), |
| 4633 | .pgbase = pgbase, |
| 4634 | .pglen = pglen, |
| 4635 | .pages = &page, |
| 4636 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4637 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | struct rpc_message msg = { |
| 4639 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4640 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4641 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | }; |
| 4643 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4644 | 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] | 4645 | } |
| 4646 | |
| 4647 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4648 | unsigned int pgbase, unsigned int pglen) |
| 4649 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4650 | struct nfs4_exception exception = { |
| 4651 | .interruptible = true, |
| 4652 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | int err; |
| 4654 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4655 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4656 | trace_nfs4_readlink(inode, err); |
| 4657 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | &exception); |
| 4659 | } while (exception.retry); |
| 4660 | return err; |
| 4661 | } |
| 4662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4664 | * 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] | 4665 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | static int |
| 4667 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4668 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4670 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4671 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4672 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | int status = 0; |
| 4675 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4676 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4677 | if (IS_ERR(ctx)) |
| 4678 | return PTR_ERR(ctx); |
| 4679 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4680 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4681 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4682 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4683 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4684 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | if (IS_ERR(state)) { |
| 4686 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4687 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4690 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4691 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | return status; |
| 4693 | } |
| 4694 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4695 | static int |
| 4696 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4698 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4699 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4701 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4702 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4703 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4704 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4705 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4707 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4708 | .rpc_argp = &args, |
| 4709 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4711 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4712 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4713 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4714 | 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] | 4715 | if (status == 0) { |
| 4716 | spin_lock(&dir->i_lock); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4717 | /* Removing a directory decrements nlink in the parent */ |
| 4718 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4719 | nfs4_dec_nlink_locked(dir); |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 4720 | nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, |
| 4721 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4722 | spin_unlock(&dir->i_lock); |
| 4723 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | return status; |
| 4725 | } |
| 4726 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4727 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4728 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4729 | struct nfs4_exception exception = { |
| 4730 | .interruptible = true, |
| 4731 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4732 | struct inode *inode = d_inode(dentry); |
| 4733 | int err; |
| 4734 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4735 | if (inode) { |
| 4736 | if (inode->i_nlink == 1) |
| 4737 | nfs4_inode_return_delegation(inode); |
| 4738 | else |
| 4739 | nfs4_inode_make_writeable(inode); |
| 4740 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4741 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4742 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4743 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4744 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4745 | &exception); |
| 4746 | } while (exception.retry); |
| 4747 | return err; |
| 4748 | } |
| 4749 | |
| 4750 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4752 | struct nfs4_exception exception = { |
| 4753 | .interruptible = true, |
| 4754 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4758 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4759 | trace_nfs4_remove(dir, name, err); |
| 4760 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | &exception); |
| 4762 | } while (exception.retry); |
| 4763 | return err; |
| 4764 | } |
| 4765 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4766 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4767 | struct dentry *dentry, |
| 4768 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4770 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4771 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4772 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4773 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4775 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4776 | |
| 4777 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4778 | |
Trond Myklebust | 00bdadc | 2021-12-17 15:36:57 -0500 | [diff] [blame] | 4779 | if (inode) { |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4780 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 00bdadc | 2021-12-17 15:36:57 -0500 | [diff] [blame] | 4781 | nfs_d_prune_case_insensitive_aliases(inode); |
| 4782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | } |
| 4784 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4785 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4786 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4787 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4788 | &data->args.seq_args, |
| 4789 | &data->res.seq_res, |
| 4790 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | } |
| 4792 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4793 | 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] | 4794 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4795 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4796 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4797 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4798 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4799 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4800 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4801 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4802 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4803 | if (task->tk_status == 0) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4804 | nfs4_update_changeattr(dir, &res->cinfo, |
| 4805 | res->dir_attr->time_start, |
| 4806 | NFS_INO_INVALID_DATA); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4807 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | } |
| 4809 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4810 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4811 | struct dentry *old_dentry, |
| 4812 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4813 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4814 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4815 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4816 | struct inode *old_inode = d_inode(old_dentry); |
| 4817 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4818 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4819 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4820 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4821 | if (new_inode) |
| 4822 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4823 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4824 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4825 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4826 | } |
| 4827 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4828 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4829 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4830 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4831 | &data->args.seq_args, |
| 4832 | &data->res.seq_res, |
| 4833 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4837 | struct inode *new_dir) |
| 4838 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4839 | struct nfs_renamedata *data = task->tk_calldata; |
| 4840 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4841 | |
| 4842 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4843 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4844 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4845 | return 0; |
| 4846 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4847 | if (task->tk_status == 0) { |
Trond Myklebust | 00bdadc | 2021-12-17 15:36:57 -0500 | [diff] [blame] | 4848 | nfs_d_prune_case_insensitive_aliases(d_inode(data->old_dentry)); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4849 | if (new_dir != old_dir) { |
| 4850 | /* Note: If we moved a directory, nlink will change */ |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4851 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4852 | res->old_fattr->time_start, |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 4853 | NFS_INO_INVALID_NLINK | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4854 | NFS_INO_INVALID_DATA); |
| 4855 | nfs4_update_changeattr(new_dir, &res->new_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4856 | res->new_fattr->time_start, |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 4857 | NFS_INO_INVALID_NLINK | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4858 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4859 | } else |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4860 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4861 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4862 | NFS_INO_INVALID_DATA); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4863 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4864 | return 1; |
| 4865 | } |
| 4866 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4867 | 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] | 4868 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4869 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4870 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | struct nfs4_link_arg arg = { |
| 4872 | .fh = NFS_FH(inode), |
| 4873 | .dir_fh = NFS_FH(dir), |
| 4874 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4875 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4877 | struct nfs4_link_res res = { |
| 4878 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4879 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | struct rpc_message msg = { |
| 4881 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4882 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4883 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4885 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | |
Anna Schumaker | aa7ca3b | 2021-10-22 13:11:03 -0400 | [diff] [blame] | 4887 | res.fattr = nfs_alloc_fattr_with_label(server); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4888 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4889 | goto out; |
| 4890 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4891 | nfs4_inode_make_writeable(inode); |
Anna Schumaker | aa7ca3b | 2021-10-22 13:11:03 -0400 | [diff] [blame] | 4892 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, res.fattr->label), inode, |
Trond Myklebust | a71029b | 2021-04-10 00:23:03 -0400 | [diff] [blame] | 4893 | NFS_INO_INVALID_CHANGE); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4894 | 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] | 4895 | if (!status) { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4896 | nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, |
| 4897 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 1301e42 | 2021-04-01 14:57:56 -0400 | [diff] [blame] | 4898 | nfs4_inc_nlink(inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4899 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4900 | if (!status) |
Anna Schumaker | dd225cb | 2021-10-22 13:11:12 -0400 | [diff] [blame] | 4901 | nfs_setsecurity(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4902 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4903 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4904 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4905 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | return status; |
| 4907 | } |
| 4908 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4909 | 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] | 4910 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4911 | struct nfs4_exception exception = { |
| 4912 | .interruptible = true, |
| 4913 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | int err; |
| 4915 | do { |
| 4916 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4917 | _nfs4_proc_link(inode, dir, name), |
| 4918 | &exception); |
| 4919 | } while (exception.retry); |
| 4920 | return err; |
| 4921 | } |
| 4922 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4923 | struct nfs4_createdata { |
| 4924 | struct rpc_message msg; |
| 4925 | struct nfs4_create_arg arg; |
| 4926 | struct nfs4_create_res res; |
| 4927 | struct nfs_fh fh; |
| 4928 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4929 | }; |
| 4930 | |
| 4931 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4932 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4933 | { |
| 4934 | struct nfs4_createdata *data; |
| 4935 | |
| 4936 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4937 | if (data != NULL) { |
| 4938 | struct nfs_server *server = NFS_SERVER(dir); |
| 4939 | |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4940 | data->fattr.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4941 | if (IS_ERR(data->fattr.label)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4942 | goto out_free; |
| 4943 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4944 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4945 | data->msg.rpc_argp = &data->arg; |
| 4946 | data->msg.rpc_resp = &data->res; |
| 4947 | data->arg.dir_fh = NFS_FH(dir); |
| 4948 | data->arg.server = server; |
| 4949 | data->arg.name = name; |
| 4950 | data->arg.attrs = sattr; |
| 4951 | data->arg.ftype = ftype; |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4952 | data->arg.bitmask = nfs4_bitmask(server, data->fattr.label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4953 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4954 | data->res.server = server; |
| 4955 | data->res.fh = &data->fh; |
| 4956 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4957 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4958 | } |
| 4959 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4960 | out_free: |
| 4961 | kfree(data); |
| 4962 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4963 | } |
| 4964 | |
| 4965 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4966 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4967 | 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] | 4968 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4969 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4970 | spin_lock(&dir->i_lock); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4971 | /* Creating a directory bumps nlink in the parent */ |
| 4972 | if (data->arg.ftype == NF4DIR) |
| 4973 | nfs4_inc_nlink_locked(dir); |
Trond Myklebust | 82eae5a | 2021-04-01 14:59:59 -0400 | [diff] [blame] | 4974 | nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, |
| 4975 | data->res.fattr->time_start, |
| 4976 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4977 | spin_unlock(&dir->i_lock); |
Anna Schumaker | d91bfc4 | 2021-10-22 13:11:09 -0400 | [diff] [blame] | 4978 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4979 | } |
| 4980 | return status; |
| 4981 | } |
| 4982 | |
| 4983 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4984 | { |
Anna Schumaker | 68be174 | 2021-10-22 13:11:02 -0400 | [diff] [blame] | 4985 | nfs4_label_free(data->fattr.label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4986 | kfree(data); |
| 4987 | } |
| 4988 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4989 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4990 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4991 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4993 | struct nfs4_createdata *data; |
| 4994 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4996 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4997 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4998 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4999 | status = -ENOMEM; |
| 5000 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 5001 | if (data == NULL) |
| 5002 | goto out; |
| 5003 | |
| 5004 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 5005 | data->arg.u.symlink.pages = &page; |
| 5006 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5007 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5009 | status = nfs4_do_create(dir, dentry, data); |
| 5010 | |
| 5011 | nfs4_free_createdata(data); |
| 5012 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | return status; |
| 5014 | } |
| 5015 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 5016 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 5017 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5018 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5019 | struct nfs4_exception exception = { |
| 5020 | .interruptible = true, |
| 5021 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5022 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5024 | |
| 5025 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5028 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 5029 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 5030 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | &exception); |
| 5032 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5033 | |
| 5034 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | return err; |
| 5036 | } |
| 5037 | |
| 5038 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5039 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5041 | struct nfs4_createdata *data; |
| 5042 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5044 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 5045 | if (data == NULL) |
| 5046 | goto out; |
| 5047 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5048 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5049 | status = nfs4_do_create(dir, dentry, data); |
| 5050 | |
| 5051 | nfs4_free_createdata(data); |
| 5052 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | return status; |
| 5054 | } |
| 5055 | |
| 5056 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 5057 | struct iattr *sattr) |
| 5058 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5059 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5060 | struct nfs4_exception exception = { |
| 5061 | .interruptible = true, |
| 5062 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5063 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 5065 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5066 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5067 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5068 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 5069 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5071 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 5072 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 5073 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | &exception); |
| 5075 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5076 | nfs4_label_release_security(label); |
| 5077 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5078 | return err; |
| 5079 | } |
| 5080 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5081 | static int _nfs4_proc_readdir(struct nfs_readdir_arg *nr_arg, |
| 5082 | struct nfs_readdir_res *nr_res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5084 | struct inode *dir = d_inode(nr_arg->dentry); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 5085 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | struct nfs4_readdir_arg args = { |
| 5087 | .fh = NFS_FH(dir), |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5088 | .pages = nr_arg->pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | .pgbase = 0, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5090 | .count = nr_arg->page_len, |
| 5091 | .plus = nr_arg->plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | }; |
| 5093 | struct nfs4_readdir_res res; |
| 5094 | struct rpc_message msg = { |
| 5095 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 5096 | .rpc_argp = &args, |
| 5097 | .rpc_resp = &res, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5098 | .rpc_cred = nr_arg->cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | }; |
| 5100 | int status; |
| 5101 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5102 | dprintk("%s: dentry = %pd2, cookie = %llu\n", __func__, |
| 5103 | nr_arg->dentry, (unsigned long long)nr_arg->cookie); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 5104 | if (!(server->caps & NFS_CAP_SECURITY_LABEL)) |
| 5105 | args.bitmask = server->attr_bitmask_nl; |
| 5106 | else |
| 5107 | args.bitmask = server->attr_bitmask; |
| 5108 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5109 | 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] | 5110 | res.pgbase = args.pgbase; |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 5111 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 5112 | &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 5113 | if (status >= 0) { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5114 | memcpy(nr_res->verf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 5115 | status += args.pgbase; |
| 5116 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 5117 | |
| 5118 | nfs_invalidate_atime(dir); |
| 5119 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5120 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5121 | return status; |
| 5122 | } |
| 5123 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5124 | static int nfs4_proc_readdir(struct nfs_readdir_arg *arg, |
| 5125 | struct nfs_readdir_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5126 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5127 | struct nfs4_exception exception = { |
| 5128 | .interruptible = true, |
| 5129 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | int err; |
| 5131 | do { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5132 | err = _nfs4_proc_readdir(arg, res); |
| 5133 | trace_nfs4_readdir(d_inode(arg->dentry), err); |
| 5134 | err = nfs4_handle_exception(NFS_SERVER(d_inode(arg->dentry)), |
| 5135 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5136 | } while (exception.retry); |
| 5137 | return err; |
| 5138 | } |
| 5139 | |
| 5140 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5141 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5143 | struct nfs4_createdata *data; |
| 5144 | int mode = sattr->ia_mode; |
| 5145 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5147 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 5148 | if (data == NULL) |
| 5149 | goto out; |
| 5150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5152 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5154 | data->arg.ftype = NF4BLK; |
| 5155 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5156 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | } |
| 5158 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5159 | data->arg.ftype = NF4CHR; |
| 5160 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5161 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5162 | } else if (!S_ISSOCK(mode)) { |
| 5163 | status = -EINVAL; |
| 5164 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5166 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5167 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5168 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5169 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5170 | nfs4_free_createdata(data); |
| 5171 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | return status; |
| 5173 | } |
| 5174 | |
| 5175 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 5176 | struct iattr *sattr, dev_t rdev) |
| 5177 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5178 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5179 | struct nfs4_exception exception = { |
| 5180 | .interruptible = true, |
| 5181 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5182 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 5184 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5185 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5186 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5187 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 5188 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5190 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 5191 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 5192 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 | &exception); |
| 5194 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5195 | |
| 5196 | nfs4_label_release_security(label); |
| 5197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | return err; |
| 5199 | } |
| 5200 | |
| 5201 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5202 | struct nfs_fsstat *fsstat) |
| 5203 | { |
| 5204 | struct nfs4_statfs_arg args = { |
| 5205 | .fh = fhandle, |
| 5206 | .bitmask = server->attr_bitmask, |
| 5207 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5208 | struct nfs4_statfs_res res = { |
| 5209 | .fsstat = fsstat, |
| 5210 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5211 | struct rpc_message msg = { |
| 5212 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5213 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5214 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | }; |
| 5216 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5217 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5218 | 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] | 5219 | } |
| 5220 | |
| 5221 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5222 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5223 | struct nfs4_exception exception = { |
| 5224 | .interruptible = true, |
| 5225 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | int err; |
| 5227 | do { |
| 5228 | err = nfs4_handle_exception(server, |
| 5229 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5230 | &exception); |
| 5231 | } while (exception.retry); |
| 5232 | return err; |
| 5233 | } |
| 5234 | |
| 5235 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5236 | struct nfs_fsinfo *fsinfo) |
| 5237 | { |
| 5238 | struct nfs4_fsinfo_arg args = { |
| 5239 | .fh = fhandle, |
| 5240 | .bitmask = server->attr_bitmask, |
| 5241 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5242 | struct nfs4_fsinfo_res res = { |
| 5243 | .fsinfo = fsinfo, |
| 5244 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5245 | struct rpc_message msg = { |
| 5246 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5247 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5248 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5249 | }; |
| 5250 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5251 | 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] | 5252 | } |
| 5253 | |
| 5254 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5255 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5256 | struct nfs4_exception exception = { |
| 5257 | .interruptible = true, |
| 5258 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5259 | int err; |
| 5260 | |
| 5261 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5262 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5263 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5264 | if (err == 0) { |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 5265 | nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5266 | break; |
| 5267 | } |
| 5268 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | } while (exception.retry); |
| 5270 | return err; |
| 5271 | } |
| 5272 | |
| 5273 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5274 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5275 | int error; |
| 5276 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5277 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5278 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5279 | if (error == 0) { |
| 5280 | /* block layout checks this! */ |
| 5281 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5282 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5283 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5284 | |
| 5285 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5289 | struct nfs_pathconf *pathconf) |
| 5290 | { |
| 5291 | struct nfs4_pathconf_arg args = { |
| 5292 | .fh = fhandle, |
| 5293 | .bitmask = server->attr_bitmask, |
| 5294 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5295 | struct nfs4_pathconf_res res = { |
| 5296 | .pathconf = pathconf, |
| 5297 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | struct rpc_message msg = { |
| 5299 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5300 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5301 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | }; |
| 5303 | |
| 5304 | /* None of the pathconf attributes are mandatory to implement */ |
| 5305 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5306 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5307 | return 0; |
| 5308 | } |
| 5309 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5310 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5311 | 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] | 5312 | } |
| 5313 | |
| 5314 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5315 | struct nfs_pathconf *pathconf) |
| 5316 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5317 | struct nfs4_exception exception = { |
| 5318 | .interruptible = true, |
| 5319 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | int err; |
| 5321 | |
| 5322 | do { |
| 5323 | err = nfs4_handle_exception(server, |
| 5324 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5325 | &exception); |
| 5326 | } while (exception.retry); |
| 5327 | return err; |
| 5328 | } |
| 5329 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5330 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5331 | const struct nfs_open_context *ctx, |
| 5332 | const struct nfs_lock_context *l_ctx, |
| 5333 | fmode_t fmode) |
| 5334 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5335 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5336 | } |
| 5337 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5338 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5339 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5340 | const struct nfs_open_context *ctx, |
| 5341 | const struct nfs_lock_context *l_ctx, |
| 5342 | fmode_t fmode) |
| 5343 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5344 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5345 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5346 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5347 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5348 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5349 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | static bool nfs4_error_stateid_expired(int err) |
| 5353 | { |
| 5354 | switch (err) { |
| 5355 | case -NFS4ERR_DELEG_REVOKED: |
| 5356 | case -NFS4ERR_ADMIN_REVOKED: |
| 5357 | case -NFS4ERR_BAD_STATEID: |
| 5358 | case -NFS4ERR_STALE_STATEID: |
| 5359 | case -NFS4ERR_OLD_STATEID: |
| 5360 | case -NFS4ERR_OPENMODE: |
| 5361 | case -NFS4ERR_EXPIRED: |
| 5362 | return true; |
| 5363 | } |
| 5364 | return false; |
| 5365 | } |
| 5366 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5367 | 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] | 5368 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5369 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5371 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5372 | if (task->tk_status < 0) { |
| 5373 | struct nfs4_exception exception = { |
| 5374 | .inode = hdr->inode, |
| 5375 | .state = hdr->args.context->state, |
| 5376 | .stateid = &hdr->args.stateid, |
| 5377 | }; |
| 5378 | task->tk_status = nfs4_async_handle_exception(task, |
| 5379 | server, task->tk_status, &exception); |
| 5380 | if (exception.retry) { |
| 5381 | rpc_restart_call_prepare(task); |
| 5382 | return -EAGAIN; |
| 5383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5384 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5387 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5388 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5389 | } |
| 5390 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5391 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5392 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5393 | { |
| 5394 | |
| 5395 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5396 | nfs4_stateid_is_current(&args->stateid, |
| 5397 | args->context, |
| 5398 | args->lock_context, |
| 5399 | FMODE_READ)) |
| 5400 | return false; |
| 5401 | rpc_restart_call_prepare(task); |
| 5402 | return true; |
| 5403 | } |
| 5404 | |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5405 | static bool nfs4_read_plus_not_supported(struct rpc_task *task, |
| 5406 | struct nfs_pgio_header *hdr) |
| 5407 | { |
| 5408 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
| 5409 | struct rpc_message *msg = &task->tk_msg; |
| 5410 | |
| 5411 | if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS] && |
| 5412 | server->caps & NFS_CAP_READ_PLUS && task->tk_status == -ENOTSUPP) { |
| 5413 | server->caps &= ~NFS_CAP_READ_PLUS; |
| 5414 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5415 | rpc_restart_call_prepare(task); |
| 5416 | return true; |
| 5417 | } |
| 5418 | return false; |
| 5419 | } |
| 5420 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5421 | 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] | 5422 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5423 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5424 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5425 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5426 | return -EAGAIN; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5427 | if (nfs4_read_plus_not_supported(task, hdr)) |
| 5428 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5429 | if (task->tk_status > 0) |
| 5430 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5431 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5432 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5433 | } |
| 5434 | |
Anna Schumaker | 21e3140 | 2020-12-03 15:18:39 -0500 | [diff] [blame] | 5435 | #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] | 5436 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5437 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5438 | { |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5439 | /* Note: We don't use READ_PLUS with pNFS yet */ |
| 5440 | 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] | 5441 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS]; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5442 | } |
| 5443 | #else |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5444 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5445 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5446 | { |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5447 | } |
| 5448 | #endif /* CONFIG_NFS_V4_2 */ |
| 5449 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5450 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5451 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5453 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5454 | if (!hdr->pgio_done_cb) |
| 5455 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5456 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5457 | nfs42_read_plus_support(hdr, msg); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5458 | 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] | 5459 | } |
| 5460 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5461 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5462 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5463 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5464 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5465 | &hdr->args.seq_args, |
| 5466 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5467 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5468 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5469 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5470 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5471 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5472 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5473 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5474 | return -EIO; |
| 5475 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5476 | } |
| 5477 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5478 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5479 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5481 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5482 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5483 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5484 | if (task->tk_status < 0) { |
| 5485 | struct nfs4_exception exception = { |
| 5486 | .inode = hdr->inode, |
| 5487 | .state = hdr->args.context->state, |
| 5488 | .stateid = &hdr->args.stateid, |
| 5489 | }; |
| 5490 | task->tk_status = nfs4_async_handle_exception(task, |
| 5491 | NFS_SERVER(inode), task->tk_status, |
| 5492 | &exception); |
| 5493 | if (exception.retry) { |
| 5494 | rpc_restart_call_prepare(task); |
| 5495 | return -EAGAIN; |
| 5496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5498 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5499 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5500 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5501 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5502 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | } |
| 5504 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5505 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5506 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5507 | { |
| 5508 | |
| 5509 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5510 | nfs4_stateid_is_current(&args->stateid, |
| 5511 | args->context, |
| 5512 | args->lock_context, |
| 5513 | FMODE_WRITE)) |
| 5514 | return false; |
| 5515 | rpc_restart_call_prepare(task); |
| 5516 | return true; |
| 5517 | } |
| 5518 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5519 | 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] | 5520 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5521 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5522 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5523 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5524 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5525 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5526 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5527 | } |
| 5528 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5529 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5530 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5531 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5532 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5533 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5534 | return false; |
| 5535 | /* Otherwise, request attributes if and only if we don't hold |
| 5536 | * a delegation |
| 5537 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5538 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5539 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5540 | |
Trond Myklebust | 8584728 | 2021-12-27 14:40:51 -0500 | [diff] [blame] | 5541 | void nfs4_bitmask_set(__u32 bitmask[], const __u32 src[], |
| 5542 | struct inode *inode, unsigned long cache_validity) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5543 | { |
Trond Myklebust | 8584728 | 2021-12-27 14:40:51 -0500 | [diff] [blame] | 5544 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5545 | unsigned int i; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5546 | |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5547 | memcpy(bitmask, src, sizeof(*bitmask) * NFS4_BITMASK_SZ); |
Trond Myklebust | 8584728 | 2021-12-27 14:40:51 -0500 | [diff] [blame] | 5548 | cache_validity |= READ_ONCE(NFS_I(inode)->cache_validity); |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5549 | |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5550 | if (cache_validity & NFS_INO_INVALID_CHANGE) |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5551 | bitmask[0] |= FATTR4_WORD0_CHANGE; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5552 | if (cache_validity & NFS_INO_INVALID_ATIME) |
| 5553 | bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 5554 | if (cache_validity & NFS_INO_INVALID_MODE) |
| 5555 | bitmask[1] |= FATTR4_WORD1_MODE; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5556 | if (cache_validity & NFS_INO_INVALID_OTHER) |
Trond Myklebust | 720869e | 2021-04-13 09:41:16 -0400 | [diff] [blame] | 5557 | bitmask[1] |= FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP; |
Trond Myklebust | fabf2b3 | 2021-03-25 13:14:42 -0400 | [diff] [blame] | 5558 | if (cache_validity & NFS_INO_INVALID_NLINK) |
| 5559 | bitmask[1] |= FATTR4_WORD1_NUMLINKS; |
Trond Myklebust | 45901a2 | 2021-02-08 08:49:32 -0500 | [diff] [blame] | 5560 | if (cache_validity & NFS_INO_INVALID_CTIME) |
| 5561 | bitmask[1] |= FATTR4_WORD1_TIME_METADATA; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5562 | if (cache_validity & NFS_INO_INVALID_MTIME) |
| 5563 | bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5564 | if (cache_validity & NFS_INO_INVALID_BLOCKS) |
| 5565 | bitmask[1] |= FATTR4_WORD1_SPACE_USED; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5566 | |
Trond Myklebust | cc7f2da | 2021-04-11 14:31:24 -0400 | [diff] [blame] | 5567 | if (cache_validity & NFS_INO_INVALID_SIZE) |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5568 | bitmask[0] |= FATTR4_WORD0_SIZE; |
| 5569 | |
| 5570 | for (i = 0; i < NFS4_BITMASK_SZ; i++) |
| 5571 | bitmask[i] &= server->attr_bitmask[i]; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5572 | } |
| 5573 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5574 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5575 | struct rpc_message *msg, |
| 5576 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5578 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5579 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5580 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5581 | hdr->args.bitmask = NULL; |
| 5582 | hdr->res.fattr = NULL; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5583 | } else { |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5584 | nfs4_bitmask_set(hdr->args.bitmask_store, |
| 5585 | server->cache_consistency_bitmask, |
Trond Myklebust | 8584728 | 2021-12-27 14:40:51 -0500 | [diff] [blame] | 5586 | hdr->inode, NFS_INO_INVALID_BLOCKS); |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 5587 | hdr->args.bitmask = hdr->args.bitmask_store; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5588 | } |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5589 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5590 | if (!hdr->pgio_done_cb) |
| 5591 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5592 | hdr->res.server = server; |
| 5593 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5594 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5595 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Olga Kornievskaia | cd1b659 | 2020-02-12 17:32:12 -0500 | [diff] [blame] | 5596 | 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] | 5597 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | } |
| 5599 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5600 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5601 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5602 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5603 | &data->args.seq_args, |
| 5604 | &data->res.seq_res, |
| 5605 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | } |
| 5607 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5608 | 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] | 5609 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5611 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5612 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5613 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5614 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5615 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5616 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5618 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | } |
| 5620 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5621 | 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] | 5622 | { |
| 5623 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5624 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5625 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5628 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5629 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5631 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5632 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5633 | if (data->commit_done_cb == NULL) |
| 5634 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5635 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5636 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5637 | 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] | 5638 | 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] | 5639 | } |
| 5640 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5641 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5642 | struct nfs_commitres *res) |
| 5643 | { |
| 5644 | struct inode *dst_inode = file_inode(dst); |
| 5645 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5646 | struct rpc_message msg = { |
| 5647 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5648 | .rpc_argp = args, |
| 5649 | .rpc_resp = res, |
| 5650 | }; |
| 5651 | |
| 5652 | args->fh = NFS_FH(dst_inode); |
| 5653 | return nfs4_call_sync(server->client, server, &msg, |
| 5654 | &args->seq_args, &res->seq_res, 1); |
| 5655 | } |
| 5656 | |
| 5657 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5658 | { |
| 5659 | struct nfs_commitargs args = { |
| 5660 | .offset = offset, |
| 5661 | .count = count, |
| 5662 | }; |
| 5663 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5664 | struct nfs4_exception exception = { }; |
| 5665 | int status; |
| 5666 | |
| 5667 | do { |
| 5668 | status = _nfs4_proc_commit(dst, &args, res); |
| 5669 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5670 | } while (exception.retry); |
| 5671 | |
| 5672 | return status; |
| 5673 | } |
| 5674 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5675 | struct nfs4_renewdata { |
| 5676 | struct nfs_client *client; |
| 5677 | unsigned long timestamp; |
| 5678 | }; |
| 5679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5680 | /* |
| 5681 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5682 | * standalone procedure for queueing an asynchronous RENEW. |
| 5683 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5684 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5685 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5686 | struct nfs4_renewdata *data = calldata; |
| 5687 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5688 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5689 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5690 | nfs4_schedule_state_renewal(clp); |
| 5691 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5692 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5693 | } |
| 5694 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5695 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5697 | struct nfs4_renewdata *data = calldata; |
| 5698 | struct nfs_client *clp = data->client; |
| 5699 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5701 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5702 | switch (task->tk_status) { |
| 5703 | case 0: |
| 5704 | break; |
| 5705 | case -NFS4ERR_LEASE_MOVED: |
| 5706 | nfs4_schedule_lease_moved_recovery(clp); |
| 5707 | break; |
| 5708 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5709 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5710 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5711 | return; |
| 5712 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5713 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5714 | return; |
| 5715 | } |
| 5716 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5718 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | } |
| 5720 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5721 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5722 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5723 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5724 | }; |
| 5725 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5726 | 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] | 5727 | { |
| 5728 | struct rpc_message msg = { |
| 5729 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5730 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5731 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5733 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5734 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5735 | if (renew_flags == 0) |
| 5736 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5737 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5738 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5739 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5740 | if (data == NULL) { |
| 5741 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5742 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5743 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5744 | data->client = clp; |
| 5745 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5746 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5747 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5748 | } |
| 5749 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5750 | 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] | 5751 | { |
| 5752 | struct rpc_message msg = { |
| 5753 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5754 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5755 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5756 | }; |
| 5757 | unsigned long now = jiffies; |
| 5758 | int status; |
| 5759 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5760 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5761 | if (status < 0) |
| 5762 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5763 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | return 0; |
| 5765 | } |
| 5766 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5767 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5768 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5769 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5770 | } |
| 5771 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5772 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5773 | * 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] | 5774 | * the stack. |
| 5775 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5776 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5777 | |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5778 | int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5779 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5780 | { |
| 5781 | struct page *newpage, **spages; |
| 5782 | int rc = 0; |
| 5783 | size_t len; |
| 5784 | spages = pages; |
| 5785 | |
| 5786 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5787 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5788 | newpage = alloc_page(GFP_KERNEL); |
| 5789 | |
| 5790 | if (newpage == NULL) |
| 5791 | goto unwind; |
| 5792 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5793 | buf += len; |
| 5794 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5795 | *pages++ = newpage; |
| 5796 | rc++; |
| 5797 | } while (buflen != 0); |
| 5798 | |
| 5799 | return rc; |
| 5800 | |
| 5801 | unwind: |
| 5802 | for(; rc > 0; rc--) |
| 5803 | __free_page(spages[rc-1]); |
| 5804 | return -ENOMEM; |
| 5805 | } |
| 5806 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5807 | struct nfs4_cached_acl { |
| 5808 | int cached; |
| 5809 | size_t len; |
Gustavo A. R. Silva | 5601cda | 2020-03-09 13:24:42 -0500 | [diff] [blame] | 5810 | char data[]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5811 | }; |
| 5812 | |
| 5813 | 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] | 5814 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5815 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5816 | |
| 5817 | spin_lock(&inode->i_lock); |
| 5818 | kfree(nfsi->nfs4_acl); |
| 5819 | nfsi->nfs4_acl = acl; |
| 5820 | spin_unlock(&inode->i_lock); |
| 5821 | } |
| 5822 | |
| 5823 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5824 | { |
| 5825 | nfs4_set_cached_acl(inode, NULL); |
| 5826 | } |
| 5827 | |
| 5828 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5829 | { |
| 5830 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5831 | struct nfs4_cached_acl *acl; |
| 5832 | int ret = -ENOENT; |
| 5833 | |
| 5834 | spin_lock(&inode->i_lock); |
| 5835 | acl = nfsi->nfs4_acl; |
| 5836 | if (acl == NULL) |
| 5837 | goto out; |
| 5838 | if (buf == NULL) /* user is just asking for length */ |
| 5839 | goto out_len; |
| 5840 | if (acl->cached == 0) |
| 5841 | goto out; |
| 5842 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5843 | if (acl->len > buflen) |
| 5844 | goto out; |
| 5845 | memcpy(buf, acl->data, acl->len); |
| 5846 | out_len: |
| 5847 | ret = acl->len; |
| 5848 | out: |
| 5849 | spin_unlock(&inode->i_lock); |
| 5850 | return ret; |
| 5851 | } |
| 5852 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5853 | 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] | 5854 | { |
| 5855 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5856 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5857 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5858 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5859 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5860 | if (acl == NULL) |
| 5861 | goto out; |
| 5862 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5863 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5864 | } else { |
| 5865 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5866 | if (acl == NULL) |
| 5867 | goto out; |
| 5868 | acl->cached = 0; |
| 5869 | } |
| 5870 | acl->len = acl_len; |
| 5871 | out: |
| 5872 | nfs4_set_cached_acl(inode, acl); |
| 5873 | } |
| 5874 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5875 | /* |
| 5876 | * The getxattr API returns the required buffer length when called with a |
| 5877 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5878 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5879 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5880 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5881 | * the cache. If not so, we throw away the page, and cache the required |
| 5882 | * length. The next getxattr call will then produce another round trip to |
| 5883 | * the server, this time with the input buf of the required size. |
| 5884 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5885 | 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] | 5886 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5887 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5888 | struct nfs_getaclargs args = { |
| 5889 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5890 | .acl_len = buflen, |
| 5891 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5892 | struct nfs_getaclres res = { |
| 5893 | .acl_len = buflen, |
| 5894 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5895 | struct rpc_message msg = { |
| 5896 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5897 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5898 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5899 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5900 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5901 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5902 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5903 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5904 | if (buflen == 0) |
| 5905 | buflen = server->rsize; |
| 5906 | |
| 5907 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5908 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5909 | if (!pages) |
| 5910 | return -ENOMEM; |
| 5911 | |
| 5912 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5913 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5914 | for (i = 0; i < npages; i++) { |
| 5915 | pages[i] = alloc_page(GFP_KERNEL); |
| 5916 | if (!pages[i]) |
| 5917 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5918 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5919 | |
| 5920 | /* for decoding across pages */ |
| 5921 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5922 | if (!res.acl_scratch) |
| 5923 | goto out_free; |
| 5924 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5925 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5926 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5927 | 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] | 5928 | __func__, buf, buflen, npages, args.acl_len); |
| 5929 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5930 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5931 | if (ret) |
| 5932 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5933 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5934 | /* Handle the case where the passed-in buffer is too short */ |
| 5935 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5936 | /* Did the user only issue a request for the acl length? */ |
| 5937 | if (buf == NULL) |
| 5938 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5939 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5940 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5941 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5942 | 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] | 5943 | if (buf) { |
| 5944 | if (res.acl_len > buflen) { |
| 5945 | ret = -ERANGE; |
| 5946 | goto out_free; |
| 5947 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5948 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5949 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5950 | out_ok: |
| 5951 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5952 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5953 | for (i = 0; i < npages; i++) |
| 5954 | if (pages[i]) |
| 5955 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5956 | if (res.acl_scratch) |
| 5957 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5958 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5959 | return ret; |
| 5960 | } |
| 5961 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5962 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5963 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5964 | struct nfs4_exception exception = { |
| 5965 | .interruptible = true, |
| 5966 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5967 | ssize_t ret; |
| 5968 | do { |
| 5969 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5970 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5971 | if (ret >= 0) |
| 5972 | break; |
| 5973 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5974 | } while (exception.retry); |
| 5975 | return ret; |
| 5976 | } |
| 5977 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5978 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5979 | { |
| 5980 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5981 | int ret; |
| 5982 | |
| 5983 | if (!nfs4_server_supports_acls(server)) |
| 5984 | return -EOPNOTSUPP; |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 5985 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5986 | if (ret < 0) |
| 5987 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5988 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5989 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5990 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5991 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5992 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5993 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5994 | return ret; |
| 5995 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5996 | } |
| 5997 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5998 | 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] | 5999 | { |
| 6000 | struct nfs_server *server = NFS_SERVER(inode); |
| 6001 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 6002 | struct nfs_setaclargs arg = { |
| 6003 | .fh = NFS_FH(inode), |
| 6004 | .acl_pages = pages, |
| 6005 | .acl_len = buflen, |
| 6006 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 6007 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6008 | struct rpc_message msg = { |
| 6009 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 6010 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 6011 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6012 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 6013 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 6014 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6015 | |
J. Bruce Fields | 4f8be1f | 2021-01-28 17:36:38 -0500 | [diff] [blame] | 6016 | /* You can't remove system.nfs4_acl: */ |
| 6017 | if (buflen == 0) |
| 6018 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6019 | if (!nfs4_server_supports_acls(server)) |
| 6020 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 6021 | if (npages > ARRAY_SIZE(pages)) |
| 6022 | return -ERANGE; |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 6023 | i = nfs4_buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 6024 | if (i < 0) |
| 6025 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 6026 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6027 | 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] | 6028 | |
| 6029 | /* |
| 6030 | * Free each page after tx, so the only ref left is |
| 6031 | * held by the network stack |
| 6032 | */ |
| 6033 | for (; i > 0; i--) |
| 6034 | put_page(pages[i-1]); |
| 6035 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 6036 | /* |
| 6037 | * Acl update can result in inode attribute update. |
| 6038 | * so mark the attribute cache invalid. |
| 6039 | */ |
| 6040 | spin_lock(&inode->i_lock); |
Trond Myklebust | b6f80a2 | 2021-03-08 14:42:55 -0500 | [diff] [blame] | 6041 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | |
| 6042 | NFS_INO_INVALID_CTIME | |
| 6043 | NFS_INO_REVAL_FORCED); |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 6044 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 6045 | nfs_access_zap_cache(inode); |
| 6046 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6047 | return ret; |
| 6048 | } |
| 6049 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 6050 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 6051 | { |
| 6052 | struct nfs4_exception exception = { }; |
| 6053 | int err; |
| 6054 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6055 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 6056 | trace_nfs4_set_acl(inode, err); |
Dai Ngo | f8849e2 | 2021-05-19 17:15:10 -0400 | [diff] [blame] | 6057 | if (err == -NFS4ERR_BADOWNER || err == -NFS4ERR_BADNAME) { |
| 6058 | /* |
| 6059 | * no need to retry since the kernel |
| 6060 | * isn't involved in encoding the ACEs. |
| 6061 | */ |
| 6062 | err = -EINVAL; |
| 6063 | break; |
| 6064 | } |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6065 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 6066 | &exception); |
| 6067 | } while (exception.retry); |
| 6068 | return err; |
| 6069 | } |
| 6070 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6071 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 6072 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 6073 | size_t buflen) |
| 6074 | { |
| 6075 | struct nfs_server *server = NFS_SERVER(inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6076 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 6077 | |
| 6078 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Anna Schumaker | 2ef61e0 | 2021-10-22 13:11:07 -0400 | [diff] [blame] | 6079 | struct nfs_fattr fattr = { |
| 6080 | .label = &label, |
| 6081 | }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 6082 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6083 | .fh = NFS_FH(inode), |
| 6084 | .bitmask = bitmask, |
| 6085 | }; |
| 6086 | struct nfs4_getattr_res res = { |
| 6087 | .fattr = &fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6088 | .server = server, |
| 6089 | }; |
| 6090 | struct rpc_message msg = { |
| 6091 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 6092 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6093 | .rpc_resp = &res, |
| 6094 | }; |
| 6095 | int ret; |
| 6096 | |
| 6097 | nfs_fattr_init(&fattr); |
| 6098 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 6099 | 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] | 6100 | if (ret) |
| 6101 | return ret; |
| 6102 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 6103 | return -ENOENT; |
Ondrej Mosnacek | 53cb245 | 2021-01-15 18:43:56 +0100 | [diff] [blame] | 6104 | return label.len; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 6108 | size_t buflen) |
| 6109 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6110 | struct nfs4_exception exception = { |
| 6111 | .interruptible = true, |
| 6112 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6113 | int err; |
| 6114 | |
| 6115 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6116 | return -EOPNOTSUPP; |
| 6117 | |
| 6118 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6119 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 6120 | trace_nfs4_get_security_label(inode, err); |
| 6121 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6122 | &exception); |
| 6123 | } while (exception.retry); |
| 6124 | return err; |
| 6125 | } |
| 6126 | |
| 6127 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 6128 | struct nfs4_label *ilabel, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6129 | struct nfs_fattr *fattr) |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6130 | { |
| 6131 | |
| 6132 | struct iattr sattr = {0}; |
| 6133 | struct nfs_server *server = NFS_SERVER(inode); |
| 6134 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6135 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6136 | .fh = NFS_FH(inode), |
| 6137 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6138 | .server = server, |
| 6139 | .bitmask = bitmask, |
| 6140 | .label = ilabel, |
| 6141 | }; |
| 6142 | struct nfs_setattrres res = { |
| 6143 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6144 | .server = server, |
| 6145 | }; |
| 6146 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6147 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 6148 | .rpc_argp = &arg, |
| 6149 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6150 | }; |
| 6151 | int status; |
| 6152 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6153 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6154 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6155 | 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] | 6156 | if (status) |
| 6157 | dprintk("%s failed: %d\n", __func__, status); |
| 6158 | |
| 6159 | return status; |
| 6160 | } |
| 6161 | |
| 6162 | static int nfs4_do_set_security_label(struct inode *inode, |
| 6163 | struct nfs4_label *ilabel, |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6164 | struct nfs_fattr *fattr) |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6165 | { |
| 6166 | struct nfs4_exception exception = { }; |
| 6167 | int err; |
| 6168 | |
| 6169 | do { |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6170 | err = _nfs4_do_set_security_label(inode, ilabel, fattr); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6171 | trace_nfs4_set_security_label(inode, err); |
| 6172 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6173 | &exception); |
| 6174 | } while (exception.retry); |
| 6175 | return err; |
| 6176 | } |
| 6177 | |
| 6178 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6179 | 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] | 6180 | { |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6181 | struct nfs4_label ilabel = {0, 0, buflen, (char *)buf }; |
| 6182 | struct nfs_fattr *fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6183 | int status; |
| 6184 | |
| 6185 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6186 | return -EOPNOTSUPP; |
| 6187 | |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6188 | fattr = nfs_alloc_fattr_with_label(NFS_SERVER(inode)); |
| 6189 | if (fattr == NULL) |
| 6190 | return -ENOMEM; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6191 | |
Anna Schumaker | 1b00ad6 | 2021-10-22 13:11:08 -0400 | [diff] [blame] | 6192 | status = nfs4_do_set_security_label(inode, &ilabel, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6193 | if (status == 0) |
Anna Schumaker | dd225cb | 2021-10-22 13:11:12 -0400 | [diff] [blame] | 6194 | nfs_setsecurity(inode, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6195 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6196 | return status; |
| 6197 | } |
| 6198 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 6199 | |
| 6200 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6201 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 6202 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6203 | { |
| 6204 | __be32 verf[2]; |
| 6205 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6206 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 6207 | /* An impossible timestamp guarantees this value |
| 6208 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6209 | verf[0] = cpu_to_be32(U32_MAX); |
| 6210 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6211 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6212 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6213 | u64 ns = ktime_to_ns(nn->boot_time); |
| 6214 | |
| 6215 | verf[0] = cpu_to_be32(ns >> 32); |
| 6216 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6217 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6218 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 6219 | } |
| 6220 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6221 | static size_t |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6222 | nfs4_get_uniquifier(struct nfs_client *clp, char *buf, size_t buflen) |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6223 | { |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6224 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 6225 | struct nfs_netns_client *nn_clp = nn->nfs_client; |
| 6226 | const char *id; |
| 6227 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6228 | buf[0] = '\0'; |
| 6229 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6230 | if (nn_clp) { |
| 6231 | rcu_read_lock(); |
| 6232 | id = rcu_dereference(nn_clp->identifier); |
| 6233 | if (id) |
| 6234 | strscpy(buf, id, buflen); |
| 6235 | rcu_read_unlock(); |
| 6236 | } |
| 6237 | |
| 6238 | if (nfs4_client_id_uniquifier[0] != '\0' && buf[0] == '\0') |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6239 | strscpy(buf, nfs4_client_id_uniquifier, buflen); |
| 6240 | |
| 6241 | return strlen(buf); |
| 6242 | } |
| 6243 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6244 | static int |
| 6245 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6246 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6247 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6248 | size_t buflen; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6249 | size_t len; |
| 6250 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6251 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6252 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6253 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 6254 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6255 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6256 | len = 14 + |
| 6257 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 6258 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6259 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6260 | 1; |
| 6261 | rcu_read_unlock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6262 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6263 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6264 | if (buflen) |
| 6265 | len += buflen + 1; |
| 6266 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6267 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6268 | return -EINVAL; |
| 6269 | |
| 6270 | /* |
| 6271 | * Since this string is allocated at mount time, and held until the |
| 6272 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6273 | * about a memory-reclaim deadlock. |
| 6274 | */ |
| 6275 | str = kmalloc(len, GFP_KERNEL); |
| 6276 | if (!str) |
| 6277 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6278 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6279 | rcu_read_lock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6280 | if (buflen) |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6281 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6282 | clp->cl_rpcclient->cl_nodename, buf, |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6283 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6284 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6285 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6286 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6287 | clp->cl_rpcclient->cl_nodename, |
| 6288 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6289 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6290 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6291 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6292 | clp->cl_owner_id = str; |
| 6293 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6294 | } |
| 6295 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6296 | static int |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6297 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6298 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6299 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6300 | size_t buflen; |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6301 | size_t len; |
| 6302 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6303 | |
| 6304 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6305 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6306 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6307 | len = 10 + 10 + 1 + 10 + 1 + |
| 6308 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6309 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6310 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6311 | if (buflen) |
| 6312 | len += buflen + 1; |
| 6313 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6314 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6315 | return -EINVAL; |
| 6316 | |
| 6317 | /* |
| 6318 | * Since this string is allocated at mount time, and held until the |
| 6319 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6320 | * about a memory-reclaim deadlock. |
| 6321 | */ |
| 6322 | str = kmalloc(len, GFP_KERNEL); |
| 6323 | if (!str) |
| 6324 | return -ENOMEM; |
| 6325 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6326 | if (buflen) |
| 6327 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
| 6328 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6329 | buf, clp->cl_rpcclient->cl_nodename); |
| 6330 | else |
| 6331 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
| 6332 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6333 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6334 | clp->cl_owner_id = str; |
| 6335 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6336 | } |
| 6337 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6338 | /* |
| 6339 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6340 | * services. Advertise one based on the address family of the |
| 6341 | * clientaddr. |
| 6342 | */ |
| 6343 | static unsigned int |
| 6344 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6345 | { |
| 6346 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6347 | return scnprintf(buf, len, "tcp6"); |
| 6348 | else |
| 6349 | return scnprintf(buf, len, "tcp"); |
| 6350 | } |
| 6351 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6352 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6353 | { |
| 6354 | struct nfs4_setclientid *sc = calldata; |
| 6355 | |
| 6356 | if (task->tk_status == 0) |
| 6357 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6358 | } |
| 6359 | |
| 6360 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6361 | .rpc_call_done = nfs4_setclientid_done, |
| 6362 | }; |
| 6363 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6364 | /** |
| 6365 | * nfs4_proc_setclientid - Negotiate client ID |
| 6366 | * @clp: state data structure |
| 6367 | * @program: RPC program for NFSv4 callback service |
| 6368 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6369 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6370 | * @res: where to place the result |
| 6371 | * |
| 6372 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6373 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6374 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6375 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6376 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6377 | { |
| 6378 | nfs4_verifier sc_verifier; |
| 6379 | struct nfs4_setclientid setclientid = { |
| 6380 | .sc_verifier = &sc_verifier, |
| 6381 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6382 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6383 | }; |
| 6384 | struct rpc_message msg = { |
| 6385 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6386 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6387 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6388 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6389 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6390 | struct rpc_task_setup task_setup_data = { |
| 6391 | .rpc_client = clp->cl_rpcclient, |
| 6392 | .rpc_message = &msg, |
| 6393 | .callback_ops = &nfs4_setclientid_ops, |
| 6394 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6395 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6396 | }; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6397 | unsigned long now = jiffies; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6398 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6399 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6400 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6401 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6402 | |
| 6403 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6404 | status = nfs4_init_uniform_client_string(clp); |
| 6405 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6406 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6407 | |
| 6408 | if (status) |
| 6409 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6410 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6411 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6412 | setclientid.sc_netid_len = |
| 6413 | nfs4_init_callback_netid(clp, |
| 6414 | setclientid.sc_netid, |
| 6415 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6416 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6417 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6418 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6419 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6420 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6421 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6422 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6423 | |
| 6424 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6425 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6426 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6427 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6428 | put_rpccred(setclientid.sc_cred); |
| 6429 | } |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6430 | |
| 6431 | if (status == 0) |
| 6432 | do_renew_lease(clp, now); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6433 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6434 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6435 | dprintk("NFS reply setclientid: %d\n", status); |
| 6436 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | } |
| 6438 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6439 | /** |
| 6440 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6441 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6442 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6443 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6444 | * |
| 6445 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6446 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6447 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6448 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6449 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6450 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6451 | struct rpc_message msg = { |
| 6452 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6453 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6454 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6455 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6456 | int status; |
| 6457 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6458 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6459 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6460 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6461 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6462 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6463 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6464 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6465 | return status; |
| 6466 | } |
| 6467 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6468 | struct nfs4_delegreturndata { |
| 6469 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6470 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6471 | struct nfs_fh fh; |
| 6472 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6473 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6474 | struct { |
| 6475 | struct nfs4_layoutreturn_args arg; |
| 6476 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6477 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6478 | u32 roc_barrier; |
| 6479 | bool roc; |
| 6480 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6481 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6482 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6483 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6484 | }; |
| 6485 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6486 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6487 | { |
| 6488 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6489 | struct nfs4_exception exception = { |
| 6490 | .inode = data->inode, |
| 6491 | .stateid = &data->stateid, |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 6492 | .task_is_privileged = data->args.seq_args.sa_privileged, |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6493 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6494 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6495 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6496 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6497 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6498 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6499 | |
| 6500 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6501 | if (pnfs_roc_done(task, &data->args.lr_args, &data->res.lr_res, |
| 6502 | &data->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6503 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6504 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6505 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6506 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6507 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6508 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6509 | case -NFS4ERR_ADMIN_REVOKED: |
| 6510 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6511 | case -NFS4ERR_EXPIRED: |
| 6512 | nfs4_free_revoked_stateid(data->res.server, |
| 6513 | data->args.stateid, |
| 6514 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6515 | fallthrough; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6516 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6517 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 244fcd2 | 2019-12-20 10:43:37 -0500 | [diff] [blame] | 6518 | case -ETIMEDOUT: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6519 | task->tk_status = 0; |
| 6520 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6521 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6522 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6523 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6524 | if (data->args.bitmask) { |
| 6525 | data->args.bitmask = NULL; |
| 6526 | data->res.fattr = NULL; |
| 6527 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6528 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6529 | case -NFS4ERR_ACCESS: |
| 6530 | if (data->args.bitmask) { |
| 6531 | data->args.bitmask = NULL; |
| 6532 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6533 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6534 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6535 | fallthrough; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6536 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6537 | task->tk_status = nfs4_async_handle_exception(task, |
| 6538 | data->res.server, task->tk_status, |
| 6539 | &exception); |
| 6540 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6541 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6542 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6543 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6544 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6545 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6546 | out_restart: |
| 6547 | task->tk_status = 0; |
| 6548 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6549 | } |
| 6550 | |
| 6551 | static void nfs4_delegreturn_release(void *calldata) |
| 6552 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6553 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6554 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6555 | |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6556 | if (data->lr.roc) |
| 6557 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6558 | data->res.lr_ret); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6559 | if (inode) { |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6560 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6561 | nfs_iput_and_deactive(inode); |
| 6562 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6563 | kfree(calldata); |
| 6564 | } |
| 6565 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6566 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6567 | { |
| 6568 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6569 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6570 | |
| 6571 | d_data = (struct nfs4_delegreturndata *)data; |
| 6572 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6573 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6574 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6575 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6576 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6577 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6578 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6579 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6580 | d_data->args.lr_args = NULL; |
| 6581 | d_data->res.lr_res = NULL; |
| 6582 | } |
| 6583 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6584 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6585 | &d_data->args.seq_args, |
| 6586 | &d_data->res.seq_res, |
| 6587 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6588 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6589 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6590 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6591 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6592 | .rpc_call_done = nfs4_delegreturn_done, |
| 6593 | .rpc_release = nfs4_delegreturn_release, |
| 6594 | }; |
| 6595 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6596 | 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] | 6597 | { |
| 6598 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6599 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6600 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6601 | struct rpc_message msg = { |
| 6602 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6603 | .rpc_cred = cred, |
| 6604 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6605 | struct rpc_task_setup task_setup_data = { |
| 6606 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6607 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6608 | .callback_ops = &nfs4_delegreturn_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 6609 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT | RPC_TASK_MOVEABLE, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6610 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6611 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6612 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6613 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6614 | if (data == NULL) |
| 6615 | return -ENOMEM; |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6616 | |
| 6617 | nfs4_state_protect(server->nfs_client, |
| 6618 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6619 | &task_setup_data.rpc_client, &msg); |
| 6620 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6621 | data->args.fhandle = &data->fh; |
| 6622 | data->args.stateid = &data->stateid; |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 6623 | nfs4_bitmask_set(data->args.bitmask_store, |
Trond Myklebust | 8584728 | 2021-12-27 14:40:51 -0500 | [diff] [blame] | 6624 | server->cache_consistency_bitmask, inode, 0); |
Trond Myklebust | 332d1a0 | 2021-03-25 18:15:36 -0400 | [diff] [blame] | 6625 | data->args.bitmask = data->args.bitmask_store; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6626 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6627 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6628 | data->res.fattr = &data->fattr; |
| 6629 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6630 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6631 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6632 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6633 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6634 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6635 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6636 | if (data->inode || issync) { |
| 6637 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, |
| 6638 | cred); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6639 | if (data->lr.roc) { |
| 6640 | data->args.lr_args = &data->lr.arg; |
| 6641 | data->res.lr_res = &data->lr.res; |
| 6642 | } |
| 6643 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6644 | |
Trond Myklebust | dfe1fe7 | 2021-06-01 11:10:05 -0400 | [diff] [blame] | 6645 | if (!data->inode) |
| 6646 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, |
| 6647 | 1); |
| 6648 | else |
| 6649 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, |
| 6650 | 0); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6651 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6652 | msg.rpc_argp = &data->args; |
| 6653 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6654 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6655 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6656 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6657 | if (!issync) |
| 6658 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6659 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6660 | if (status != 0) |
| 6661 | goto out; |
| 6662 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6663 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6664 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6665 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6666 | } |
| 6667 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6668 | 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] | 6669 | { |
| 6670 | struct nfs_server *server = NFS_SERVER(inode); |
| 6671 | struct nfs4_exception exception = { }; |
| 6672 | int err; |
| 6673 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6674 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6675 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6676 | switch (err) { |
| 6677 | case -NFS4ERR_STALE_STATEID: |
| 6678 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6679 | case 0: |
| 6680 | return 0; |
| 6681 | } |
| 6682 | err = nfs4_handle_exception(server, err, &exception); |
| 6683 | } while (exception.retry); |
| 6684 | return err; |
| 6685 | } |
| 6686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6687 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6688 | { |
| 6689 | struct inode *inode = state->inode; |
| 6690 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6691 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6692 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6693 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6694 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6695 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6696 | struct nfs_lockt_res res = { |
| 6697 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6698 | }; |
| 6699 | struct rpc_message msg = { |
| 6700 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6701 | .rpc_argp = &arg, |
| 6702 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6703 | .rpc_cred = state->owner->so_cred, |
| 6704 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6705 | struct nfs4_lock_state *lsp; |
| 6706 | int status; |
| 6707 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6708 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6709 | status = nfs4_set_lock_state(state, request); |
| 6710 | if (status != 0) |
| 6711 | goto out; |
| 6712 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6713 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6714 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6715 | 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] | 6716 | switch (status) { |
| 6717 | case 0: |
| 6718 | request->fl_type = F_UNLCK; |
| 6719 | break; |
| 6720 | case -NFS4ERR_DENIED: |
| 6721 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6722 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6723 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6724 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6725 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6726 | return status; |
| 6727 | } |
| 6728 | |
| 6729 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6730 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6731 | struct nfs4_exception exception = { |
| 6732 | .interruptible = true, |
| 6733 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6734 | int err; |
| 6735 | |
| 6736 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6737 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6738 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6739 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6740 | &exception); |
| 6741 | } while (exception.retry); |
| 6742 | return err; |
| 6743 | } |
| 6744 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6745 | /* |
| 6746 | * Update the seqid of a lock stateid after receiving |
| 6747 | * NFS4ERR_OLD_STATEID |
| 6748 | */ |
| 6749 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6750 | struct nfs4_lock_state *lsp) |
| 6751 | { |
| 6752 | struct nfs4_state *state = lsp->ls_state; |
| 6753 | bool ret = false; |
| 6754 | |
| 6755 | spin_lock(&state->state_lock); |
| 6756 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6757 | goto out; |
| 6758 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6759 | nfs4_stateid_seqid_inc(dst); |
| 6760 | else |
| 6761 | dst->seqid = lsp->ls_stateid.seqid; |
| 6762 | ret = true; |
| 6763 | out: |
| 6764 | spin_unlock(&state->state_lock); |
| 6765 | return ret; |
| 6766 | } |
| 6767 | |
| 6768 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6769 | struct nfs4_lock_state *lsp) |
| 6770 | { |
| 6771 | struct nfs4_state *state = lsp->ls_state; |
| 6772 | bool ret; |
| 6773 | |
| 6774 | spin_lock(&state->state_lock); |
| 6775 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6776 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6777 | spin_unlock(&state->state_lock); |
| 6778 | return ret; |
| 6779 | } |
| 6780 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6781 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6782 | struct nfs_locku_args arg; |
| 6783 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6784 | struct nfs4_lock_state *lsp; |
| 6785 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6786 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6787 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6788 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6789 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6790 | }; |
| 6791 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6792 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6793 | struct nfs_open_context *ctx, |
| 6794 | struct nfs4_lock_state *lsp, |
| 6795 | struct nfs_seqid *seqid) |
| 6796 | { |
| 6797 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6798 | struct nfs4_state *state = lsp->ls_state; |
| 6799 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6800 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6801 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6802 | if (p == NULL) |
| 6803 | return NULL; |
| 6804 | p->arg.fh = NFS_FH(inode); |
| 6805 | p->arg.fl = &p->fl; |
| 6806 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6807 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6808 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6809 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6810 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6811 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6812 | locks_init_lock(&p->fl); |
| 6813 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6814 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6815 | spin_lock(&state->state_lock); |
| 6816 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6817 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6818 | return p; |
| 6819 | } |
| 6820 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6821 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6822 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6823 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6824 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6825 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6826 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6827 | put_nfs_open_context(calldata->ctx); |
| 6828 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6829 | } |
| 6830 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6831 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6832 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6833 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6834 | struct nfs4_exception exception = { |
| 6835 | .inode = calldata->lsp->ls_state->inode, |
| 6836 | .stateid = &calldata->arg.stateid, |
| 6837 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6838 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6839 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6840 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6841 | switch (task->tk_status) { |
| 6842 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6843 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6844 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6845 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6846 | &calldata->res.stateid)) |
| 6847 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6848 | fallthrough; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6849 | case -NFS4ERR_ADMIN_REVOKED: |
| 6850 | case -NFS4ERR_EXPIRED: |
| 6851 | nfs4_free_revoked_stateid(calldata->server, |
| 6852 | &calldata->arg.stateid, |
| 6853 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6854 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6855 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6856 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6857 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6858 | calldata->lsp)) |
| 6859 | rpc_restart_call_prepare(task); |
| 6860 | break; |
| 6861 | case -NFS4ERR_OLD_STATEID: |
| 6862 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6863 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6864 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6865 | break; |
| 6866 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6867 | task->tk_status = nfs4_async_handle_exception(task, |
| 6868 | calldata->server, task->tk_status, |
| 6869 | &exception); |
| 6870 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6871 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6872 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6873 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6874 | } |
| 6875 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6876 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6877 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6878 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6879 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6880 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6881 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6882 | return; |
| 6883 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6884 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6885 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6886 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6887 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6888 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6889 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6890 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6891 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6892 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6893 | &calldata->res.seq_res, |
| 6894 | task) != 0) |
| 6895 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6896 | return; |
| 6897 | out_no_action: |
| 6898 | task->tk_action = NULL; |
| 6899 | out_wait: |
| 6900 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6901 | } |
| 6902 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6903 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6904 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6905 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6906 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6907 | }; |
| 6908 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6909 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6910 | struct nfs_open_context *ctx, |
| 6911 | struct nfs4_lock_state *lsp, |
| 6912 | struct nfs_seqid *seqid) |
| 6913 | { |
| 6914 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6915 | struct rpc_message msg = { |
| 6916 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6917 | .rpc_cred = ctx->cred, |
| 6918 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6919 | struct rpc_task_setup task_setup_data = { |
| 6920 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6921 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6922 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6923 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6924 | .flags = RPC_TASK_ASYNC, |
| 6925 | }; |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 6926 | struct nfs_client *client = |
| 6927 | NFS_SERVER(lsp->ls_state->inode)->nfs_client; |
| 6928 | |
| 6929 | if (client->cl_minorversion) |
| 6930 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6931 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6932 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6933 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6934 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6935 | /* Ensure this is an unlock - when canceling a lock, the |
| 6936 | * canceled lock is passed in, and it won't be an unlock. |
| 6937 | */ |
| 6938 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6939 | if (fl->fl_flags & FL_CLOSE) |
| 6940 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6941 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6942 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6943 | if (data == NULL) { |
| 6944 | nfs_free_seqid(seqid); |
| 6945 | return ERR_PTR(-ENOMEM); |
| 6946 | } |
| 6947 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6948 | 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] | 6949 | msg.rpc_argp = &data->arg; |
| 6950 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6951 | task_setup_data.callback_data = data; |
| 6952 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6953 | } |
| 6954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6955 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6956 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6957 | struct inode *inode = state->inode; |
| 6958 | struct nfs4_state_owner *sp = state->owner; |
| 6959 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6960 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6961 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6962 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6963 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6964 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6965 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6966 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6967 | status = nfs4_set_lock_state(state, request); |
| 6968 | /* Unlock _before_ we do the RPC call */ |
| 6969 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6970 | /* Exclude nfs_delegation_claim_locks() */ |
| 6971 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6972 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6973 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6974 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6975 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6976 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6977 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6978 | } |
| 6979 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6980 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6981 | if (status != 0) |
| 6982 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6983 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6984 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6985 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6986 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6987 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6988 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6989 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6990 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6991 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6992 | 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] | 6993 | status = PTR_ERR(task); |
| 6994 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6995 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6996 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6997 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6998 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6999 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 7000 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 7001 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7002 | } |
| 7003 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7004 | struct nfs4_lockdata { |
| 7005 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 7006 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7007 | struct nfs4_lock_state *lsp; |
| 7008 | struct nfs_open_context *ctx; |
| 7009 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 7010 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7011 | int rpc_status; |
| 7012 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 7013 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7014 | }; |
| 7015 | |
| 7016 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7017 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 7018 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7019 | { |
| 7020 | struct nfs4_lockdata *p; |
| 7021 | struct inode *inode = lsp->ls_state->inode; |
| 7022 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 7023 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7024 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7025 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7026 | if (p == NULL) |
| 7027 | return NULL; |
| 7028 | |
| 7029 | p->arg.fh = NFS_FH(inode); |
| 7030 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7031 | 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] | 7032 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7033 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 7034 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 7035 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 7036 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7037 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 7038 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7039 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 7040 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 7041 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7042 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 7043 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7044 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 7045 | locks_init_lock(&p->fl); |
| 7046 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7047 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7048 | out_free_seqid: |
| 7049 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7050 | out_free: |
| 7051 | kfree(p); |
| 7052 | return NULL; |
| 7053 | } |
| 7054 | |
| 7055 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 7056 | { |
| 7057 | struct nfs4_lockdata *data = calldata; |
| 7058 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7059 | |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7060 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 7061 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7062 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 7063 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7064 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 7065 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7066 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7067 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 7068 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7069 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 7070 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7071 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7072 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7073 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 7074 | &data->lsp->ls_stateid); |
| 7075 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 7076 | if (!nfs4_valid_open_stateid(state)) { |
| 7077 | data->rpc_status = -EBADF; |
| 7078 | task->tk_action = NULL; |
| 7079 | goto out_release_open_seqid; |
| 7080 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 7081 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 7082 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7083 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 7084 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7085 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 7086 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 7087 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 7088 | nfs_release_seqid(data->arg.open_seqid); |
| 7089 | out_release_lock_seqid: |
| 7090 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 7091 | out_wait: |
| 7092 | nfs4_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 7093 | dprintk("%s: ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 7094 | } |
| 7095 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7096 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 7097 | { |
| 7098 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7099 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7100 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7101 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 7102 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 7103 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7104 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7105 | switch (task->tk_status) { |
| 7106 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 7107 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7108 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7109 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7110 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7111 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7112 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7113 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 7114 | if (data->arg.new_lock_owner != 0) { |
| 7115 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 7116 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 7117 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7118 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 7119 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7120 | break; |
| 7121 | case -NFS4ERR_BAD_STATEID: |
| 7122 | case -NFS4ERR_OLD_STATEID: |
| 7123 | case -NFS4ERR_STALE_STATEID: |
| 7124 | case -NFS4ERR_EXPIRED: |
| 7125 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7126 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7127 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7128 | goto out_restart; |
| 7129 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7130 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7131 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7132 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7133 | out_done: |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 7134 | dprintk("%s: ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7135 | return; |
| 7136 | out_restart: |
| 7137 | if (!data->cancelled) |
| 7138 | rpc_restart_call_prepare(task); |
| 7139 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | static void nfs4_lock_release(void *calldata) |
| 7143 | { |
| 7144 | struct nfs4_lockdata *data = calldata; |
| 7145 | |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7146 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7147 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7148 | struct rpc_task *task; |
| 7149 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 7150 | data->arg.lock_seqid); |
| 7151 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7152 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7153 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7154 | } else |
| 7155 | nfs_free_seqid(data->arg.lock_seqid); |
| 7156 | nfs4_put_lock_state(data->lsp); |
| 7157 | put_nfs_open_context(data->ctx); |
| 7158 | kfree(data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7159 | } |
| 7160 | |
| 7161 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 7162 | .rpc_call_prepare = nfs4_lock_prepare, |
| 7163 | .rpc_call_done = nfs4_lock_done, |
| 7164 | .rpc_release = nfs4_lock_release, |
| 7165 | }; |
| 7166 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7167 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 7168 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7169 | switch (error) { |
| 7170 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 7171 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7172 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7173 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7174 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 7175 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7176 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7177 | break; |
| 7178 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7179 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7180 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 7181 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7182 | } |
| 7183 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7184 | 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] | 7185 | { |
| 7186 | struct nfs4_lockdata *data; |
| 7187 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7188 | struct rpc_message msg = { |
| 7189 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 7190 | .rpc_cred = state->owner->so_cred, |
| 7191 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7192 | struct rpc_task_setup task_setup_data = { |
| 7193 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7194 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7195 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 7196 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 7197 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7198 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7199 | int ret; |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 7200 | struct nfs_client *client = NFS_SERVER(state->inode)->nfs_client; |
| 7201 | |
| 7202 | if (client->cl_minorversion) |
| 7203 | task_setup_data.flags |= RPC_TASK_MOVEABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7204 | |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7205 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7206 | fl->fl_u.nfs4_fl.owner, |
| 7207 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7208 | if (data == NULL) |
| 7209 | return -ENOMEM; |
| 7210 | if (IS_SETLKW(cmd)) |
| 7211 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7212 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 7213 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 7214 | msg.rpc_argp = &data->arg; |
| 7215 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7216 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7217 | if (recovery_type > NFS_LOCK_NEW) { |
| 7218 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 7219 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7220 | } else |
| 7221 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7222 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 7223 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7224 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 7225 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7226 | if (ret == 0) { |
| 7227 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7228 | if (ret) |
| 7229 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 7230 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7231 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 7232 | data->cancelled = true; |
Dave Wysochanski | 3d1a90a | 2020-12-11 05:12:51 -0500 | [diff] [blame] | 7233 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 7234 | rpc_put_task(task); |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 7235 | dprintk("%s: ret = %d\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7236 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7237 | } |
| 7238 | |
| 7239 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 7240 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7241 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7242 | struct nfs4_exception exception = { |
| 7243 | .inode = state->inode, |
| 7244 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7245 | int err; |
| 7246 | |
| 7247 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7248 | /* Cache the lock if possible... */ |
| 7249 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7250 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7251 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 7252 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7253 | break; |
| 7254 | nfs4_handle_exception(server, err, &exception); |
| 7255 | } while (exception.retry); |
| 7256 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7257 | } |
| 7258 | |
| 7259 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7260 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7261 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7262 | struct nfs4_exception exception = { |
| 7263 | .inode = state->inode, |
| 7264 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7265 | int err; |
| 7266 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 7267 | err = nfs4_set_lock_state(state, request); |
| 7268 | if (err != 0) |
| 7269 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 7270 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 7271 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 7272 | return 0; |
| 7273 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7274 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7275 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7276 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7277 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7278 | switch (err) { |
| 7279 | default: |
| 7280 | goto out; |
| 7281 | case -NFS4ERR_GRACE: |
| 7282 | case -NFS4ERR_DELAY: |
| 7283 | nfs4_handle_exception(server, err, &exception); |
| 7284 | err = 0; |
| 7285 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7286 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7287 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7288 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7289 | } |
| 7290 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7291 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7292 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7293 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7294 | struct nfs4_lock_state *lsp; |
| 7295 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7296 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7297 | status = nfs4_set_lock_state(state, request); |
| 7298 | if (status != 0) |
| 7299 | return status; |
| 7300 | lsp = request->fl_u.nfs4_fl.owner; |
| 7301 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7302 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7303 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7304 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7305 | } |
| 7306 | #endif |
| 7307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7308 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7309 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7310 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7311 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7312 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7313 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7314 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7315 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7316 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7317 | if (status < 0) |
| 7318 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7319 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7320 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7321 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7322 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7323 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7324 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7325 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7326 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7327 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7328 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7329 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7330 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7331 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7332 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7333 | out: |
| 7334 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7335 | return status; |
| 7336 | } |
| 7337 | |
| 7338 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7339 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7340 | struct nfs4_exception exception = { |
| 7341 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7342 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7343 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7344 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7345 | int err; |
| 7346 | |
| 7347 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7348 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7349 | if (err == -NFS4ERR_DENIED) |
| 7350 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7351 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7352 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7353 | } while (exception.retry); |
| 7354 | return err; |
| 7355 | } |
| 7356 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7357 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7358 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7359 | |
| 7360 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7361 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7362 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7363 | { |
| 7364 | int status = -ERESTARTSYS; |
| 7365 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7366 | |
| 7367 | while(!signalled()) { |
| 7368 | status = nfs4_proc_setlk(state, cmd, request); |
| 7369 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7370 | break; |
| 7371 | freezable_schedule_timeout_interruptible(timeout); |
| 7372 | timeout *= 2; |
| 7373 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7374 | status = -ERESTARTSYS; |
| 7375 | } |
| 7376 | return status; |
| 7377 | } |
| 7378 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7379 | #ifdef CONFIG_NFS_V4_1 |
| 7380 | struct nfs4_lock_waiter { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7381 | struct inode *inode; |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7382 | struct nfs_lowner owner; |
| 7383 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7384 | }; |
| 7385 | |
| 7386 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7387 | 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] | 7388 | { |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7389 | struct nfs4_lock_waiter *waiter = |
| 7390 | container_of(wait, struct nfs4_lock_waiter, wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7391 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7392 | /* NULL key means to wake up everyone */ |
| 7393 | if (key) { |
| 7394 | struct cb_notify_lock_args *cbnl = key; |
| 7395 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7396 | *wowner = &waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7397 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7398 | /* Only wake if the callback was for the same owner. */ |
| 7399 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7400 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7401 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7402 | /* Make sure it's for the right inode */ |
| 7403 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7404 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7405 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7406 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7407 | return woken_wake_function(wait, mode, flags, key); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7408 | } |
| 7409 | |
| 7410 | static int |
| 7411 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7412 | { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7413 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7414 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7415 | struct nfs_client *clp = server->nfs_client; |
| 7416 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7417 | struct nfs4_lock_waiter waiter = { |
| 7418 | .inode = state->inode, |
| 7419 | .owner = { .clientid = clp->cl_clientid, |
| 7420 | .id = lsp->ls_seqid.owner_id, |
| 7421 | .s_dev = server->s_dev }, |
| 7422 | }; |
| 7423 | int status; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7424 | |
| 7425 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7426 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7427 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7428 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7429 | init_wait(&waiter.wait); |
| 7430 | waiter.wait.func = nfs4_wake_lock_waiter; |
| 7431 | add_wait_queue(q, &waiter.wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7432 | |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7433 | do { |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7434 | status = nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7435 | if (status != -EAGAIN || IS_SETLK(cmd)) |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7436 | break; |
| 7437 | |
| 7438 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7439 | freezer_do_not_count(); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7440 | wait_woken(&waiter.wait, TASK_INTERRUPTIBLE, |
| 7441 | NFS4_LOCK_MAXTIMEOUT); |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7442 | freezer_count(); |
Trond Myklebust | 8643818 | 2021-02-02 14:22:51 -0500 | [diff] [blame] | 7443 | } while (!signalled()); |
| 7444 | |
| 7445 | remove_wait_queue(q, &waiter.wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7446 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7447 | return status; |
| 7448 | } |
| 7449 | #else /* !CONFIG_NFS_V4_1 */ |
| 7450 | static inline int |
| 7451 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7452 | { |
| 7453 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7454 | } |
| 7455 | #endif |
| 7456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7457 | static int |
| 7458 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7459 | { |
| 7460 | struct nfs_open_context *ctx; |
| 7461 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7462 | int status; |
| 7463 | |
| 7464 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7465 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7466 | state = ctx->state; |
| 7467 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7468 | if (IS_GETLK(cmd)) { |
| 7469 | if (state != NULL) |
| 7470 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7471 | return 0; |
| 7472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7473 | |
| 7474 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7475 | return -EINVAL; |
| 7476 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7477 | if (request->fl_type == F_UNLCK) { |
| 7478 | if (state != NULL) |
| 7479 | return nfs4_proc_unlck(state, cmd, request); |
| 7480 | return 0; |
| 7481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7482 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7483 | if (state == NULL) |
| 7484 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7485 | |
| 7486 | if ((request->fl_flags & FL_POSIX) && |
| 7487 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7488 | return -ENOLCK; |
| 7489 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7490 | /* |
| 7491 | * Don't rely on the VFS having checked the file open mode, |
| 7492 | * since it won't do this for flock() locks. |
| 7493 | */ |
| 7494 | switch (request->fl_type) { |
| 7495 | case F_RDLCK: |
| 7496 | if (!(filp->f_mode & FMODE_READ)) |
| 7497 | return -EBADF; |
| 7498 | break; |
| 7499 | case F_WRLCK: |
| 7500 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7501 | return -EBADF; |
| 7502 | } |
| 7503 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7504 | status = nfs4_set_lock_state(state, request); |
| 7505 | if (status != 0) |
| 7506 | return status; |
| 7507 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7508 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7509 | } |
| 7510 | |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7511 | static int nfs4_delete_lease(struct file *file, void **priv) |
| 7512 | { |
| 7513 | return generic_setlease(file, F_UNLCK, NULL, priv); |
| 7514 | } |
| 7515 | |
| 7516 | static int nfs4_add_lease(struct file *file, long arg, struct file_lock **lease, |
| 7517 | void **priv) |
| 7518 | { |
| 7519 | struct inode *inode = file_inode(file); |
| 7520 | fmode_t type = arg == F_RDLCK ? FMODE_READ : FMODE_WRITE; |
| 7521 | int ret; |
| 7522 | |
| 7523 | /* No delegation, no lease */ |
| 7524 | if (!nfs4_have_delegation(inode, type)) |
Trond Myklebust | df2c7b9 | 2021-06-25 15:08:39 -0400 | [diff] [blame] | 7525 | return -EAGAIN; |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7526 | ret = generic_setlease(file, arg, lease, priv); |
| 7527 | if (ret || nfs4_have_delegation(inode, type)) |
| 7528 | return ret; |
| 7529 | /* We raced with a delegation return */ |
| 7530 | nfs4_delete_lease(file, priv); |
Trond Myklebust | df2c7b9 | 2021-06-25 15:08:39 -0400 | [diff] [blame] | 7531 | return -EAGAIN; |
Trond Myklebust | e93a5e9 | 2021-05-07 10:06:13 -0400 | [diff] [blame] | 7532 | } |
| 7533 | |
| 7534 | int nfs4_proc_setlease(struct file *file, long arg, struct file_lock **lease, |
| 7535 | void **priv) |
| 7536 | { |
| 7537 | switch (arg) { |
| 7538 | case F_RDLCK: |
| 7539 | case F_WRLCK: |
| 7540 | return nfs4_add_lease(file, arg, lease, priv); |
| 7541 | case F_UNLCK: |
| 7542 | return nfs4_delete_lease(file, priv); |
| 7543 | default: |
| 7544 | return -EINVAL; |
| 7545 | } |
| 7546 | } |
| 7547 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7548 | 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] | 7549 | { |
| 7550 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7551 | int err; |
| 7552 | |
| 7553 | err = nfs4_set_lock_state(state, fl); |
| 7554 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7555 | return err; |
Olga Kornievskaia | 3d7a952 | 2020-08-20 18:52:43 -0400 | [diff] [blame] | 7556 | do { |
| 7557 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
| 7558 | if (err != -NFS4ERR_DELAY) |
| 7559 | break; |
| 7560 | ssleep(1); |
| 7561 | } while (err == -NFS4ERR_DELAY); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7562 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7563 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7564 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7565 | struct nfs_release_lockowner_data { |
| 7566 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7567 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7568 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7569 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7570 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7571 | }; |
| 7572 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7573 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7574 | { |
| 7575 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7576 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7577 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7578 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7579 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7580 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7581 | } |
| 7582 | |
| 7583 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7584 | { |
| 7585 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7586 | struct nfs_server *server = data->server; |
| 7587 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7588 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7589 | |
| 7590 | switch (task->tk_status) { |
| 7591 | case 0: |
| 7592 | renew_lease(server, data->timestamp); |
| 7593 | break; |
| 7594 | case -NFS4ERR_STALE_CLIENTID: |
| 7595 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7596 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7597 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7598 | case -NFS4ERR_LEASE_MOVED: |
| 7599 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7600 | if (nfs4_async_handle_error(task, server, |
| 7601 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7602 | rpc_restart_call_prepare(task); |
| 7603 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7604 | } |
| 7605 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7606 | static void nfs4_release_lockowner_release(void *calldata) |
| 7607 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7608 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7609 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7610 | kfree(calldata); |
| 7611 | } |
| 7612 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7613 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7614 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7615 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7616 | .rpc_release = nfs4_release_lockowner_release, |
| 7617 | }; |
| 7618 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7619 | static void |
| 7620 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7621 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7622 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7623 | struct rpc_message msg = { |
| 7624 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7625 | }; |
| 7626 | |
| 7627 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7628 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7629 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7630 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7631 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7632 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7633 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7634 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7635 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7636 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7637 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7638 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7639 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7640 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7641 | 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] | 7642 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7643 | } |
| 7644 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7645 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7646 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7647 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7648 | struct user_namespace *mnt_userns, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7649 | struct dentry *unused, struct inode *inode, |
| 7650 | const char *key, const void *buf, |
| 7651 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7652 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7653 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7654 | } |
| 7655 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7656 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7657 | struct dentry *unused, struct inode *inode, |
| 7658 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7659 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7660 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7661 | } |
| 7662 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7663 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7664 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7665 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7666 | } |
| 7667 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7668 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7669 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7670 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7671 | struct user_namespace *mnt_userns, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7672 | struct dentry *unused, struct inode *inode, |
| 7673 | const char *key, const void *buf, |
| 7674 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7675 | { |
| 7676 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7677 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7678 | |
| 7679 | return -EOPNOTSUPP; |
| 7680 | } |
| 7681 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7682 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7683 | struct dentry *unused, struct inode *inode, |
| 7684 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7685 | { |
| 7686 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7687 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7688 | return -EOPNOTSUPP; |
| 7689 | } |
| 7690 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7691 | static ssize_t |
| 7692 | 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] | 7693 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7694 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7695 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7696 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7697 | len = security_inode_listsecurity(inode, list, list_len); |
Chengguang Xu | 82c596e | 2020-06-17 09:09:39 +0800 | [diff] [blame] | 7698 | if (len >= 0 && list_len && len > list_len) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7699 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7700 | } |
| 7701 | return len; |
| 7702 | } |
| 7703 | |
| 7704 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7705 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7706 | .get = nfs4_xattr_get_nfs4_label, |
| 7707 | .set = nfs4_xattr_set_nfs4_label, |
| 7708 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7709 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7710 | #else |
| 7711 | |
| 7712 | static ssize_t |
| 7713 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7714 | { |
| 7715 | return 0; |
| 7716 | } |
| 7717 | |
| 7718 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7719 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7720 | #ifdef CONFIG_NFS_V4_2 |
| 7721 | static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler, |
Christian Brauner | e65ce2a | 2021-01-21 14:19:27 +0100 | [diff] [blame] | 7722 | struct user_namespace *mnt_userns, |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7723 | struct dentry *unused, struct inode *inode, |
| 7724 | const char *key, const void *buf, |
| 7725 | size_t buflen, int flags) |
| 7726 | { |
NeilBrown | b5e7b59 | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 7727 | u32 mask; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7728 | int ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7729 | |
| 7730 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7731 | return -EOPNOTSUPP; |
| 7732 | |
| 7733 | /* |
| 7734 | * There is no mapping from the MAY_* flags to the NFS_ACCESS_XA* |
| 7735 | * flags right now. Handling of xattr operations use the normal |
| 7736 | * file read/write permissions. |
| 7737 | * |
| 7738 | * Just in case the server has other ideas (which RFC 8276 allows), |
| 7739 | * do a cached access check for the XA* flags to possibly avoid |
| 7740 | * doing an RPC and getting EACCES back. |
| 7741 | */ |
NeilBrown | b5e7b59 | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 7742 | if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) { |
| 7743 | if (!(mask & NFS_ACCESS_XAWRITE)) |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7744 | return -EACCES; |
| 7745 | } |
| 7746 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7747 | if (buf == NULL) { |
| 7748 | ret = nfs42_proc_removexattr(inode, key); |
| 7749 | if (!ret) |
| 7750 | nfs4_xattr_cache_remove(inode, key); |
| 7751 | } else { |
| 7752 | ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags); |
| 7753 | if (!ret) |
| 7754 | nfs4_xattr_cache_add(inode, key, buf, NULL, buflen); |
| 7755 | } |
| 7756 | |
| 7757 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7758 | } |
| 7759 | |
| 7760 | static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler, |
| 7761 | struct dentry *unused, struct inode *inode, |
| 7762 | const char *key, void *buf, size_t buflen) |
| 7763 | { |
NeilBrown | b5e7b59 | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 7764 | u32 mask; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7765 | ssize_t ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7766 | |
| 7767 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7768 | return -EOPNOTSUPP; |
| 7769 | |
NeilBrown | b5e7b59 | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 7770 | if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) { |
| 7771 | if (!(mask & NFS_ACCESS_XAREAD)) |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7772 | return -EACCES; |
| 7773 | } |
| 7774 | |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 7775 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7776 | if (ret) |
| 7777 | return ret; |
| 7778 | |
| 7779 | ret = nfs4_xattr_cache_get(inode, key, buf, buflen); |
| 7780 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7781 | return ret; |
| 7782 | |
| 7783 | ret = nfs42_proc_getxattr(inode, key, buf, buflen); |
| 7784 | |
| 7785 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7786 | } |
| 7787 | |
| 7788 | static ssize_t |
| 7789 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7790 | { |
| 7791 | u64 cookie; |
| 7792 | bool eof; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7793 | ssize_t ret, size; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7794 | char *buf; |
| 7795 | size_t buflen; |
NeilBrown | b5e7b59 | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 7796 | u32 mask; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7797 | |
| 7798 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7799 | return 0; |
| 7800 | |
NeilBrown | b5e7b59 | 2021-09-28 09:47:57 +1000 | [diff] [blame] | 7801 | if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) { |
| 7802 | if (!(mask & NFS_ACCESS_XALIST)) |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7803 | return 0; |
| 7804 | } |
| 7805 | |
Trond Myklebust | 1f3208b | 2021-03-25 11:04:34 -0400 | [diff] [blame] | 7806 | ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7807 | if (ret) |
| 7808 | return ret; |
| 7809 | |
| 7810 | ret = nfs4_xattr_cache_list(inode, list, list_len); |
| 7811 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7812 | return ret; |
| 7813 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7814 | cookie = 0; |
| 7815 | eof = false; |
| 7816 | buflen = list_len ? list_len : XATTR_LIST_MAX; |
| 7817 | buf = list_len ? list : NULL; |
| 7818 | size = 0; |
| 7819 | |
| 7820 | while (!eof) { |
| 7821 | ret = nfs42_proc_listxattrs(inode, buf, buflen, |
| 7822 | &cookie, &eof); |
| 7823 | if (ret < 0) |
| 7824 | return ret; |
| 7825 | |
| 7826 | if (list_len) { |
| 7827 | buf += ret; |
| 7828 | buflen -= ret; |
| 7829 | } |
| 7830 | size += ret; |
| 7831 | } |
| 7832 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7833 | if (list_len) |
| 7834 | nfs4_xattr_cache_set_list(inode, list, size); |
| 7835 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7836 | return size; |
| 7837 | } |
| 7838 | |
| 7839 | #else |
| 7840 | |
| 7841 | static ssize_t |
| 7842 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7843 | { |
| 7844 | return 0; |
| 7845 | } |
| 7846 | #endif /* CONFIG_NFS_V4_2 */ |
| 7847 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7848 | /* |
| 7849 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7850 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7851 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7852 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7853 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7854 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7855 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7856 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7857 | return; |
| 7858 | |
| 7859 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7860 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7861 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7862 | fattr->nlink = 2; |
| 7863 | } |
| 7864 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7865 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7866 | const struct qstr *name, |
| 7867 | struct nfs4_fs_locations *fs_locations, |
| 7868 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7869 | { |
| 7870 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7871 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7872 | struct nfs4_fs_locations_arg args = { |
| 7873 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7874 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7875 | .page = page, |
| 7876 | .bitmask = bitmask, |
| 7877 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7878 | struct nfs4_fs_locations_res res = { |
| 7879 | .fs_locations = fs_locations, |
| 7880 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7881 | struct rpc_message msg = { |
| 7882 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7883 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7884 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7885 | }; |
| 7886 | int status; |
| 7887 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7888 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7889 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7890 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7891 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7892 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7893 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7894 | * is not supported */ |
| 7895 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7896 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7897 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7898 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7899 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7900 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7901 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7902 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7903 | 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] | 7904 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7905 | return status; |
| 7906 | } |
| 7907 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7908 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7909 | const struct qstr *name, |
| 7910 | struct nfs4_fs_locations *fs_locations, |
| 7911 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7912 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7913 | struct nfs4_exception exception = { |
| 7914 | .interruptible = true, |
| 7915 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7916 | int err; |
| 7917 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7918 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7919 | fs_locations, page); |
| 7920 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7921 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7922 | &exception); |
| 7923 | } while (exception.retry); |
| 7924 | return err; |
| 7925 | } |
| 7926 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7927 | /* |
| 7928 | * This operation also signals the server that this client is |
| 7929 | * performing migration recovery. The server can stop returning |
| 7930 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7931 | * appended to this compound to identify the client ID which is |
| 7932 | * performing recovery. |
| 7933 | */ |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 7934 | static int _nfs40_proc_get_locations(struct nfs_server *server, |
| 7935 | struct nfs_fh *fhandle, |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7936 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7937 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7938 | { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7939 | struct rpc_clnt *clnt = server->client; |
| 7940 | u32 bitmask[2] = { |
| 7941 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7942 | }; |
| 7943 | struct nfs4_fs_locations_arg args = { |
| 7944 | .clientid = server->nfs_client->cl_clientid, |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 7945 | .fh = fhandle, |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7946 | .page = page, |
| 7947 | .bitmask = bitmask, |
| 7948 | .migration = 1, /* skip LOOKUP */ |
| 7949 | .renew = 1, /* append RENEW */ |
| 7950 | }; |
| 7951 | struct nfs4_fs_locations_res res = { |
| 7952 | .fs_locations = locations, |
| 7953 | .migration = 1, |
| 7954 | .renew = 1, |
| 7955 | }; |
| 7956 | struct rpc_message msg = { |
| 7957 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7958 | .rpc_argp = &args, |
| 7959 | .rpc_resp = &res, |
| 7960 | .rpc_cred = cred, |
| 7961 | }; |
| 7962 | unsigned long now = jiffies; |
| 7963 | int status; |
| 7964 | |
| 7965 | nfs_fattr_init(&locations->fattr); |
| 7966 | locations->server = server; |
| 7967 | locations->nlocations = 0; |
| 7968 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7969 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7970 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7971 | &args.seq_args, &res.seq_res); |
| 7972 | if (status) |
| 7973 | return status; |
| 7974 | |
| 7975 | renew_lease(server, now); |
| 7976 | return 0; |
| 7977 | } |
| 7978 | |
| 7979 | #ifdef CONFIG_NFS_V4_1 |
| 7980 | |
| 7981 | /* |
| 7982 | * This operation also signals the server that this client is |
| 7983 | * performing migration recovery. The server can stop asserting |
| 7984 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7985 | * performing this operation is identified in the SEQUENCE |
| 7986 | * operation in this compound. |
| 7987 | * |
| 7988 | * When the client supports GETATTR(fs_locations_info), it can |
| 7989 | * be plumbed in here. |
| 7990 | */ |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 7991 | static int _nfs41_proc_get_locations(struct nfs_server *server, |
| 7992 | struct nfs_fh *fhandle, |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7993 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7994 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7995 | { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7996 | struct rpc_clnt *clnt = server->client; |
| 7997 | u32 bitmask[2] = { |
| 7998 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7999 | }; |
| 8000 | struct nfs4_fs_locations_arg args = { |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 8001 | .fh = fhandle, |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8002 | .page = page, |
| 8003 | .bitmask = bitmask, |
| 8004 | .migration = 1, /* skip LOOKUP */ |
| 8005 | }; |
| 8006 | struct nfs4_fs_locations_res res = { |
| 8007 | .fs_locations = locations, |
| 8008 | .migration = 1, |
| 8009 | }; |
| 8010 | struct rpc_message msg = { |
| 8011 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 8012 | .rpc_argp = &args, |
| 8013 | .rpc_resp = &res, |
| 8014 | .rpc_cred = cred, |
| 8015 | }; |
| 8016 | int status; |
| 8017 | |
| 8018 | nfs_fattr_init(&locations->fattr); |
| 8019 | locations->server = server; |
| 8020 | locations->nlocations = 0; |
| 8021 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8022 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8023 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 8024 | &args.seq_args, &res.seq_res); |
| 8025 | if (status == NFS4_OK && |
| 8026 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 8027 | status = -NFS4ERR_LEASE_MOVED; |
| 8028 | return status; |
| 8029 | } |
| 8030 | |
| 8031 | #endif /* CONFIG_NFS_V4_1 */ |
| 8032 | |
| 8033 | /** |
| 8034 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 8035 | * @inode: inode on FSID that is migrating |
| 8036 | * @locations: result of query |
| 8037 | * @page: buffer |
| 8038 | * @cred: credential to use for this operation |
| 8039 | * |
| 8040 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 8041 | * operation failed, or a negative errno if a local error occurred. |
| 8042 | * |
| 8043 | * On success, "locations" is filled in, but if the server has |
| 8044 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 8045 | * asserted. |
| 8046 | * |
| 8047 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 8048 | * from this client that require migration recovery. |
| 8049 | */ |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 8050 | int nfs4_proc_get_locations(struct nfs_server *server, |
| 8051 | struct nfs_fh *fhandle, |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8052 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8053 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8054 | { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8055 | struct nfs_client *clp = server->nfs_client; |
| 8056 | const struct nfs4_mig_recovery_ops *ops = |
| 8057 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8058 | struct nfs4_exception exception = { |
| 8059 | .interruptible = true, |
| 8060 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8061 | int status; |
| 8062 | |
| 8063 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 8064 | (unsigned long long)server->fsid.major, |
| 8065 | (unsigned long long)server->fsid.minor, |
| 8066 | clp->cl_hostname); |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 8067 | nfs_display_fhandle(fhandle, __func__); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8068 | |
| 8069 | do { |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 8070 | status = ops->get_locations(server, fhandle, locations, page, |
| 8071 | cred); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8072 | if (status != -NFS4ERR_DELAY) |
| 8073 | break; |
| 8074 | nfs4_handle_exception(server, status, &exception); |
| 8075 | } while (exception.retry); |
| 8076 | return status; |
| 8077 | } |
| 8078 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8079 | /* |
| 8080 | * This operation also signals the server that this client is |
| 8081 | * performing "lease moved" recovery. The server can stop |
| 8082 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 8083 | * is appended to this compound to identify the client ID which is |
| 8084 | * performing recovery. |
| 8085 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8086 | 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] | 8087 | { |
| 8088 | struct nfs_server *server = NFS_SERVER(inode); |
| 8089 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 8090 | struct rpc_clnt *clnt = server->client; |
| 8091 | struct nfs4_fsid_present_arg args = { |
| 8092 | .fh = NFS_FH(inode), |
| 8093 | .clientid = clp->cl_clientid, |
| 8094 | .renew = 1, /* append RENEW */ |
| 8095 | }; |
| 8096 | struct nfs4_fsid_present_res res = { |
| 8097 | .renew = 1, |
| 8098 | }; |
| 8099 | struct rpc_message msg = { |
| 8100 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 8101 | .rpc_argp = &args, |
| 8102 | .rpc_resp = &res, |
| 8103 | .rpc_cred = cred, |
| 8104 | }; |
| 8105 | unsigned long now = jiffies; |
| 8106 | int status; |
| 8107 | |
| 8108 | res.fh = nfs_alloc_fhandle(); |
| 8109 | if (res.fh == NULL) |
| 8110 | return -ENOMEM; |
| 8111 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8112 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8113 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 8114 | &args.seq_args, &res.seq_res); |
| 8115 | nfs_free_fhandle(res.fh); |
| 8116 | if (status) |
| 8117 | return status; |
| 8118 | |
| 8119 | do_renew_lease(clp, now); |
| 8120 | return 0; |
| 8121 | } |
| 8122 | |
| 8123 | #ifdef CONFIG_NFS_V4_1 |
| 8124 | |
| 8125 | /* |
| 8126 | * This operation also signals the server that this client is |
| 8127 | * performing "lease moved" recovery. The server can stop asserting |
| 8128 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 8129 | * this operation is identified in the SEQUENCE operation in this |
| 8130 | * compound. |
| 8131 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8132 | 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] | 8133 | { |
| 8134 | struct nfs_server *server = NFS_SERVER(inode); |
| 8135 | struct rpc_clnt *clnt = server->client; |
| 8136 | struct nfs4_fsid_present_arg args = { |
| 8137 | .fh = NFS_FH(inode), |
| 8138 | }; |
| 8139 | struct nfs4_fsid_present_res res = { |
| 8140 | }; |
| 8141 | struct rpc_message msg = { |
| 8142 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 8143 | .rpc_argp = &args, |
| 8144 | .rpc_resp = &res, |
| 8145 | .rpc_cred = cred, |
| 8146 | }; |
| 8147 | int status; |
| 8148 | |
| 8149 | res.fh = nfs_alloc_fhandle(); |
| 8150 | if (res.fh == NULL) |
| 8151 | return -ENOMEM; |
| 8152 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8153 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8154 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 8155 | &args.seq_args, &res.seq_res); |
| 8156 | nfs_free_fhandle(res.fh); |
| 8157 | if (status == NFS4_OK && |
| 8158 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 8159 | status = -NFS4ERR_LEASE_MOVED; |
| 8160 | return status; |
| 8161 | } |
| 8162 | |
| 8163 | #endif /* CONFIG_NFS_V4_1 */ |
| 8164 | |
| 8165 | /** |
| 8166 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 8167 | * @inode: inode on FSID to check |
| 8168 | * @cred: credential to use for this operation |
| 8169 | * |
| 8170 | * Server indicates whether the FSID is present, moved, or not |
| 8171 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 8172 | * condition for this client ID. |
| 8173 | * |
| 8174 | * Returns NFS4_OK if the FSID is present on this server, |
| 8175 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 8176 | * NFS4ERR code if some error occurred on the server, or a |
| 8177 | * negative errno if a local failure occurred. |
| 8178 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8179 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8180 | { |
| 8181 | struct nfs_server *server = NFS_SERVER(inode); |
| 8182 | struct nfs_client *clp = server->nfs_client; |
| 8183 | const struct nfs4_mig_recovery_ops *ops = |
| 8184 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8185 | struct nfs4_exception exception = { |
| 8186 | .interruptible = true, |
| 8187 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8188 | int status; |
| 8189 | |
| 8190 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 8191 | (unsigned long long)server->fsid.major, |
| 8192 | (unsigned long long)server->fsid.minor, |
| 8193 | clp->cl_hostname); |
| 8194 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 8195 | |
| 8196 | do { |
| 8197 | status = ops->fsid_present(inode, cred); |
| 8198 | if (status != -NFS4ERR_DELAY) |
| 8199 | break; |
| 8200 | nfs4_handle_exception(server, status, &exception); |
| 8201 | } while (exception.retry); |
| 8202 | return status; |
| 8203 | } |
| 8204 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 8205 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8206 | * If 'use_integrity' is true and the state managment nfs_client |
| 8207 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 8208 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 8209 | * Considerations sections. Otherwise, just use the user cred with the |
| 8210 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 8211 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8212 | 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] | 8213 | { |
| 8214 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8215 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 8216 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8217 | struct nfs4_secinfo_arg args = { |
| 8218 | .dir_fh = NFS_FH(dir), |
| 8219 | .name = name, |
| 8220 | }; |
| 8221 | struct nfs4_secinfo_res res = { |
| 8222 | .flavors = flavors, |
| 8223 | }; |
| 8224 | struct rpc_message msg = { |
| 8225 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 8226 | .rpc_argp = &args, |
| 8227 | .rpc_resp = &res, |
| 8228 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8229 | struct nfs4_call_sync_data data = { |
| 8230 | .seq_server = NFS_SERVER(dir), |
| 8231 | .seq_args = &args.seq_args, |
| 8232 | .seq_res = &res.seq_res, |
| 8233 | }; |
| 8234 | struct rpc_task_setup task_setup = { |
| 8235 | .rpc_client = clnt, |
| 8236 | .rpc_message = &msg, |
| 8237 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 8238 | .callback_data = &data, |
| 8239 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 8240 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8241 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8242 | |
| 8243 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8244 | clnt = clp->cl_rpcclient; |
| 8245 | task_setup.rpc_client = clnt; |
| 8246 | |
| 8247 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8248 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8249 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8250 | |
| 8251 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8252 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8253 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 8254 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 8255 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8256 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8257 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8258 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8259 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8260 | return status; |
| 8261 | } |
| 8262 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 8263 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 8264 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8265 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8266 | struct nfs4_exception exception = { |
| 8267 | .interruptible = true, |
| 8268 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8269 | int err; |
| 8270 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8271 | err = -NFS4ERR_WRONGSEC; |
| 8272 | |
| 8273 | /* try to use integrity protection with machine cred */ |
| 8274 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 8275 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 8276 | |
| 8277 | /* |
| 8278 | * if unable to use integrity protection, or SECINFO with |
| 8279 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8280 | * disallowed by spec, but exists in deployed servers) use |
| 8281 | * the current filesystem's rpc_client and the user cred. |
| 8282 | */ |
| 8283 | if (err == -NFS4ERR_WRONGSEC) |
| 8284 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 8285 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 8286 | trace_nfs4_secinfo(dir, name, err); |
| 8287 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8288 | &exception); |
| 8289 | } while (exception.retry); |
| 8290 | return err; |
| 8291 | } |
| 8292 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8293 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8294 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8295 | * Check the exchange flags returned by the server for invalid flags, having |
| 8296 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 8297 | * DS flags set. |
| 8298 | */ |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8299 | static int nfs4_check_cl_exchange_flags(u32 flags, u32 version) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8300 | { |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8301 | if (version >= 2 && (flags & ~EXCHGID4_2_FLAG_MASK_R)) |
| 8302 | goto out_inval; |
| 8303 | else if (version < 2 && (flags & ~EXCHGID4_FLAG_MASK_R)) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8304 | goto out_inval; |
| 8305 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 8306 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 8307 | goto out_inval; |
| 8308 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 8309 | goto out_inval; |
| 8310 | return NFS_OK; |
| 8311 | out_inval: |
| 8312 | return -NFS4ERR_INVAL; |
| 8313 | } |
| 8314 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8315 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 8316 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 8317 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8318 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 8319 | if (a->server_scope_sz != b->server_scope_sz) |
| 8320 | return false; |
| 8321 | 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] | 8322 | } |
| 8323 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8324 | static void |
| 8325 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 8326 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8327 | 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] | 8328 | 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] | 8329 | struct nfs_client *clp = args->client; |
| 8330 | |
| 8331 | switch (task->tk_status) { |
| 8332 | case -NFS4ERR_BADSESSION: |
| 8333 | case -NFS4ERR_DEADSESSION: |
| 8334 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8335 | task->tk_status); |
| 8336 | } |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8337 | if (args->dir == NFS4_CDFC4_FORE_OR_BOTH && |
| 8338 | res->dir != NFS4_CDFS4_BOTH) { |
| 8339 | rpc_task_close_connection(task); |
| 8340 | if (args->retries++ < MAX_BIND_CONN_TO_SESSION_RETRIES) |
| 8341 | rpc_restart_call(task); |
| 8342 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8343 | } |
| 8344 | |
| 8345 | 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] | 8346 | .rpc_call_done = nfs4_bind_one_conn_to_session_done, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8347 | }; |
| 8348 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8349 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8350 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8351 | * |
| 8352 | * The 4.1 client currently uses the same TCP connection for the |
| 8353 | * fore and backchannel. |
| 8354 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8355 | static |
| 8356 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 8357 | struct rpc_xprt *xprt, |
| 8358 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8359 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8360 | { |
| 8361 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8362 | struct nfs41_bind_conn_to_session_args args = { |
| 8363 | .client = clp, |
| 8364 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8365 | .retries = 0, |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8366 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8367 | struct nfs41_bind_conn_to_session_res res; |
| 8368 | struct rpc_message msg = { |
| 8369 | .rpc_proc = |
| 8370 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8371 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8372 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 8373 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8374 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8375 | struct rpc_task_setup task_setup_data = { |
| 8376 | .rpc_client = clnt, |
| 8377 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8378 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8379 | .rpc_message = &msg, |
| 8380 | .flags = RPC_TASK_TIMEOUT, |
| 8381 | }; |
| 8382 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8383 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8384 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 8385 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 8386 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8387 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8388 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 8389 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 8390 | args.dir = NFS4_CDFC4_FORE; |
| 8391 | |
| 8392 | task = rpc_run_task(&task_setup_data); |
| 8393 | if (!IS_ERR(task)) { |
| 8394 | status = task->tk_status; |
| 8395 | rpc_put_task(task); |
| 8396 | } else |
| 8397 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8398 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8399 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8400 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8401 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 8402 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8403 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8404 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8405 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8406 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 8407 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8408 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8409 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8410 | 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] | 8411 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 8412 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8413 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8414 | } |
| 8415 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8416 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8417 | return status; |
| 8418 | } |
| 8419 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8420 | struct rpc_bind_conn_calldata { |
| 8421 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8422 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8423 | }; |
| 8424 | |
| 8425 | static int |
| 8426 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 8427 | struct rpc_xprt *xprt, |
| 8428 | void *calldata) |
| 8429 | { |
| 8430 | struct rpc_bind_conn_calldata *p = calldata; |
| 8431 | |
| 8432 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 8433 | } |
| 8434 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8435 | 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] | 8436 | { |
| 8437 | struct rpc_bind_conn_calldata data = { |
| 8438 | .clp = clp, |
| 8439 | .cred = cred, |
| 8440 | }; |
| 8441 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 8442 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 8443 | } |
| 8444 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8445 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8446 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 8447 | * 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] | 8448 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8449 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 8450 | .how = SP4_MACH_CRED, |
| 8451 | .enforce.u.words = { |
| 8452 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8453 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8454 | 1 << (OP_CREATE_SESSION - 32) | |
| 8455 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8456 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8457 | }, |
| 8458 | .allow.u.words = { |
| 8459 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8460 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8461 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8462 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8463 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8464 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8465 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8466 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8467 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8468 | 1 << (OP_FREE_STATEID - 32) | |
| 8469 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8470 | } |
| 8471 | }; |
| 8472 | |
| 8473 | /* |
| 8474 | * Select the state protection mode for client `clp' given the server results |
| 8475 | * from exchange_id in `sp'. |
| 8476 | * |
| 8477 | * Returns 0 on success, negative errno otherwise. |
| 8478 | */ |
| 8479 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8480 | struct nfs41_state_protection *sp) |
| 8481 | { |
| 8482 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8483 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8484 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8485 | 1 << (OP_CREATE_SESSION - 32) | |
| 8486 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8487 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8488 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8489 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8490 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8491 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8492 | |
| 8493 | if (sp->how == SP4_MACH_CRED) { |
| 8494 | /* Print state protect result */ |
| 8495 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8496 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8497 | if (test_bit(i, sp->enforce.u.longs)) |
| 8498 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8499 | if (test_bit(i, sp->allow.u.longs)) |
| 8500 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8501 | } |
| 8502 | |
| 8503 | /* make sure nothing is on enforce list that isn't supported */ |
| 8504 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8505 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8506 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8507 | ret = -EINVAL; |
| 8508 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8509 | } |
| 8510 | } |
| 8511 | |
| 8512 | /* |
| 8513 | * Minimal mode - state operations are allowed to use machine |
| 8514 | * credential. Note this already happens by default, so the |
| 8515 | * client doesn't have to do anything more than the negotiation. |
| 8516 | * |
| 8517 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8518 | * we're already using the machine cred for exchange_id |
| 8519 | * and will never use a different cred. |
| 8520 | */ |
| 8521 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8522 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8523 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8524 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8525 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8526 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8527 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8528 | } else { |
| 8529 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8530 | ret = -EINVAL; |
| 8531 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8532 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8533 | |
| 8534 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8535 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8536 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8537 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8538 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8539 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8540 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8541 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8542 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8543 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8544 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8545 | } |
| 8546 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8547 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8548 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8549 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8550 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8551 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8552 | |
| 8553 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8554 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8555 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8556 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8557 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8558 | |
| 8559 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8560 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8561 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8562 | } |
| 8563 | |
| 8564 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8565 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8566 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8567 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8568 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8569 | out: |
| 8570 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8571 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8572 | } |
| 8573 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8574 | struct nfs41_exchange_id_data { |
| 8575 | struct nfs41_exchange_id_res res; |
| 8576 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8577 | }; |
| 8578 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8579 | static void nfs4_exchange_id_release(void *data) |
| 8580 | { |
| 8581 | struct nfs41_exchange_id_data *cdata = |
| 8582 | (struct nfs41_exchange_id_data *)data; |
| 8583 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8584 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8585 | kfree(cdata->res.impl_id); |
| 8586 | kfree(cdata->res.server_scope); |
| 8587 | kfree(cdata->res.server_owner); |
| 8588 | kfree(cdata); |
| 8589 | } |
| 8590 | |
| 8591 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8592 | .rpc_release = nfs4_exchange_id_release, |
| 8593 | }; |
| 8594 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8595 | /* |
| 8596 | * _nfs4_proc_exchange_id() |
| 8597 | * |
| 8598 | * Wrapper for EXCHANGE_ID operation. |
| 8599 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8600 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8601 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8602 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8603 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8604 | struct rpc_message msg = { |
| 8605 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8606 | .rpc_cred = cred, |
| 8607 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8608 | struct rpc_task_setup task_setup_data = { |
| 8609 | .rpc_client = clp->cl_rpcclient, |
| 8610 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8611 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8612 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8613 | }; |
| 8614 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8615 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8616 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8617 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8618 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8619 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8620 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8621 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8622 | if (!calldata) |
| 8623 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8624 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8625 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8626 | |
| 8627 | status = nfs4_init_uniform_client_string(clp); |
| 8628 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8629 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8630 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8631 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8632 | GFP_NOFS); |
| 8633 | status = -ENOMEM; |
| 8634 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8635 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8636 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8637 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8638 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8639 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8640 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8641 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8642 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8643 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8644 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8645 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8646 | switch (sp4_how) { |
| 8647 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8648 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8649 | break; |
| 8650 | |
| 8651 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8652 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8653 | break; |
| 8654 | |
| 8655 | default: |
| 8656 | /* unsupported! */ |
| 8657 | WARN_ON_ONCE(1); |
| 8658 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8659 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8660 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8661 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8662 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8663 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8664 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8665 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8666 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8667 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8668 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8669 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8670 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8671 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8672 | #endif |
| 8673 | msg.rpc_argp = &calldata->args; |
| 8674 | msg.rpc_resp = &calldata->res; |
| 8675 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8676 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8677 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8678 | |
| 8679 | out_impl_id: |
| 8680 | kfree(calldata->res.impl_id); |
| 8681 | out_server_scope: |
| 8682 | kfree(calldata->res.server_scope); |
| 8683 | out_server_owner: |
| 8684 | kfree(calldata->res.server_owner); |
| 8685 | out_calldata: |
| 8686 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8687 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8688 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8689 | return ERR_PTR(status); |
| 8690 | } |
| 8691 | |
| 8692 | /* |
| 8693 | * _nfs4_proc_exchange_id() |
| 8694 | * |
| 8695 | * Wrapper for EXCHANGE_ID operation. |
| 8696 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8697 | 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] | 8698 | u32 sp4_how) |
| 8699 | { |
| 8700 | struct rpc_task *task; |
| 8701 | struct nfs41_exchange_id_args *argp; |
| 8702 | struct nfs41_exchange_id_res *resp; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8703 | unsigned long now = jiffies; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8704 | int status; |
| 8705 | |
| 8706 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8707 | if (IS_ERR(task)) |
| 8708 | return PTR_ERR(task); |
| 8709 | |
| 8710 | argp = task->tk_msg.rpc_argp; |
| 8711 | resp = task->tk_msg.rpc_resp; |
| 8712 | status = task->tk_status; |
| 8713 | if (status != 0) |
| 8714 | goto out; |
| 8715 | |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8716 | status = nfs4_check_cl_exchange_flags(resp->flags, |
| 8717 | clp->cl_mvops->minor_version); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8718 | if (status != 0) |
| 8719 | goto out; |
| 8720 | |
| 8721 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8722 | if (status != 0) |
| 8723 | goto out; |
| 8724 | |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8725 | do_renew_lease(clp, now); |
| 8726 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8727 | clp->cl_clientid = resp->clientid; |
| 8728 | clp->cl_exchange_flags = resp->flags; |
| 8729 | clp->cl_seqid = resp->seqid; |
| 8730 | /* Client ID is not confirmed */ |
| 8731 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8732 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8733 | &clp->cl_session->session_state); |
| 8734 | |
| 8735 | if (clp->cl_serverscope != NULL && |
| 8736 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8737 | resp->server_scope)) { |
| 8738 | dprintk("%s: server_scope mismatch detected\n", |
| 8739 | __func__); |
| 8740 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8741 | } |
| 8742 | |
| 8743 | swap(clp->cl_serverowner, resp->server_owner); |
| 8744 | swap(clp->cl_serverscope, resp->server_scope); |
| 8745 | swap(clp->cl_implid, resp->impl_id); |
| 8746 | |
| 8747 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8748 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8749 | sizeof(clp->cl_confirm.data)); |
| 8750 | out: |
| 8751 | trace_nfs4_exchange_id(clp, status); |
| 8752 | rpc_put_task(task); |
| 8753 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8754 | } |
| 8755 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8756 | /* |
| 8757 | * nfs4_proc_exchange_id() |
| 8758 | * |
| 8759 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8760 | * |
| 8761 | * Since the clientid has expired, all compounds using sessions |
| 8762 | * associated with the stale clientid will be returning |
| 8763 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8764 | * be in some phase of session reset. |
| 8765 | * |
| 8766 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8767 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8768 | 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] | 8769 | { |
| 8770 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8771 | int status; |
| 8772 | |
| 8773 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8774 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8775 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8776 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8777 | if (!status) |
| 8778 | return 0; |
| 8779 | } |
| 8780 | |
| 8781 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8782 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8783 | } |
| 8784 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8785 | /** |
| 8786 | * nfs4_test_session_trunk |
| 8787 | * |
| 8788 | * This is an add_xprt_test() test function called from |
| 8789 | * rpc_clnt_setup_test_and_add_xprt. |
| 8790 | * |
| 8791 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8792 | * and is dereferrenced in nfs4_exchange_id_release |
| 8793 | * |
| 8794 | * Upon success, add the new transport to the rpc_clnt |
| 8795 | * |
| 8796 | * @clnt: struct rpc_clnt to get new transport |
| 8797 | * @xprt: the rpc_xprt to test |
| 8798 | * @data: call data for _nfs4_proc_exchange_id. |
| 8799 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8800 | 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] | 8801 | void *data) |
| 8802 | { |
| 8803 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8804 | struct rpc_task *task; |
| 8805 | int status; |
| 8806 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8807 | u32 sp4_how; |
| 8808 | |
| 8809 | dprintk("--> %s try %s\n", __func__, |
| 8810 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8811 | |
| 8812 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8813 | |
| 8814 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8815 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8816 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8817 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8818 | |
| 8819 | status = task->tk_status; |
| 8820 | if (status == 0) |
| 8821 | status = nfs4_detect_session_trunking(adata->clp, |
| 8822 | task->tk_msg.rpc_resp, xprt); |
| 8823 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8824 | if (status == 0) |
| 8825 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8826 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8827 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8828 | } |
| 8829 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8830 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8831 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8832 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8833 | { |
| 8834 | struct rpc_message msg = { |
| 8835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8836 | .rpc_argp = clp, |
| 8837 | .rpc_cred = cred, |
| 8838 | }; |
| 8839 | int status; |
| 8840 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8841 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8842 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8843 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8844 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8845 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8846 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8847 | return status; |
| 8848 | } |
| 8849 | |
| 8850 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8851 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8852 | { |
| 8853 | unsigned int loop; |
| 8854 | int ret; |
| 8855 | |
| 8856 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8857 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8858 | switch (ret) { |
| 8859 | case -NFS4ERR_DELAY: |
| 8860 | case -NFS4ERR_CLIENTID_BUSY: |
| 8861 | ssleep(1); |
| 8862 | break; |
| 8863 | default: |
| 8864 | return ret; |
| 8865 | } |
| 8866 | } |
| 8867 | return 0; |
| 8868 | } |
| 8869 | |
| 8870 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8871 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8872 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8873 | int ret = 0; |
| 8874 | |
| 8875 | if (clp->cl_mvops->minor_version < 1) |
| 8876 | goto out; |
| 8877 | if (clp->cl_exchange_flags == 0) |
| 8878 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8879 | if (clp->cl_preserve_clid) |
| 8880 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8881 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8882 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8883 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8884 | switch (ret) { |
| 8885 | case 0: |
| 8886 | case -NFS4ERR_STALE_CLIENTID: |
| 8887 | clp->cl_exchange_flags = 0; |
| 8888 | } |
| 8889 | out: |
| 8890 | return ret; |
| 8891 | } |
| 8892 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8893 | #endif /* CONFIG_NFS_V4_1 */ |
| 8894 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8895 | struct nfs4_get_lease_time_data { |
| 8896 | struct nfs4_get_lease_time_args *args; |
| 8897 | struct nfs4_get_lease_time_res *res; |
| 8898 | struct nfs_client *clp; |
| 8899 | }; |
| 8900 | |
| 8901 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8902 | void *calldata) |
| 8903 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8904 | struct nfs4_get_lease_time_data *data = |
| 8905 | (struct nfs4_get_lease_time_data *)calldata; |
| 8906 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8907 | /* just setup sequence, do not trigger session recovery |
| 8908 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8909 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8910 | &data->args->la_seq_args, |
| 8911 | &data->res->lr_seq_res, |
| 8912 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8913 | } |
| 8914 | |
| 8915 | /* |
| 8916 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8917 | * from sequence operation or clientid errors. |
| 8918 | */ |
| 8919 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8920 | { |
| 8921 | struct nfs4_get_lease_time_data *data = |
| 8922 | (struct nfs4_get_lease_time_data *)calldata; |
| 8923 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8924 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8925 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8926 | switch (task->tk_status) { |
| 8927 | case -NFS4ERR_DELAY: |
| 8928 | case -NFS4ERR_GRACE: |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8929 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8930 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 8931 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8932 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8933 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8934 | return; |
| 8935 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8936 | } |
| 8937 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8938 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8939 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8940 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8941 | }; |
| 8942 | |
| 8943 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8944 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8945 | struct nfs4_get_lease_time_args args; |
| 8946 | struct nfs4_get_lease_time_res res = { |
| 8947 | .lr_fsinfo = fsinfo, |
| 8948 | }; |
| 8949 | struct nfs4_get_lease_time_data data = { |
| 8950 | .args = &args, |
| 8951 | .res = &res, |
| 8952 | .clp = clp, |
| 8953 | }; |
| 8954 | struct rpc_message msg = { |
| 8955 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8956 | .rpc_argp = &args, |
| 8957 | .rpc_resp = &res, |
| 8958 | }; |
| 8959 | struct rpc_task_setup task_setup = { |
| 8960 | .rpc_client = clp->cl_rpcclient, |
| 8961 | .rpc_message = &msg, |
| 8962 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8963 | .callback_data = &data, |
| 8964 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8965 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8966 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8967 | 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] | 8968 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8969 | } |
| 8970 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8971 | #ifdef CONFIG_NFS_V4_1 |
| 8972 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8973 | /* |
| 8974 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8975 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8976 | * use them. |
| 8977 | * |
| 8978 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8979 | * always set csa_cachethis to FALSE because the current implementation |
| 8980 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8981 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8982 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8983 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8984 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8985 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8986 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8987 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8988 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8989 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8990 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8991 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8992 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8993 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8994 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8995 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8996 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8997 | |
| 8998 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8999 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9000 | __func__, |
| 9001 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 9002 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9003 | |
| 9004 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 9005 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 9006 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9007 | args->bc_attrs.max_resp_sz_cached = 0; |
| 9008 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 9009 | 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] | 9010 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 9011 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9012 | |
| 9013 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 9014 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 9015 | __func__, |
| 9016 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 9017 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 9018 | args->bc_attrs.max_reqs); |
| 9019 | } |
| 9020 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9021 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 9022 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9023 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9024 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9025 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9026 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9027 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 9028 | return -EINVAL; |
| 9029 | /* |
| 9030 | * Our requested max_ops is the minimum we need; we're not |
| 9031 | * prepared to break up compounds into smaller pieces than that. |
| 9032 | * So, no point even trying to continue if the server won't |
| 9033 | * cooperate: |
| 9034 | */ |
| 9035 | if (rcvd->max_ops < sent->max_ops) |
| 9036 | return -EINVAL; |
| 9037 | if (rcvd->max_reqs == 0) |
| 9038 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 9039 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 9040 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9041 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9042 | } |
| 9043 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9044 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 9045 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9046 | { |
| 9047 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9048 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9049 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 9050 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 9051 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9052 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 9053 | return -EINVAL; |
| 9054 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 9055 | return -EINVAL; |
| 9056 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 9057 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 9058 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9059 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 9060 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9061 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 9062 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9063 | return 0; |
| 9064 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9065 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9066 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9067 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9068 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9069 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9070 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9071 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 9072 | if (ret) |
| 9073 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9074 | return nfs4_verify_back_channel_attrs(args, res); |
| 9075 | } |
| 9076 | |
| 9077 | static void nfs4_update_session(struct nfs4_session *session, |
| 9078 | struct nfs41_create_session_res *res) |
| 9079 | { |
| 9080 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 9081 | /* Mark client id and session as being confirmed */ |
| 9082 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 9083 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9084 | session->flags = res->flags; |
| 9085 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 9086 | if (res->flags & SESSION4_BACK_CHAN) |
| 9087 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 9088 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9089 | } |
| 9090 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9091 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9092 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9093 | { |
| 9094 | struct nfs4_session *session = clp->cl_session; |
| 9095 | struct nfs41_create_session_args args = { |
| 9096 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9097 | .clientid = clp->cl_clientid, |
| 9098 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9099 | .cb_program = NFS4_CALLBACK, |
| 9100 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9101 | struct nfs41_create_session_res res; |
| 9102 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9103 | struct rpc_message msg = { |
| 9104 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 9105 | .rpc_argp = &args, |
| 9106 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9107 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9108 | }; |
| 9109 | int status; |
| 9110 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 9111 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 9112 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9113 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9114 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9115 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9116 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9117 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 9118 | switch (status) { |
| 9119 | case -NFS4ERR_STALE_CLIENTID: |
| 9120 | case -NFS4ERR_DELAY: |
| 9121 | case -ETIMEDOUT: |
| 9122 | case -EACCES: |
| 9123 | case -EAGAIN: |
| 9124 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 9125 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 9126 | |
| 9127 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 9128 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 9129 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9130 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9131 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9132 | if (status) |
| 9133 | goto out; |
| 9134 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9135 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 9136 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9137 | return status; |
| 9138 | } |
| 9139 | |
| 9140 | /* |
| 9141 | * Issues a CREATE_SESSION operation to the server. |
| 9142 | * It is the responsibility of the caller to verify the session is |
| 9143 | * expired before calling this routine. |
| 9144 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9145 | 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] | 9146 | { |
| 9147 | int status; |
| 9148 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9149 | struct nfs4_session *session = clp->cl_session; |
| 9150 | |
| 9151 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 9152 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9153 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9154 | if (status) |
| 9155 | goto out; |
| 9156 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 9157 | /* Init or reset the session slot tables */ |
| 9158 | status = nfs4_setup_session_slot_tables(session); |
| 9159 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9160 | if (status) |
| 9161 | goto out; |
| 9162 | |
| 9163 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 9164 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 9165 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9166 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9167 | return status; |
| 9168 | } |
| 9169 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9170 | /* |
| 9171 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 9172 | * The caller must serialize access to this routine. |
| 9173 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9174 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9175 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9176 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9177 | struct rpc_message msg = { |
| 9178 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 9179 | .rpc_argp = session, |
| 9180 | .rpc_cred = cred, |
| 9181 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9182 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9183 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9184 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 9185 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 9186 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9187 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9188 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9189 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9190 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9191 | |
| 9192 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 9193 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9194 | "Session has been destroyed regardless...\n", status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9195 | return status; |
| 9196 | } |
| 9197 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 9198 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9199 | * Renew the cl_session lease. |
| 9200 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9201 | struct nfs4_sequence_data { |
| 9202 | struct nfs_client *clp; |
| 9203 | struct nfs4_sequence_args args; |
| 9204 | struct nfs4_sequence_res res; |
| 9205 | }; |
| 9206 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9207 | static void nfs41_sequence_release(void *data) |
| 9208 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9209 | struct nfs4_sequence_data *calldata = data; |
| 9210 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9211 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9212 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9213 | nfs4_schedule_state_renewal(clp); |
| 9214 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9215 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9216 | } |
| 9217 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9218 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9219 | { |
| 9220 | switch(task->tk_status) { |
| 9221 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9222 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 9223 | return -EAGAIN; |
| 9224 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9225 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9226 | } |
| 9227 | return 0; |
| 9228 | } |
| 9229 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9230 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9231 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9232 | struct nfs4_sequence_data *calldata = data; |
| 9233 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9234 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9235 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 9236 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9237 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9238 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9239 | if (task->tk_status < 0) { |
| 9240 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9241 | if (refcount_read(&clp->cl_count) == 1) |
Chuck Lever | 86882c7 | 2021-10-16 18:03:04 -0400 | [diff] [blame] | 9242 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9243 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9244 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 9245 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9246 | return; |
| 9247 | } |
| 9248 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9249 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9250 | } |
| 9251 | |
| 9252 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 9253 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9254 | struct nfs4_sequence_data *calldata = data; |
| 9255 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9256 | struct nfs4_sequence_args *args; |
| 9257 | struct nfs4_sequence_res *res; |
| 9258 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9259 | args = task->tk_msg.rpc_argp; |
| 9260 | res = task->tk_msg.rpc_resp; |
| 9261 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9262 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9263 | } |
| 9264 | |
| 9265 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 9266 | .rpc_call_done = nfs41_sequence_call_done, |
| 9267 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9268 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9269 | }; |
| 9270 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9271 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9272 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9273 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9274 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9275 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9276 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9277 | struct rpc_message msg = { |
| 9278 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 9279 | .rpc_cred = cred, |
| 9280 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9281 | struct rpc_task_setup task_setup_data = { |
| 9282 | .rpc_client = clp->cl_rpcclient, |
| 9283 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9284 | .callback_ops = &nfs41_sequence_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9285 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT | RPC_TASK_MOVEABLE, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9286 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9287 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9288 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9289 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9290 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9291 | goto out_err; |
| 9292 | |
| 9293 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 9294 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9295 | if (calldata == NULL) |
| 9296 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9297 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9298 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9299 | msg.rpc_argp = &calldata->args; |
| 9300 | msg.rpc_resp = &calldata->res; |
| 9301 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9302 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9303 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9304 | ret = rpc_run_task(&task_setup_data); |
| 9305 | if (IS_ERR(ret)) |
| 9306 | goto out_err; |
| 9307 | return ret; |
| 9308 | out_put_clp: |
| 9309 | nfs_put_client(clp); |
| 9310 | out_err: |
| 9311 | nfs41_release_slot(slot); |
| 9312 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9313 | } |
| 9314 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9315 | 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] | 9316 | { |
| 9317 | struct rpc_task *task; |
| 9318 | int ret = 0; |
| 9319 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 9320 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 9321 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9322 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9323 | if (IS_ERR(task)) |
| 9324 | ret = PTR_ERR(task); |
| 9325 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 9326 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9327 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9328 | return ret; |
| 9329 | } |
| 9330 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9331 | 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] | 9332 | { |
| 9333 | struct rpc_task *task; |
| 9334 | int ret; |
| 9335 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9336 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9337 | if (IS_ERR(task)) { |
| 9338 | ret = PTR_ERR(task); |
| 9339 | goto out; |
| 9340 | } |
| 9341 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 9342 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9343 | ret = task->tk_status; |
| 9344 | rpc_put_task(task); |
| 9345 | out: |
| 9346 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9347 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9348 | } |
| 9349 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9350 | struct nfs4_reclaim_complete_data { |
| 9351 | struct nfs_client *clp; |
| 9352 | struct nfs41_reclaim_complete_args arg; |
| 9353 | struct nfs41_reclaim_complete_res res; |
| 9354 | }; |
| 9355 | |
| 9356 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 9357 | { |
| 9358 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9359 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9360 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9361 | &calldata->arg.seq_args, |
| 9362 | &calldata->res.seq_res, |
| 9363 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9364 | } |
| 9365 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9366 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9367 | { |
| 9368 | switch(task->tk_status) { |
| 9369 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 9370 | wake_up_all(&clp->cl_lock_waitq); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9371 | fallthrough; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9372 | case -NFS4ERR_COMPLETE_ALREADY: |
| 9373 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 9374 | break; |
| 9375 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9376 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9377 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 9378 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9379 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9380 | case -NFS4ERR_BADSESSION: |
| 9381 | case -NFS4ERR_DEADSESSION: |
| 9382 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9383 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9384 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9385 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9386 | } |
| 9387 | return 0; |
| 9388 | } |
| 9389 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9390 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 9391 | { |
| 9392 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9393 | struct nfs_client *clp = calldata->clp; |
| 9394 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 9395 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9396 | if (!nfs41_sequence_done(task, res)) |
| 9397 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9398 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9399 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9400 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 9401 | rpc_restart_call_prepare(task); |
| 9402 | return; |
| 9403 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9404 | } |
| 9405 | |
| 9406 | static void nfs4_free_reclaim_complete_data(void *data) |
| 9407 | { |
| 9408 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9409 | |
| 9410 | kfree(calldata); |
| 9411 | } |
| 9412 | |
| 9413 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 9414 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 9415 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 9416 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 9417 | }; |
| 9418 | |
| 9419 | /* |
| 9420 | * Issue a global reclaim complete. |
| 9421 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9422 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9423 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9424 | { |
| 9425 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9426 | struct rpc_message msg = { |
| 9427 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9428 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9429 | }; |
| 9430 | struct rpc_task_setup task_setup_data = { |
| 9431 | .rpc_client = clp->cl_rpcclient, |
| 9432 | .rpc_message = &msg, |
| 9433 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9434 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9435 | }; |
| 9436 | int status = -ENOMEM; |
| 9437 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 9438 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9439 | if (calldata == NULL) |
| 9440 | goto out; |
| 9441 | calldata->clp = clp; |
| 9442 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9443 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9444 | 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] | 9445 | msg.rpc_argp = &calldata->arg; |
| 9446 | msg.rpc_resp = &calldata->res; |
| 9447 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9448 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9449 | out: |
| 9450 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9451 | return status; |
| 9452 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9453 | |
| 9454 | static void |
| 9455 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9456 | { |
| 9457 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9458 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9459 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9460 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9461 | &lgp->res.seq_res, task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9462 | } |
| 9463 | |
| 9464 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9465 | { |
| 9466 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9467 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9468 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9469 | } |
| 9470 | |
| 9471 | static int |
| 9472 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9473 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9474 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9475 | struct inode *inode = lgp->args.inode; |
| 9476 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4e89bc | 2021-07-02 17:24:22 -0400 | [diff] [blame] | 9477 | struct pnfs_layout_hdr *lo = lgp->lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9478 | int nfs4err = task->tk_status; |
| 9479 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9480 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9481 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9482 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9483 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9484 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9485 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9486 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9487 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9488 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9489 | |
| 9490 | /* |
| 9491 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9492 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9493 | * retry go inband. |
| 9494 | */ |
| 9495 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9496 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9497 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9498 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9499 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9500 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9501 | */ |
| 9502 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9503 | status = -EOVERFLOW; |
| 9504 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9505 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9506 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9507 | * (or clients) writing to the same RAID stripe except when |
| 9508 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9509 | * |
| 9510 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9511 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9512 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9513 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9514 | if (lgp->args.minlength == 0) { |
| 9515 | status = -EOVERFLOW; |
| 9516 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9517 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9518 | status = -EBUSY; |
| 9519 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9520 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9521 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9522 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9523 | case -NFS4ERR_DELEG_REVOKED: |
| 9524 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9525 | case -NFS4ERR_EXPIRED: |
| 9526 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9527 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9528 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9529 | /* If the open stateid was bad, then recover it. */ |
| 9530 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9531 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9532 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9533 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9534 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9535 | break; |
| 9536 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9537 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9538 | /* |
| 9539 | * Mark the bad layout state as invalid, then retry |
| 9540 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9541 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9542 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9543 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9544 | pnfs_free_lseg_list(&head); |
| 9545 | status = -EAGAIN; |
| 9546 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9547 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9548 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9549 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9550 | if (!status) { |
| 9551 | if (exception->retry) |
| 9552 | status = -EAGAIN; |
| 9553 | else |
| 9554 | status = err; |
| 9555 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9556 | out: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9557 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9558 | } |
| 9559 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9560 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9561 | { |
| 9562 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9563 | return nfs_page_array_len(0, max_resp_sz); |
| 9564 | } |
| 9565 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9566 | static void nfs4_layoutget_release(void *calldata) |
| 9567 | { |
| 9568 | struct nfs4_layoutget *lgp = calldata; |
| 9569 | |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9570 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9571 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9572 | } |
| 9573 | |
| 9574 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9575 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9576 | .rpc_call_done = nfs4_layoutget_done, |
| 9577 | .rpc_release = nfs4_layoutget_release, |
| 9578 | }; |
| 9579 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9580 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9581 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9582 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9583 | struct inode *inode = lgp->args.inode; |
| 9584 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9585 | struct rpc_task *task; |
| 9586 | struct rpc_message msg = { |
| 9587 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9588 | .rpc_argp = &lgp->args, |
| 9589 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9590 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9591 | }; |
| 9592 | struct rpc_task_setup task_setup_data = { |
| 9593 | .rpc_client = server->client, |
| 9594 | .rpc_message = &msg, |
| 9595 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9596 | .callback_data = lgp, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9597 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF | |
| 9598 | RPC_TASK_MOVEABLE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9599 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9600 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9601 | struct nfs4_exception exception = { |
| 9602 | .inode = inode, |
| 9603 | .timeout = *timeout, |
| 9604 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9605 | int status = 0; |
| 9606 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9607 | 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] | 9608 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9609 | task = rpc_run_task(&task_setup_data); |
Xiyu Yang | 6e47666 | 2020-04-25 21:04:40 +0800 | [diff] [blame] | 9610 | |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9611 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9612 | if (status != 0) |
| 9613 | goto out; |
| 9614 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9615 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9616 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9617 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9618 | } else if (lgp->res.layoutp->len == 0) { |
| 9619 | status = -EAGAIN; |
| 9620 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9621 | } else |
| 9622 | lseg = pnfs_layout_process(lgp); |
| 9623 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9624 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9625 | &lgp->args.range, |
| 9626 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9627 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9628 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9629 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9630 | rpc_put_task(task); |
| 9631 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9632 | if (status) |
| 9633 | return ERR_PTR(status); |
| 9634 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9635 | } |
| 9636 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9637 | static void |
| 9638 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9639 | { |
| 9640 | struct nfs4_layoutreturn *lrp = calldata; |
| 9641 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9642 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9643 | &lrp->args.seq_args, |
| 9644 | &lrp->res.seq_res, |
| 9645 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9646 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9647 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9648 | } |
| 9649 | |
| 9650 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9651 | { |
| 9652 | struct nfs4_layoutreturn *lrp = calldata; |
| 9653 | struct nfs_server *server; |
| 9654 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9655 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9656 | return; |
| 9657 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9658 | /* |
| 9659 | * Was there an RPC level error? Assume the call succeeded, |
| 9660 | * and that we need to release the layout |
| 9661 | */ |
| 9662 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9663 | lrp->res.lrs_present = 0; |
| 9664 | return; |
| 9665 | } |
| 9666 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9667 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9668 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9669 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9670 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9671 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9672 | lrp->args.inode)) |
| 9673 | goto out_restart; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9674 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9675 | default: |
| 9676 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9677 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9678 | case 0: |
| 9679 | break; |
| 9680 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9681 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9682 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9683 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9684 | } |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9685 | return; |
| 9686 | out_restart: |
| 9687 | task->tk_status = 0; |
| 9688 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9689 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9690 | } |
| 9691 | |
| 9692 | static void nfs4_layoutreturn_release(void *calldata) |
| 9693 | { |
| 9694 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9695 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9696 | |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9697 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9698 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9699 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9700 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9701 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9702 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9703 | nfs_iput_and_deactive(lrp->inode); |
Trond Myklebust | 44ea8df | 2020-04-02 15:37:02 -0400 | [diff] [blame] | 9704 | put_cred(lrp->cred); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9705 | kfree(calldata); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9706 | } |
| 9707 | |
| 9708 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9709 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9710 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9711 | .rpc_release = nfs4_layoutreturn_release, |
| 9712 | }; |
| 9713 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9714 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9715 | { |
| 9716 | struct rpc_task *task; |
| 9717 | struct rpc_message msg = { |
| 9718 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9719 | .rpc_argp = &lrp->args, |
| 9720 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9721 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9722 | }; |
| 9723 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9724 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9725 | .rpc_message = &msg, |
| 9726 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9727 | .callback_data = lrp, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9728 | .flags = RPC_TASK_MOVEABLE, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9729 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9730 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9731 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9732 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9733 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9734 | &task_setup_data.rpc_client, &msg); |
| 9735 | |
Trond Myklebust | c3aba89 | 2021-06-01 11:35:56 -0400 | [diff] [blame] | 9736 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9737 | if (!sync) { |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9738 | if (!lrp->inode) { |
| 9739 | nfs4_layoutreturn_release(lrp); |
| 9740 | return -EAGAIN; |
| 9741 | } |
| 9742 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9743 | } |
Trond Myklebust | c3aba89 | 2021-06-01 11:35:56 -0400 | [diff] [blame] | 9744 | if (!lrp->inode) |
| 9745 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, |
| 9746 | 1); |
| 9747 | else |
| 9748 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, |
| 9749 | 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9750 | task = rpc_run_task(&task_setup_data); |
| 9751 | if (IS_ERR(task)) |
| 9752 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9753 | if (sync) |
| 9754 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9755 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9756 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9757 | rpc_put_task(task); |
| 9758 | return status; |
| 9759 | } |
| 9760 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9761 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9762 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9763 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9764 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9765 | { |
| 9766 | struct nfs4_getdeviceinfo_args args = { |
| 9767 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9768 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9769 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9770 | }; |
| 9771 | struct nfs4_getdeviceinfo_res res = { |
| 9772 | .pdev = pdev, |
| 9773 | }; |
| 9774 | struct rpc_message msg = { |
| 9775 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9776 | .rpc_argp = &args, |
| 9777 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9778 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9779 | }; |
| 9780 | int status; |
| 9781 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9782 | 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] | 9783 | if (res.notification & ~args.notify_types) |
| 9784 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9785 | if (res.notification != args.notify_types) |
| 9786 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9787 | |
Trond Myklebust | cac1d3a | 2020-12-16 16:31:26 -0500 | [diff] [blame] | 9788 | trace_nfs4_getdeviceinfo(server, &pdev->dev_id, status); |
| 9789 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9790 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9791 | |
| 9792 | return status; |
| 9793 | } |
| 9794 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9795 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9796 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9797 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9798 | { |
| 9799 | struct nfs4_exception exception = { }; |
| 9800 | int err; |
| 9801 | |
| 9802 | do { |
| 9803 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9804 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9805 | &exception); |
| 9806 | } while (exception.retry); |
| 9807 | return err; |
| 9808 | } |
| 9809 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9810 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9811 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9812 | { |
| 9813 | struct nfs4_layoutcommit_data *data = calldata; |
| 9814 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9815 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9816 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9817 | &data->args.seq_args, |
| 9818 | &data->res.seq_res, |
| 9819 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9820 | } |
| 9821 | |
| 9822 | static void |
| 9823 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9824 | { |
| 9825 | struct nfs4_layoutcommit_data *data = calldata; |
| 9826 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9827 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9828 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9829 | return; |
| 9830 | |
| 9831 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9832 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9833 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9834 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9835 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9836 | task->tk_status = 0; |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame] | 9837 | break; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9838 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9839 | break; |
| 9840 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9841 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9842 | rpc_restart_call_prepare(task); |
| 9843 | return; |
| 9844 | } |
| 9845 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9846 | } |
| 9847 | |
| 9848 | static void nfs4_layoutcommit_release(void *calldata) |
| 9849 | { |
| 9850 | struct nfs4_layoutcommit_data *data = calldata; |
| 9851 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9852 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9853 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9854 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9855 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9856 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9857 | kfree(data); |
| 9858 | } |
| 9859 | |
| 9860 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9861 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9862 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9863 | .rpc_release = nfs4_layoutcommit_release, |
| 9864 | }; |
| 9865 | |
| 9866 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9867 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9868 | { |
| 9869 | struct rpc_message msg = { |
| 9870 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9871 | .rpc_argp = &data->args, |
| 9872 | .rpc_resp = &data->res, |
| 9873 | .rpc_cred = data->cred, |
| 9874 | }; |
| 9875 | struct rpc_task_setup task_setup_data = { |
| 9876 | .task = &data->task, |
| 9877 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9878 | .rpc_message = &msg, |
| 9879 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9880 | .callback_data = data, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 9881 | .flags = RPC_TASK_MOVEABLE, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9882 | }; |
| 9883 | struct rpc_task *task; |
| 9884 | int status = 0; |
| 9885 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9886 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9887 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9888 | data->args.lastbytewritten, |
| 9889 | data->args.inode->i_ino); |
| 9890 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9891 | if (!sync) { |
| 9892 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9893 | if (data->inode == NULL) { |
| 9894 | nfs4_layoutcommit_release(data); |
| 9895 | return -EAGAIN; |
| 9896 | } |
| 9897 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9898 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9899 | 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] | 9900 | task = rpc_run_task(&task_setup_data); |
| 9901 | if (IS_ERR(task)) |
| 9902 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9903 | if (sync) |
| 9904 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9905 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9906 | dprintk("%s: status %d\n", __func__, status); |
| 9907 | rpc_put_task(task); |
| 9908 | return status; |
| 9909 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9910 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9911 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9912 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9913 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9914 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9915 | static int |
| 9916 | _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] | 9917 | struct nfs_fsinfo *info, |
| 9918 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9919 | { |
| 9920 | struct nfs41_secinfo_no_name_args args = { |
| 9921 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9922 | }; |
| 9923 | struct nfs4_secinfo_res res = { |
| 9924 | .flavors = flavors, |
| 9925 | }; |
| 9926 | struct rpc_message msg = { |
| 9927 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9928 | .rpc_argp = &args, |
| 9929 | .rpc_resp = &res, |
| 9930 | }; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9931 | struct nfs4_call_sync_data data = { |
| 9932 | .seq_server = server, |
| 9933 | .seq_args = &args.seq_args, |
| 9934 | .seq_res = &res.seq_res, |
| 9935 | }; |
| 9936 | struct rpc_task_setup task_setup = { |
| 9937 | .rpc_client = server->client, |
| 9938 | .rpc_message = &msg, |
| 9939 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9940 | .callback_data = &data, |
| 9941 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9942 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9943 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9944 | int status; |
| 9945 | |
| 9946 | if (use_integrity) { |
Colin Ian King | 48bb6ec | 2020-06-10 00:22:57 +0100 | [diff] [blame] | 9947 | task_setup.rpc_client = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9948 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9949 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9950 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9951 | } |
| 9952 | |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9953 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9954 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9955 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9956 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9957 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9958 | |
| 9959 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9960 | } |
| 9961 | |
| 9962 | static int |
| 9963 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9964 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9965 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9966 | struct nfs4_exception exception = { |
| 9967 | .interruptible = true, |
| 9968 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9969 | int err; |
| 9970 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9971 | /* first try using integrity protection */ |
| 9972 | err = -NFS4ERR_WRONGSEC; |
| 9973 | |
| 9974 | /* try to use integrity protection with machine cred */ |
| 9975 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9976 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9977 | flavors, true); |
| 9978 | |
| 9979 | /* |
| 9980 | * if unable to use integrity protection, or SECINFO with |
| 9981 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9982 | * disallowed by spec, but exists in deployed servers) use |
| 9983 | * the current filesystem's rpc_client and the user cred. |
| 9984 | */ |
| 9985 | if (err == -NFS4ERR_WRONGSEC) |
| 9986 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9987 | flavors, false); |
| 9988 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9989 | switch (err) { |
| 9990 | case 0: |
| 9991 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9992 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9993 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9994 | default: |
| 9995 | err = nfs4_handle_exception(server, err, &exception); |
| 9996 | } |
| 9997 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9998 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9999 | return err; |
| 10000 | } |
| 10001 | |
| 10002 | static int |
| 10003 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 10004 | struct nfs_fsinfo *info) |
| 10005 | { |
| 10006 | int err; |
| 10007 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 10008 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10009 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 10010 | struct nfs4_secinfo4 *secinfo; |
| 10011 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10012 | |
| 10013 | page = alloc_page(GFP_KERNEL); |
| 10014 | if (!page) { |
| 10015 | err = -ENOMEM; |
| 10016 | goto out; |
| 10017 | } |
| 10018 | |
| 10019 | flavors = page_address(page); |
| 10020 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 10021 | |
| 10022 | /* |
| 10023 | * Fall back on "guess and check" method if |
| 10024 | * the server doesn't support SECINFO_NO_NAME |
| 10025 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 10026 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10027 | err = nfs4_find_root_sec(server, fhandle, info); |
| 10028 | goto out_freepage; |
| 10029 | } |
| 10030 | if (err) |
| 10031 | goto out_freepage; |
| 10032 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 10033 | for (i = 0; i < flavors->num_flavors; i++) { |
| 10034 | secinfo = &flavors->flavors[i]; |
| 10035 | |
| 10036 | switch (secinfo->flavor) { |
| 10037 | case RPC_AUTH_NULL: |
| 10038 | case RPC_AUTH_UNIX: |
| 10039 | case RPC_AUTH_GSS: |
| 10040 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 10041 | &secinfo->flavor_info); |
| 10042 | break; |
| 10043 | default: |
| 10044 | flavor = RPC_AUTH_MAXFLAVOR; |
| 10045 | break; |
| 10046 | } |
| 10047 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 10048 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 10049 | flavor = RPC_AUTH_MAXFLAVOR; |
| 10050 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 10051 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 10052 | err = nfs4_lookup_root_sec(server, fhandle, |
| 10053 | info, flavor); |
| 10054 | if (!err) |
| 10055 | break; |
| 10056 | } |
| 10057 | } |
| 10058 | |
| 10059 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 10060 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10061 | |
| 10062 | out_freepage: |
| 10063 | put_page(page); |
| 10064 | if (err == -EACCES) |
| 10065 | return -EPERM; |
| 10066 | out: |
| 10067 | return err; |
| 10068 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 10069 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10070 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 10071 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10072 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10073 | { |
| 10074 | int status; |
| 10075 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 10076 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10077 | }; |
| 10078 | struct nfs41_test_stateid_res res; |
| 10079 | struct rpc_message msg = { |
| 10080 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 10081 | .rpc_argp = &args, |
| 10082 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10083 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10084 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10085 | struct rpc_clnt *rpc_client = server->client; |
| 10086 | |
| 10087 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 10088 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 10089 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10090 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10091 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10092 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 10093 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10094 | if (status != NFS_OK) { |
| 10095 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 10096 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10097 | } |
| 10098 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 10099 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10100 | } |
| 10101 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10102 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 10103 | int err, struct nfs4_exception *exception) |
| 10104 | { |
| 10105 | exception->retry = 0; |
| 10106 | switch(err) { |
| 10107 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 10108 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10109 | nfs4_handle_exception(server, err, exception); |
| 10110 | break; |
| 10111 | case -NFS4ERR_BADSESSION: |
| 10112 | case -NFS4ERR_BADSLOT: |
| 10113 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 10114 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 10115 | case -NFS4ERR_DEADSESSION: |
| 10116 | nfs4_do_handle_exception(server, err, exception); |
| 10117 | } |
| 10118 | } |
| 10119 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10120 | /** |
| 10121 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 10122 | * |
| 10123 | * @server: server / transport on which to perform the operation |
| 10124 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10125 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10126 | * |
| 10127 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 10128 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 10129 | * failed or the state ID is not currently valid. |
| 10130 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10131 | static int nfs41_test_stateid(struct nfs_server *server, |
| 10132 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10133 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10134 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 10135 | struct nfs4_exception exception = { |
| 10136 | .interruptible = true, |
| 10137 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10138 | int err; |
| 10139 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10140 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10141 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10142 | } while (exception.retry); |
| 10143 | return err; |
| 10144 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10145 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10146 | struct nfs_free_stateid_data { |
| 10147 | struct nfs_server *server; |
| 10148 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10149 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10150 | }; |
| 10151 | |
| 10152 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 10153 | { |
| 10154 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 10155 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10156 | &data->args.seq_args, |
| 10157 | &data->res.seq_res, |
| 10158 | task); |
| 10159 | } |
| 10160 | |
| 10161 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 10162 | { |
| 10163 | struct nfs_free_stateid_data *data = calldata; |
| 10164 | |
| 10165 | nfs41_sequence_done(task, &data->res.seq_res); |
| 10166 | |
| 10167 | switch (task->tk_status) { |
| 10168 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 10169 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10170 | rpc_restart_call_prepare(task); |
| 10171 | } |
| 10172 | } |
| 10173 | |
| 10174 | static void nfs41_free_stateid_release(void *calldata) |
| 10175 | { |
Scott Mayhew | 576acc2 | 2021-11-03 06:24:40 -0400 | [diff] [blame] | 10176 | struct nfs_free_stateid_data *data = calldata; |
| 10177 | struct nfs_client *clp = data->server->nfs_client; |
| 10178 | |
| 10179 | nfs_put_client(clp); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10180 | kfree(calldata); |
| 10181 | } |
| 10182 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10183 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10184 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 10185 | .rpc_call_done = nfs41_free_stateid_done, |
| 10186 | .rpc_release = nfs41_free_stateid_release, |
| 10187 | }; |
| 10188 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10189 | /** |
| 10190 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 10191 | * |
| 10192 | * @server: server / transport on which to perform the operation |
| 10193 | * @stateid: state ID to release |
| 10194 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 10195 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10196 | * |
| 10197 | * Note: this function is always asynchronous. |
| 10198 | */ |
| 10199 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10200 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10201 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10202 | bool privileged) |
| 10203 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10204 | struct rpc_message msg = { |
| 10205 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10206 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10207 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10208 | struct rpc_task_setup task_setup = { |
| 10209 | .rpc_client = server->client, |
| 10210 | .rpc_message = &msg, |
| 10211 | .callback_ops = &nfs41_free_stateid_ops, |
Olga Kornievskaia | 85e39fe | 2021-06-23 23:28:51 -0400 | [diff] [blame] | 10212 | .flags = RPC_TASK_ASYNC | RPC_TASK_MOVEABLE, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10213 | }; |
| 10214 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10215 | struct rpc_task *task; |
Scott Mayhew | 576acc2 | 2021-11-03 06:24:40 -0400 | [diff] [blame] | 10216 | struct nfs_client *clp = server->nfs_client; |
| 10217 | |
| 10218 | if (!refcount_inc_not_zero(&clp->cl_count)) |
| 10219 | return -EIO; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10220 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10221 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 10222 | &task_setup.rpc_client, &msg); |
| 10223 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10224 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10225 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 10226 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10227 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10228 | data->server = server; |
| 10229 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 10230 | |
| 10231 | task_setup.callback_data = data; |
| 10232 | |
| 10233 | msg.rpc_argp = &data->args; |
| 10234 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10235 | 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] | 10236 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10237 | if (IS_ERR(task)) |
| 10238 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10239 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10240 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10241 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10242 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 10243 | static void |
| 10244 | 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] | 10245 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10246 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10247 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10248 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10249 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10250 | } |
| 10251 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10252 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 10253 | const nfs4_stateid *s2) |
| 10254 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 10255 | if (s1->type != s2->type) |
| 10256 | return false; |
| 10257 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10258 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10259 | return false; |
| 10260 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10261 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10262 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10263 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 10264 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10265 | } |
| 10266 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 10267 | #endif /* CONFIG_NFS_V4_1 */ |
| 10268 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10269 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 10270 | const nfs4_stateid *s2) |
| 10271 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10272 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10273 | } |
| 10274 | |
| 10275 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10276 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10277 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10278 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10279 | .recover_open = nfs4_open_reclaim, |
| 10280 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10281 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10282 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10283 | }; |
| 10284 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10285 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10286 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10287 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 10288 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 10289 | .recover_open = nfs4_open_reclaim, |
| 10290 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10291 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 10292 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10293 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10294 | }; |
| 10295 | #endif /* CONFIG_NFS_V4_1 */ |
| 10296 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10297 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10298 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10299 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 10300 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10301 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10302 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10303 | }; |
| 10304 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10305 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10306 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10307 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 10308 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 10309 | .recover_open = nfs41_open_expired, |
| 10310 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10311 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10312 | }; |
| 10313 | #endif /* CONFIG_NFS_V4_1 */ |
| 10314 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10315 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10316 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10317 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10318 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10319 | }; |
| 10320 | |
| 10321 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10322 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10323 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10324 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10325 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10326 | }; |
| 10327 | #endif |
| 10328 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10329 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10330 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10331 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10332 | }; |
| 10333 | |
| 10334 | #if defined(CONFIG_NFS_V4_1) |
| 10335 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10336 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10337 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10338 | }; |
| 10339 | #endif /* CONFIG_NFS_V4_1 */ |
| 10340 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10341 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 10342 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10343 | .init_caps = NFS_CAP_READDIRPLUS |
| 10344 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10345 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10346 | .init_client = nfs40_init_client, |
| 10347 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10348 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10349 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10350 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10351 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10352 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10353 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10354 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 10355 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 10356 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10357 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10358 | }; |
| 10359 | |
| 10360 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10361 | static struct nfs_seqid * |
| 10362 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 10363 | { |
| 10364 | return NULL; |
| 10365 | } |
| 10366 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10367 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 10368 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10369 | .init_caps = NFS_CAP_READDIRPLUS |
| 10370 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 10371 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 10372 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10373 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 10374 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10375 | .init_client = nfs41_init_client, |
| 10376 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10377 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10378 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10379 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10380 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10381 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10382 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10383 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10384 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10385 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10386 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10387 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10388 | }; |
| 10389 | #endif |
| 10390 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10391 | #if defined(CONFIG_NFS_V4_2) |
| 10392 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 10393 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10394 | .init_caps = NFS_CAP_READDIRPLUS |
| 10395 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10396 | | NFS_CAP_POSIX_LOCK |
| 10397 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 10398 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10399 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 10400 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 10401 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 10402 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 10403 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 10404 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 10405 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 10406 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 10407 | | NFS_CAP_CLONE |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 10408 | | NFS_CAP_LAYOUTERROR |
| 10409 | | NFS_CAP_READ_PLUS, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10410 | .init_client = nfs41_init_client, |
| 10411 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10412 | .match_stateid = nfs41_match_stateid, |
| 10413 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10414 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10415 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10416 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10417 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10418 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10419 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10420 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10421 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 10422 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10423 | }; |
| 10424 | #endif |
| 10425 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10426 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 10427 | [0] = &nfs_v4_0_minor_ops, |
| 10428 | #if defined(CONFIG_NFS_V4_1) |
| 10429 | [1] = &nfs_v4_1_minor_ops, |
| 10430 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10431 | #if defined(CONFIG_NFS_V4_2) |
| 10432 | [2] = &nfs_v4_2_minor_ops, |
| 10433 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10434 | }; |
| 10435 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 10436 | 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] | 10437 | { |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10438 | ssize_t error, error2, error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10439 | |
| 10440 | error = generic_listxattr(dentry, list, size); |
| 10441 | if (error < 0) |
| 10442 | return error; |
| 10443 | if (list) { |
| 10444 | list += error; |
| 10445 | size -= error; |
| 10446 | } |
| 10447 | |
| 10448 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10449 | if (error2 < 0) |
| 10450 | return error2; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10451 | |
| 10452 | if (list) { |
| 10453 | list += error2; |
| 10454 | size -= error2; |
| 10455 | } |
| 10456 | |
| 10457 | error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); |
| 10458 | if (error3 < 0) |
| 10459 | return error3; |
| 10460 | |
| 10461 | return error + error2 + error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10462 | } |
| 10463 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10464 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10465 | .create = nfs_create, |
| 10466 | .lookup = nfs_lookup, |
| 10467 | .atomic_open = nfs_atomic_open, |
| 10468 | .link = nfs_link, |
| 10469 | .unlink = nfs_unlink, |
| 10470 | .symlink = nfs_symlink, |
| 10471 | .mkdir = nfs_mkdir, |
| 10472 | .rmdir = nfs_rmdir, |
| 10473 | .mknod = nfs_mknod, |
| 10474 | .rename = nfs_rename, |
| 10475 | .permission = nfs_permission, |
| 10476 | .getattr = nfs_getattr, |
| 10477 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10478 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10479 | }; |
| 10480 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10481 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10482 | .permission = nfs_permission, |
| 10483 | .getattr = nfs_getattr, |
| 10484 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10485 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10486 | }; |
| 10487 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10488 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10489 | .version = 4, /* protocol version */ |
| 10490 | .dentry_ops = &nfs4_dentry_operations, |
| 10491 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10492 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10493 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10494 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10495 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10496 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10497 | .getattr = nfs4_proc_getattr, |
| 10498 | .setattr = nfs4_proc_setattr, |
| 10499 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10500 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10501 | .access = nfs4_proc_access, |
| 10502 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10503 | .create = nfs4_proc_create, |
| 10504 | .remove = nfs4_proc_remove, |
| 10505 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10506 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10507 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10508 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10509 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10510 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10511 | .link = nfs4_proc_link, |
| 10512 | .symlink = nfs4_proc_symlink, |
| 10513 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10514 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10515 | .readdir = nfs4_proc_readdir, |
| 10516 | .mknod = nfs4_proc_mknod, |
| 10517 | .statfs = nfs4_proc_statfs, |
| 10518 | .fsinfo = nfs4_proc_fsinfo, |
| 10519 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10520 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10521 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10522 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10523 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10524 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10525 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10526 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10527 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10528 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10529 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10530 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10531 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10532 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10533 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10534 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10535 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10536 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10537 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10538 | .create_server = nfs4_create_server, |
| 10539 | .clone_server = nfs_clone_server, |
Olga Kornievskaia | 1976b2b | 2022-01-12 10:27:38 -0500 | [diff] [blame] | 10540 | .discover_trunking = nfs4_discover_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10541 | }; |
| 10542 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10543 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10544 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10545 | .list = nfs4_xattr_list_nfs4_acl, |
| 10546 | .get = nfs4_xattr_get_nfs4_acl, |
| 10547 | .set = nfs4_xattr_set_nfs4_acl, |
| 10548 | }; |
| 10549 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10550 | #ifdef CONFIG_NFS_V4_2 |
| 10551 | static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { |
| 10552 | .prefix = XATTR_USER_PREFIX, |
| 10553 | .get = nfs4_xattr_get_nfs4_user, |
| 10554 | .set = nfs4_xattr_set_nfs4_user, |
| 10555 | }; |
| 10556 | #endif |
| 10557 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10558 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10559 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10560 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10561 | &nfs4_xattr_nfs4_label_handler, |
| 10562 | #endif |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10563 | #ifdef CONFIG_NFS_V4_2 |
| 10564 | &nfs4_xattr_nfs4_user_handler, |
| 10565 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10566 | NULL |
| 10567 | }; |