Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 56 | #include <linux/freezer.h> |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 57 | #include <linux/iversion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 66 | #include "sysfs.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 67 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 68 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 69 | #include "fscache.h" |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 70 | #include "nfs42.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 72 | #include "nfs4trace.h" |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 75 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 76 | #define NFS4_BITMASK_SZ 3 |
| 77 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 78 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 80 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 81 | /* file attributes which can be mapped to nfs attributes */ |
| 82 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 83 | | ATTR_UID \ |
| 84 | | ATTR_GID \ |
| 85 | | ATTR_SIZE \ |
| 86 | | ATTR_ATIME \ |
| 87 | | ATTR_MTIME \ |
| 88 | | ATTR_CTIME \ |
| 89 | | ATTR_ATIME_SET \ |
| 90 | | ATTR_MTIME_SET) |
| 91 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 92 | struct nfs4_opendata; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 93 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 95 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 96 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 97 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 98 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 99 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 100 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 101 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 102 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 103 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 104 | struct nfs4_slot *slot, |
| 105 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 106 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 107 | const struct cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 108 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 109 | const struct cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 110 | #endif |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 111 | static void nfs4_bitmask_adjust(__u32 *bitmask, struct inode *inode, |
| 112 | struct nfs_server *server, |
| 113 | struct nfs4_label *label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 114 | |
| 115 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 116 | static inline struct nfs4_label * |
| 117 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 118 | struct iattr *sattr, struct nfs4_label *label) |
| 119 | { |
| 120 | int err; |
| 121 | |
| 122 | if (label == NULL) |
| 123 | return NULL; |
| 124 | |
| 125 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 126 | return NULL; |
| 127 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 128 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 129 | &dentry->d_name, (void **)&label->label, &label->len); |
| 130 | if (err == 0) |
| 131 | return label; |
| 132 | |
| 133 | return NULL; |
| 134 | } |
| 135 | static inline void |
| 136 | nfs4_label_release_security(struct nfs4_label *label) |
| 137 | { |
| 138 | if (label) |
| 139 | security_release_secctx(label->label, label->len); |
| 140 | } |
| 141 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 142 | { |
| 143 | if (label) |
| 144 | return server->attr_bitmask; |
| 145 | |
| 146 | return server->attr_bitmask_nl; |
| 147 | } |
| 148 | #else |
| 149 | static inline struct nfs4_label * |
| 150 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 151 | struct iattr *sattr, struct nfs4_label *l) |
| 152 | { return NULL; } |
| 153 | static inline void |
| 154 | nfs4_label_release_security(struct nfs4_label *label) |
| 155 | { return; } |
| 156 | static inline u32 * |
| 157 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 158 | { return server->attr_bitmask; } |
| 159 | #endif |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 162 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 164 | if (err >= -1000) |
| 165 | return err; |
| 166 | switch (err) { |
| 167 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 168 | case -NFS4ERR_LAYOUTTRYLATER: |
| 169 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 170 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 171 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 172 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 173 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 174 | case -NFS4ERR_BADOWNER: |
| 175 | case -NFS4ERR_BADNAME: |
| 176 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 177 | case -NFS4ERR_SHARE_DENIED: |
| 178 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 179 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 180 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 181 | case -NFS4ERR_FILE_OPEN: |
| 182 | return -EBUSY; |
Trond Myklebust | 9fff59e | 2020-11-02 20:11:32 -0500 | [diff] [blame] | 183 | case -NFS4ERR_NOT_SAME: |
| 184 | return -ENOTSYNC; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 185 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 187 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 188 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 190 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /* |
| 194 | * This is our standard bitmap for GETATTR requests. |
| 195 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 196 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | FATTR4_WORD0_TYPE |
| 198 | | FATTR4_WORD0_CHANGE |
| 199 | | FATTR4_WORD0_SIZE |
| 200 | | FATTR4_WORD0_FSID |
| 201 | | FATTR4_WORD0_FILEID, |
| 202 | FATTR4_WORD1_MODE |
| 203 | | FATTR4_WORD1_NUMLINKS |
| 204 | | FATTR4_WORD1_OWNER |
| 205 | | FATTR4_WORD1_OWNER_GROUP |
| 206 | | FATTR4_WORD1_RAWDEV |
| 207 | | FATTR4_WORD1_SPACE_USED |
| 208 | | FATTR4_WORD1_TIME_ACCESS |
| 209 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 210 | | FATTR4_WORD1_TIME_MODIFY |
| 211 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 212 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 213 | FATTR4_WORD2_SECURITY_LABEL |
| 214 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 217 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 218 | FATTR4_WORD0_TYPE |
| 219 | | FATTR4_WORD0_CHANGE |
| 220 | | FATTR4_WORD0_SIZE |
| 221 | | FATTR4_WORD0_FSID |
| 222 | | FATTR4_WORD0_FILEID, |
| 223 | FATTR4_WORD1_MODE |
| 224 | | FATTR4_WORD1_NUMLINKS |
| 225 | | FATTR4_WORD1_OWNER |
| 226 | | FATTR4_WORD1_OWNER_GROUP |
| 227 | | FATTR4_WORD1_RAWDEV |
| 228 | | FATTR4_WORD1_SPACE_USED |
| 229 | | FATTR4_WORD1_TIME_ACCESS |
| 230 | | FATTR4_WORD1_TIME_METADATA |
| 231 | | FATTR4_WORD1_TIME_MODIFY, |
| 232 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 233 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 234 | | FATTR4_WORD2_SECURITY_LABEL |
| 235 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 236 | }; |
| 237 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 238 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 239 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 240 | | FATTR4_WORD0_FILEID, |
| 241 | }; |
| 242 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 243 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | FATTR4_WORD0_FILES_AVAIL |
| 245 | | FATTR4_WORD0_FILES_FREE |
| 246 | | FATTR4_WORD0_FILES_TOTAL, |
| 247 | FATTR4_WORD1_SPACE_AVAIL |
| 248 | | FATTR4_WORD1_SPACE_FREE |
| 249 | | FATTR4_WORD1_SPACE_TOTAL |
| 250 | }; |
| 251 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 252 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | FATTR4_WORD0_MAXLINK |
| 254 | | FATTR4_WORD0_MAXNAME, |
| 255 | 0 |
| 256 | }; |
| 257 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 258 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | | FATTR4_WORD0_MAXREAD |
| 260 | | FATTR4_WORD0_MAXWRITE |
| 261 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 262 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 263 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 264 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 265 | | FATTR4_WORD2_CLONE_BLKSIZE |
Frank van der Linden | b78ef84 | 2020-06-23 22:38:55 +0000 | [diff] [blame] | 266 | | FATTR4_WORD2_XATTR_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | }; |
| 268 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 269 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 270 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 271 | | FATTR4_WORD0_SIZE |
| 272 | | FATTR4_WORD0_FSID |
| 273 | | FATTR4_WORD0_FILEID |
| 274 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 275 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 276 | | FATTR4_WORD1_OWNER_GROUP |
| 277 | | FATTR4_WORD1_RAWDEV |
| 278 | | FATTR4_WORD1_SPACE_USED |
| 279 | | FATTR4_WORD1_TIME_ACCESS |
| 280 | | FATTR4_WORD1_TIME_METADATA |
| 281 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 282 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 283 | }; |
| 284 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 285 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
| 286 | struct inode *inode) |
| 287 | { |
| 288 | unsigned long cache_validity; |
| 289 | |
| 290 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 291 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 292 | return; |
| 293 | |
| 294 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 295 | if (!(cache_validity & NFS_INO_REVAL_FORCED)) |
| 296 | cache_validity &= ~(NFS_INO_INVALID_CHANGE |
| 297 | | NFS_INO_INVALID_SIZE); |
| 298 | |
| 299 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 300 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 301 | |
| 302 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 303 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
| 304 | } |
| 305 | |
| 306 | static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, |
| 307 | const __u32 *src, struct inode *inode) |
| 308 | { |
| 309 | nfs4_bitmap_copy_adjust(dst, src, inode); |
| 310 | } |
| 311 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 312 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | struct nfs4_readdir_arg *readdir) |
| 314 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 315 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 316 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 319 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | readdir->cookie = 0; |
| 325 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 326 | if (cookie == 2) |
| 327 | return; |
| 328 | |
| 329 | /* |
| 330 | * NFSv4 servers do not return entries for '.' and '..' |
| 331 | * Therefore, we fake these entries here. We let '.' |
| 332 | * have cookie 0 and '..' have cookie 1. Note that |
| 333 | * when talking to the server, we always send cookie 0 |
| 334 | * instead of 1 or 2. |
| 335 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 336 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | if (cookie == 0) { |
| 339 | *p++ = xdr_one; /* next */ |
| 340 | *p++ = xdr_zero; /* cookie, first word */ |
| 341 | *p++ = xdr_one; /* cookie, second word */ |
| 342 | *p++ = xdr_one; /* entry len */ |
| 343 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 344 | p++; |
| 345 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 346 | *p++ = htonl(attrs); /* bitmap */ |
| 347 | *p++ = htonl(12); /* attribute buffer length */ |
| 348 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 349 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | *p++ = xdr_one; /* next */ |
| 353 | *p++ = xdr_zero; /* cookie, first word */ |
| 354 | *p++ = xdr_two; /* cookie, second word */ |
| 355 | *p++ = xdr_two; /* entry len */ |
| 356 | memcpy(p, "..\0\0", 4); /* entry */ |
| 357 | p++; |
| 358 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 359 | *p++ = htonl(attrs); /* bitmap */ |
| 360 | *p++ = htonl(12); /* attribute buffer length */ |
| 361 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 362 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
| 364 | readdir->pgbase = (char *)p - (char *)start; |
| 365 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 366 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 369 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 370 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 371 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 372 | { |
| 373 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 374 | |
| 375 | ops->test_and_free_expired(server, stateid, cred); |
| 376 | } |
| 377 | |
| 378 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 379 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 380 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 381 | { |
| 382 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 383 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 384 | } |
| 385 | |
| 386 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 387 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 388 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 389 | { |
| 390 | nfs4_stateid tmp; |
| 391 | |
| 392 | nfs4_stateid_copy(&tmp, stateid); |
| 393 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 394 | } |
| 395 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 396 | static long nfs4_update_delay(long *timeout) |
| 397 | { |
| 398 | long ret; |
| 399 | if (!timeout) |
| 400 | return NFS4_POLL_RETRY_MAX; |
| 401 | if (*timeout <= 0) |
| 402 | *timeout = NFS4_POLL_RETRY_MIN; |
| 403 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 404 | *timeout = NFS4_POLL_RETRY_MAX; |
| 405 | ret = *timeout; |
| 406 | *timeout <<= 1; |
| 407 | return ret; |
| 408 | } |
| 409 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 410 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 411 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 412 | might_sleep(); |
| 413 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 414 | freezable_schedule_timeout_killable_unsafe( |
| 415 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 416 | if (!__fatal_signal_pending(current)) |
| 417 | return 0; |
| 418 | return -EINTR; |
| 419 | } |
| 420 | |
| 421 | static int nfs4_delay_interruptible(long *timeout) |
| 422 | { |
| 423 | might_sleep(); |
| 424 | |
He Zhe | 59679d9 | 2020-07-06 17:52:24 +0800 | [diff] [blame] | 425 | freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 426 | if (!signal_pending(current)) |
| 427 | return 0; |
| 428 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 429 | } |
| 430 | |
| 431 | static int nfs4_delay(long *timeout, bool interruptible) |
| 432 | { |
| 433 | if (interruptible) |
| 434 | return nfs4_delay_interruptible(timeout); |
| 435 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 438 | static const nfs4_stateid * |
| 439 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 440 | { |
| 441 | if (!stateid) |
| 442 | return NULL; |
| 443 | switch (stateid->type) { |
| 444 | case NFS4_OPEN_STATEID_TYPE: |
| 445 | case NFS4_LOCK_STATEID_TYPE: |
| 446 | case NFS4_DELEGATION_STATEID_TYPE: |
| 447 | return stateid; |
| 448 | default: |
| 449 | break; |
| 450 | } |
| 451 | return NULL; |
| 452 | } |
| 453 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 454 | /* This is the error handling routine for processes that are allowed |
| 455 | * to sleep. |
| 456 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 457 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 458 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 459 | { |
| 460 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 461 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 462 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 463 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 464 | int ret = errorcode; |
| 465 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 466 | exception->delay = 0; |
| 467 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 468 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 469 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 470 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 471 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 472 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 473 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 474 | switch(errorcode) { |
| 475 | case 0: |
| 476 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 477 | case -NFS4ERR_BADHANDLE: |
| 478 | case -ESTALE: |
| 479 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 480 | pnfs_destroy_layout(NFS_I(inode)); |
| 481 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 482 | case -NFS4ERR_DELEG_REVOKED: |
| 483 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 484 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 485 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame] | 486 | case -NFS4ERR_PARTNER_NO_AUTH: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 487 | if (inode != NULL && stateid != NULL) { |
| 488 | nfs_inode_find_state_and_recover(inode, |
| 489 | stateid); |
| 490 | goto wait_on_recovery; |
| 491 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 492 | fallthrough; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 493 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 494 | if (inode) { |
| 495 | int err; |
| 496 | |
| 497 | err = nfs_async_inode_return_delegation(inode, |
| 498 | stateid); |
| 499 | if (err == 0) |
| 500 | goto wait_on_recovery; |
| 501 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 502 | exception->retry = 1; |
| 503 | break; |
| 504 | } |
| 505 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 506 | if (state == NULL) |
| 507 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 508 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 509 | if (ret < 0) |
| 510 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 511 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 512 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 513 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 514 | nfs4_schedule_lease_recovery(clp); |
| 515 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 516 | case -NFS4ERR_MOVED: |
| 517 | ret = nfs4_schedule_migration_recovery(server); |
| 518 | if (ret < 0) |
| 519 | break; |
| 520 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 521 | case -NFS4ERR_LEASE_MOVED: |
| 522 | nfs4_schedule_lease_moved_recovery(clp); |
| 523 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 524 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 525 | case -NFS4ERR_BADSESSION: |
| 526 | case -NFS4ERR_BADSLOT: |
| 527 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 528 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 529 | case -NFS4ERR_DEADSESSION: |
| 530 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 531 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 532 | /* Handled in nfs41_sequence_process() */ |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 533 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 534 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 535 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 536 | if (exception->timeout > HZ) { |
| 537 | /* We have retried a decent amount, time to |
| 538 | * fail |
| 539 | */ |
| 540 | ret = -EBUSY; |
| 541 | break; |
| 542 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 543 | fallthrough; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 544 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 545 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 546 | fallthrough; |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 547 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 548 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 549 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 550 | exception->delay = 1; |
| 551 | return 0; |
| 552 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 553 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 554 | case -NFS4ERR_OLD_STATEID: |
| 555 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 556 | break; |
| 557 | case -NFS4ERR_BADOWNER: |
| 558 | /* The following works around a Linux server bug! */ |
| 559 | case -NFS4ERR_BADNAME: |
| 560 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 561 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 562 | exception->retry = 1; |
| 563 | printk(KERN_WARNING "NFS: v4 server %s " |
| 564 | "does not accept raw " |
| 565 | "uid/gids. " |
| 566 | "Reenabling the idmapper.\n", |
| 567 | server->nfs_client->cl_hostname); |
| 568 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 569 | } |
| 570 | /* We failed to handle the error */ |
| 571 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 572 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 573 | exception->recovering = 1; |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | /* This is the error handling routine for processes that are allowed |
| 578 | * to sleep. |
| 579 | */ |
| 580 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 581 | { |
| 582 | struct nfs_client *clp = server->nfs_client; |
| 583 | int ret; |
| 584 | |
| 585 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 586 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 587 | ret = nfs4_delay(&exception->timeout, |
| 588 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 589 | goto out_retry; |
| 590 | } |
| 591 | if (exception->recovering) { |
| 592 | ret = nfs4_wait_clnt_recover(clp); |
| 593 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 594 | return -EIO; |
| 595 | goto out_retry; |
| 596 | } |
| 597 | return ret; |
| 598 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 599 | if (ret == 0) |
| 600 | exception->retry = 1; |
| 601 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 602 | } |
| 603 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 604 | static int |
| 605 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 606 | int errorcode, struct nfs4_exception *exception) |
| 607 | { |
| 608 | struct nfs_client *clp = server->nfs_client; |
| 609 | int ret; |
| 610 | |
| 611 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 612 | if (exception->delay) { |
| 613 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 614 | goto out_retry; |
| 615 | } |
| 616 | if (exception->recovering) { |
| 617 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 618 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 619 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 620 | goto out_retry; |
| 621 | } |
| 622 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 623 | ret = -EIO; |
| 624 | return ret; |
| 625 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 626 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 627 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 628 | /* |
| 629 | * For NFS4ERR_MOVED, the client transport will need to |
| 630 | * be recomputed after migration recovery has completed. |
| 631 | */ |
| 632 | if (errorcode == -NFS4ERR_MOVED) |
| 633 | rpc_task_release_transport(task); |
| 634 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 635 | return ret; |
| 636 | } |
| 637 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 638 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 639 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 640 | struct nfs4_state *state, long *timeout) |
| 641 | { |
| 642 | struct nfs4_exception exception = { |
| 643 | .state = state, |
| 644 | }; |
| 645 | |
| 646 | if (task->tk_status >= 0) |
| 647 | return 0; |
| 648 | if (timeout) |
| 649 | exception.timeout = *timeout; |
| 650 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 651 | task->tk_status, |
| 652 | &exception); |
| 653 | if (exception.delay && timeout) |
| 654 | *timeout = exception.timeout; |
| 655 | if (exception.retry) |
| 656 | return -EAGAIN; |
| 657 | return 0; |
| 658 | } |
| 659 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 660 | /* |
| 661 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 662 | * or 'false' otherwise. |
| 663 | */ |
| 664 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 665 | { |
| 666 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 667 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 668 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 669 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 670 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | spin_lock(&clp->cl_lock); |
| 673 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 674 | clp->cl_last_renewal = timestamp; |
| 675 | spin_unlock(&clp->cl_lock); |
| 676 | } |
| 677 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 678 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 679 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 680 | struct nfs_client *clp = server->nfs_client; |
| 681 | |
| 682 | if (!nfs4_has_session(clp)) |
| 683 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 684 | } |
| 685 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 686 | struct nfs4_call_sync_data { |
| 687 | const struct nfs_server *seq_server; |
| 688 | struct nfs4_sequence_args *seq_args; |
| 689 | struct nfs4_sequence_res *seq_res; |
| 690 | }; |
| 691 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 692 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 693 | struct nfs4_sequence_res *res, int cache_reply, |
| 694 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 695 | { |
| 696 | args->sa_slot = NULL; |
| 697 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 698 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 699 | |
| 700 | res->sr_slot = NULL; |
| 701 | } |
| 702 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 703 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 704 | { |
| 705 | struct nfs4_slot *slot = res->sr_slot; |
| 706 | struct nfs4_slot_table *tbl; |
| 707 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 708 | tbl = slot->table; |
| 709 | spin_lock(&tbl->slot_tbl_lock); |
| 710 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 711 | nfs4_free_slot(tbl, slot); |
| 712 | spin_unlock(&tbl->slot_tbl_lock); |
| 713 | |
| 714 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static int nfs40_sequence_done(struct rpc_task *task, |
| 718 | struct nfs4_sequence_res *res) |
| 719 | { |
| 720 | if (res->sr_slot != NULL) |
| 721 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 722 | return 1; |
| 723 | } |
| 724 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 725 | #if defined(CONFIG_NFS_V4_1) |
| 726 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 727 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 728 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 729 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 730 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 731 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 732 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 733 | if (!slot) |
| 734 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 735 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 736 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 737 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 738 | /* Bump the slot sequence number */ |
| 739 | if (slot->seq_done) |
| 740 | slot->seq_nr++; |
| 741 | slot->seq_done = 0; |
| 742 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 743 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 744 | /* Be nice to the server: try to ensure that the last transmitted |
| 745 | * value for highest_user_slotid <= target_highest_slotid |
| 746 | */ |
| 747 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 748 | send_new_highest_used_slotid = true; |
| 749 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 750 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 751 | send_new_highest_used_slotid = false; |
| 752 | goto out_unlock; |
| 753 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 754 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 755 | |
| 756 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 757 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 758 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 759 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 760 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 761 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 762 | if (waitqueue_active(&tbl->slot_waitq)) |
| 763 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 764 | } |
| 765 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 766 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 767 | { |
| 768 | nfs41_release_slot(res->sr_slot); |
| 769 | res->sr_slot = NULL; |
| 770 | } |
| 771 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 772 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 773 | u32 seqnr) |
| 774 | { |
| 775 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 776 | slot->seq_nr_highest_sent = seqnr; |
| 777 | } |
| 778 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 779 | u32 seqnr) |
| 780 | { |
| 781 | slot->seq_nr_highest_sent = seqnr; |
| 782 | slot->seq_nr_last_acked = seqnr; |
| 783 | } |
| 784 | |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 785 | static void nfs4_probe_sequence(struct nfs_client *client, const struct cred *cred, |
| 786 | struct nfs4_slot *slot) |
| 787 | { |
| 788 | struct rpc_task *task = _nfs41_proc_sequence(client, cred, slot, true); |
| 789 | if (!IS_ERR(task)) |
| 790 | rpc_put_task_async(task); |
| 791 | } |
| 792 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 793 | static int nfs41_sequence_process(struct rpc_task *task, |
| 794 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 795 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 796 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 797 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 798 | struct nfs_client *clp; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 799 | int status; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 800 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 801 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 802 | if (slot == NULL) |
| 803 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 804 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 805 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 806 | goto out; |
| 807 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 808 | session = slot->table->session; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 809 | clp = session->clp; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 810 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 811 | trace_nfs4_sequence_done(session, res); |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 812 | |
| 813 | status = res->sr_status; |
| 814 | if (task->tk_status == -NFS4ERR_DEADSESSION) |
| 815 | status = -NFS4ERR_DEADSESSION; |
| 816 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 817 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 818 | switch (status) { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 819 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 820 | /* Mark this sequence number as having been acked */ |
| 821 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 822 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 823 | slot->seq_done = 1; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 824 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 825 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 826 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 827 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 828 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 829 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 830 | case 1: |
| 831 | /* |
| 832 | * sr_status remains 1 if an RPC level error occurred. |
| 833 | * The server may or may not have processed the sequence |
| 834 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 835 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 836 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 837 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 838 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 839 | case -NFS4ERR_DELAY: |
| 840 | /* The server detected a resend of the RPC call and |
| 841 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 842 | * of RFC5661. |
| 843 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 844 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 845 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 846 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 847 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 848 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 849 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 850 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 851 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 852 | /* |
| 853 | * The server thinks we tried to replay a request. |
| 854 | * Retry the call after bumping the sequence ID. |
| 855 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 856 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 857 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 858 | case -NFS4ERR_BADSLOT: |
| 859 | /* |
| 860 | * The slot id we used was probably retired. Try again |
| 861 | * using a different slot id. |
| 862 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 863 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 864 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 865 | goto retry_nowait; |
| 866 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 867 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 868 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 869 | * Were one or more calls using this slot interrupted? |
| 870 | * If the server never received the request, then our |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 871 | * transmitted slot sequence number may be too high. However, |
| 872 | * if the server did receive the request then it might |
| 873 | * accidentally give us a reply with a mismatched operation. |
| 874 | * We can sort this out by sending a lone sequence operation |
| 875 | * to the server on the same slot. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 876 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 877 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 878 | slot->seq_nr--; |
Anna Schumaker | 913fadc | 2020-07-08 10:33:40 -0400 | [diff] [blame] | 879 | if (task->tk_msg.rpc_proc != &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE]) { |
| 880 | nfs4_probe_sequence(clp, task->tk_msg.rpc_cred, slot); |
| 881 | res->sr_slot = NULL; |
| 882 | } |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 883 | goto retry_nowait; |
| 884 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 885 | /* |
| 886 | * RFC5661: |
| 887 | * A retry might be sent while the original request is |
| 888 | * still in progress on the replier. The replier SHOULD |
| 889 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 890 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 891 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 892 | * |
| 893 | * Restart the search after a delay. |
| 894 | */ |
| 895 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 896 | goto out_retry; |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 897 | case -NFS4ERR_BADSESSION: |
| 898 | case -NFS4ERR_DEADSESSION: |
| 899 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 900 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 901 | default: |
| 902 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 903 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 904 | } |
| 905 | out: |
| 906 | /* The session may be reset by one of the error handlers. */ |
| 907 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 908 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 909 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 910 | session_recover: |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 911 | nfs4_schedule_session_recovery(session, status); |
| 912 | dprintk("%s ERROR: %d Reset session\n", __func__, status); |
| 913 | nfs41_sequence_free_slot(res); |
| 914 | goto out; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 915 | retry_new_seq: |
| 916 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 917 | retry_nowait: |
| 918 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 919 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 920 | task->tk_status = 0; |
| 921 | ret = 0; |
| 922 | } |
| 923 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 924 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 925 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 926 | goto out; |
| 927 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 928 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 929 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 930 | |
| 931 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 932 | { |
| 933 | if (!nfs41_sequence_process(task, res)) |
| 934 | return 0; |
| 935 | if (res->sr_slot != NULL) |
| 936 | nfs41_sequence_free_slot(res); |
| 937 | return 1; |
| 938 | |
| 939 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 940 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 941 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 942 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 943 | { |
| 944 | if (res->sr_slot == NULL) |
| 945 | return 1; |
| 946 | if (res->sr_slot->table->session != NULL) |
| 947 | return nfs41_sequence_process(task, res); |
| 948 | return nfs40_sequence_done(task, res); |
| 949 | } |
| 950 | |
| 951 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 952 | { |
| 953 | if (res->sr_slot != NULL) { |
| 954 | if (res->sr_slot->table->session != NULL) |
| 955 | nfs41_sequence_free_slot(res); |
| 956 | else |
| 957 | nfs40_sequence_free_slot(res); |
| 958 | } |
| 959 | } |
| 960 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 961 | 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] | 962 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 963 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 964 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 965 | if (!res->sr_slot->table->session) |
| 966 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 967 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 968 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 969 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 970 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 971 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 972 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 973 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 974 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 975 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 976 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 977 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 978 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 979 | } |
| 980 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 981 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 982 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 983 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 984 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 985 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 986 | } |
| 987 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 988 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 989 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 990 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 991 | }; |
| 992 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 993 | #else /* !CONFIG_NFS_V4_1 */ |
| 994 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 995 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 996 | { |
| 997 | return nfs40_sequence_done(task, res); |
| 998 | } |
| 999 | |
| 1000 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1001 | { |
| 1002 | if (res->sr_slot != NULL) |
| 1003 | nfs40_sequence_free_slot(res); |
| 1004 | } |
| 1005 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1006 | int nfs4_sequence_done(struct rpc_task *task, |
| 1007 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1008 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1009 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1010 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1011 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1012 | |
| 1013 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1014 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1015 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 1016 | { |
| 1017 | res->sr_timestamp = jiffies; |
| 1018 | res->sr_status_flags = 0; |
| 1019 | res->sr_status = 1; |
| 1020 | } |
| 1021 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1022 | static |
| 1023 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 1024 | struct nfs4_sequence_res *res, |
| 1025 | struct nfs4_slot *slot) |
| 1026 | { |
| 1027 | if (!slot) |
| 1028 | return; |
| 1029 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 1030 | args->sa_slot = slot; |
| 1031 | |
| 1032 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1036 | struct nfs4_sequence_args *args, |
| 1037 | struct nfs4_sequence_res *res, |
| 1038 | struct rpc_task *task) |
| 1039 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1040 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1041 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1042 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1043 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1044 | /* slot already allocated? */ |
| 1045 | if (res->sr_slot != NULL) |
| 1046 | goto out_start; |
| 1047 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1048 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1049 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1050 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1051 | spin_lock(&tbl->slot_tbl_lock); |
| 1052 | /* The state manager will wait until the slot table is empty */ |
| 1053 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1054 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1055 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1056 | slot = nfs4_alloc_slot(tbl); |
| 1057 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1058 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1059 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1060 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1061 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1062 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1063 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1064 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1065 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1066 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1067 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1068 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1069 | rpc_call_start(task); |
| 1070 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1071 | out_sleep_timeout: |
| 1072 | /* Try again in 1/4 second */ |
| 1073 | if (args->sa_privileged) |
| 1074 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1075 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1076 | else |
| 1077 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1078 | NULL, jiffies + (HZ >> 2)); |
| 1079 | spin_unlock(&tbl->slot_tbl_lock); |
| 1080 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1081 | out_sleep: |
| 1082 | if (args->sa_privileged) |
| 1083 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1084 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1085 | else |
| 1086 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1087 | spin_unlock(&tbl->slot_tbl_lock); |
| 1088 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1089 | } |
| 1090 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1091 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1092 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1093 | { |
| 1094 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1095 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1096 | data->seq_args, data->seq_res, task); |
| 1097 | } |
| 1098 | |
| 1099 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1100 | { |
| 1101 | struct nfs4_call_sync_data *data = calldata; |
| 1102 | nfs4_sequence_done(task, data->seq_res); |
| 1103 | } |
| 1104 | |
| 1105 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1106 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1107 | .rpc_call_done = nfs40_call_sync_done, |
| 1108 | }; |
| 1109 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1110 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1111 | { |
| 1112 | int ret; |
| 1113 | struct rpc_task *task; |
| 1114 | |
| 1115 | task = rpc_run_task(task_setup); |
| 1116 | if (IS_ERR(task)) |
| 1117 | return PTR_ERR(task); |
| 1118 | |
| 1119 | ret = task->tk_status; |
| 1120 | rpc_put_task(task); |
| 1121 | return ret; |
| 1122 | } |
| 1123 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1124 | static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
| 1125 | struct nfs_server *server, |
| 1126 | struct rpc_message *msg, |
| 1127 | struct nfs4_sequence_args *args, |
| 1128 | struct nfs4_sequence_res *res, |
| 1129 | unsigned short task_flags) |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1130 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1131 | struct nfs_client *clp = server->nfs_client; |
| 1132 | struct nfs4_call_sync_data data = { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1133 | .seq_server = server, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1134 | .seq_args = args, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1135 | .seq_res = res, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1136 | }; |
| 1137 | struct rpc_task_setup task_setup = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1138 | .rpc_client = clnt, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1139 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1140 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1141 | .callback_data = &data, |
| 1142 | .flags = task_flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1143 | }; |
| 1144 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1145 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1146 | } |
| 1147 | |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 1148 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 1149 | struct nfs_server *server, |
| 1150 | struct rpc_message *msg, |
| 1151 | struct nfs4_sequence_args *args, |
| 1152 | struct nfs4_sequence_res *res) |
| 1153 | { |
| 1154 | return nfs4_do_call_sync(clnt, server, msg, args, res, 0); |
| 1155 | } |
| 1156 | |
| 1157 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1158 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1159 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1160 | struct rpc_message *msg, |
| 1161 | struct nfs4_sequence_args *args, |
| 1162 | struct nfs4_sequence_res *res, |
| 1163 | int cache_reply) |
| 1164 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1165 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1166 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1169 | static void |
| 1170 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1171 | { |
| 1172 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1173 | inc_nlink(inode); |
| 1174 | } |
| 1175 | |
| 1176 | static void |
| 1177 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1178 | { |
| 1179 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1180 | drop_nlink(inode); |
| 1181 | } |
| 1182 | |
| 1183 | static void |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1184 | nfs4_update_changeattr_locked(struct inode *inode, |
| 1185 | struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1186 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1188 | struct nfs_inode *nfsi = NFS_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1190 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1191 | | NFS_INO_INVALID_MTIME |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1192 | | cache_validity; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1193 | |
| 1194 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(inode)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1195 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1196 | nfsi->attrtimeo_timestamp = jiffies; |
| 1197 | } else { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1198 | if (S_ISDIR(inode->i_mode)) { |
| 1199 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; |
| 1200 | nfs_force_lookup_revalidate(inode); |
| 1201 | } else { |
| 1202 | if (!NFS_PROTO(inode)->have_delegation(inode, |
| 1203 | FMODE_READ)) |
| 1204 | nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE; |
| 1205 | } |
| 1206 | |
| 1207 | if (cinfo->before != inode_peek_iversion_raw(inode)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1208 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
Frank van der Linden | 0f44da5 | 2020-06-23 22:39:00 +0000 | [diff] [blame] | 1209 | NFS_INO_INVALID_ACL | |
| 1210 | NFS_INO_INVALID_XATTR; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1211 | } |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1212 | inode_set_iversion_raw(inode, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1213 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1214 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1215 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1216 | |
| 1217 | if (nfsi->cache_validity & NFS_INO_INVALID_DATA) |
| 1218 | nfs_fscache_invalidate(inode); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1219 | } |
| 1220 | |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1221 | void |
| 1222 | nfs4_update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1223 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1224 | { |
| 1225 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 1226 | nfs4_update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | spin_unlock(&dir->i_lock); |
| 1228 | } |
| 1229 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1230 | struct nfs4_open_createattrs { |
| 1231 | struct nfs4_label *label; |
| 1232 | struct iattr *sattr; |
| 1233 | const __u32 verf[2]; |
| 1234 | }; |
| 1235 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1236 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1237 | int err, struct nfs4_exception *exception) |
| 1238 | { |
| 1239 | if (err != -EINVAL) |
| 1240 | return false; |
| 1241 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1242 | return false; |
| 1243 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1244 | exception->retry = 1; |
| 1245 | return true; |
| 1246 | } |
| 1247 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1248 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1249 | { |
| 1250 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1251 | } |
| 1252 | |
| 1253 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1254 | { |
| 1255 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1256 | |
| 1257 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1258 | } |
| 1259 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1260 | static u32 |
| 1261 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1262 | fmode_t fmode, int openflags) |
| 1263 | { |
| 1264 | u32 res = 0; |
| 1265 | |
| 1266 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1267 | case FMODE_READ: |
| 1268 | res = NFS4_SHARE_ACCESS_READ; |
| 1269 | break; |
| 1270 | case FMODE_WRITE: |
| 1271 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1272 | break; |
| 1273 | case FMODE_READ|FMODE_WRITE: |
| 1274 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1275 | } |
| 1276 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1277 | goto out; |
| 1278 | /* Want no delegation if we're using O_DIRECT */ |
| 1279 | if (openflags & O_DIRECT) |
| 1280 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1281 | out: |
| 1282 | return res; |
| 1283 | } |
| 1284 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1285 | static enum open_claim_type4 |
| 1286 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1287 | enum open_claim_type4 claim) |
| 1288 | { |
| 1289 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1290 | return claim; |
| 1291 | switch (claim) { |
| 1292 | default: |
| 1293 | return claim; |
| 1294 | case NFS4_OPEN_CLAIM_FH: |
| 1295 | return NFS4_OPEN_CLAIM_NULL; |
| 1296 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1297 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1298 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1299 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1300 | } |
| 1301 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | |
| 1303 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1304 | { |
| 1305 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1306 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1307 | p->o_res.seqid = p->o_arg.seqid; |
| 1308 | p->c_res.seqid = p->c_arg.seqid; |
| 1309 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1310 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1311 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1312 | 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] | 1313 | } |
| 1314 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1315 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1316 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1317 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1318 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1319 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1320 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1321 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1322 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1323 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1324 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1325 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1326 | struct nfs4_opendata *p; |
| 1327 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1328 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1329 | if (p == NULL) |
| 1330 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1331 | |
| 1332 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1333 | if (IS_ERR(p->f_label)) |
| 1334 | goto err_free_p; |
| 1335 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1336 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1337 | if (IS_ERR(p->a_label)) |
| 1338 | goto err_free_f; |
| 1339 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1340 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1341 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1342 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1343 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1344 | nfs_sb_active(dentry->d_sb); |
| 1345 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1346 | p->dir = parent; |
| 1347 | p->owner = sp; |
| 1348 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1349 | p->o_arg.open_flags = flags; |
| 1350 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1351 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1352 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1353 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1354 | if (flags & O_CREAT) { |
| 1355 | p->o_arg.umask = current_umask(); |
| 1356 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1357 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1358 | p->o_arg.u.attrs = &p->attrs; |
| 1359 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1360 | |
| 1361 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1362 | sizeof(p->o_arg.u.verifier.data)); |
| 1363 | } |
| 1364 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1365 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1366 | * will return permission denied for all bits until close */ |
| 1367 | if (!(flags & O_EXCL)) { |
| 1368 | /* ask server to check for all possible rights as results |
| 1369 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1370 | switch (p->o_arg.claim) { |
| 1371 | default: |
| 1372 | break; |
| 1373 | case NFS4_OPEN_CLAIM_NULL: |
| 1374 | case NFS4_OPEN_CLAIM_FH: |
| 1375 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1376 | NFS4_ACCESS_MODIFY | |
| 1377 | NFS4_ACCESS_EXTEND | |
| 1378 | NFS4_ACCESS_EXECUTE; |
Frank van der Linden | 72832a2 | 2020-06-23 22:38:58 +0000 | [diff] [blame] | 1379 | #ifdef CONFIG_NFS_V4_2 |
| 1380 | if (server->caps & NFS_CAP_XATTR) |
| 1381 | p->o_arg.access |= NFS4_ACCESS_XAREAD | |
| 1382 | NFS4_ACCESS_XAWRITE | |
| 1383 | NFS4_ACCESS_XALIST; |
| 1384 | #endif |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1385 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1386 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1387 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1388 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1389 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1390 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1391 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1392 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1393 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1394 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1395 | case NFS4_OPEN_CLAIM_NULL: |
| 1396 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1397 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1398 | p->o_arg.fh = NFS_FH(dir); |
| 1399 | break; |
| 1400 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1401 | case NFS4_OPEN_CLAIM_FH: |
| 1402 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1403 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1404 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1405 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1406 | p->c_arg.fh = &p->o_res.fh; |
| 1407 | p->c_arg.stateid = &p->o_res.stateid; |
| 1408 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1409 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1410 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1411 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1412 | |
| 1413 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1414 | nfs4_label_free(p->a_label); |
| 1415 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1416 | nfs4_label_free(p->f_label); |
| 1417 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1418 | kfree(p); |
| 1419 | err: |
| 1420 | dput(parent); |
| 1421 | return NULL; |
| 1422 | } |
| 1423 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1424 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1425 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1426 | struct nfs4_opendata *p = container_of(kref, |
| 1427 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1428 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1429 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1430 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1431 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1432 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1433 | if (p->state != NULL) |
| 1434 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1435 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1436 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1437 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1438 | nfs4_label_free(p->f_label); |
| 1439 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1440 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1441 | dput(p->dentry); |
| 1442 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1443 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1444 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1445 | kfree(p); |
| 1446 | } |
| 1447 | |
| 1448 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1449 | { |
| 1450 | if (p != NULL) |
| 1451 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1452 | } |
| 1453 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1454 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1455 | fmode_t fmode) |
| 1456 | { |
| 1457 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1458 | case FMODE_READ|FMODE_WRITE: |
| 1459 | return state->n_rdwr != 0; |
| 1460 | case FMODE_WRITE: |
| 1461 | return state->n_wronly != 0; |
| 1462 | case FMODE_READ: |
| 1463 | return state->n_rdonly != 0; |
| 1464 | } |
| 1465 | WARN_ON_ONCE(1); |
| 1466 | return false; |
| 1467 | } |
| 1468 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1469 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1470 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1471 | { |
| 1472 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1473 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1474 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1475 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1476 | switch (claim) { |
| 1477 | case NFS4_OPEN_CLAIM_NULL: |
| 1478 | case NFS4_OPEN_CLAIM_FH: |
| 1479 | goto out; |
| 1480 | default: |
| 1481 | break; |
| 1482 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1483 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1484 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1485 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1486 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1487 | break; |
| 1488 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1489 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1490 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1491 | break; |
| 1492 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1493 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1494 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1495 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1496 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1497 | return ret; |
| 1498 | } |
| 1499 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1500 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1501 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1502 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1503 | if (delegation == NULL) |
| 1504 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1505 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1506 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1507 | switch (claim) { |
| 1508 | case NFS4_OPEN_CLAIM_NULL: |
| 1509 | case NFS4_OPEN_CLAIM_FH: |
| 1510 | break; |
| 1511 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1512 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1513 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1514 | fallthrough; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1515 | default: |
| 1516 | return 0; |
| 1517 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1518 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1519 | return 1; |
| 1520 | } |
| 1521 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1522 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1523 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1524 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1525 | case FMODE_WRITE: |
| 1526 | state->n_wronly++; |
| 1527 | break; |
| 1528 | case FMODE_READ: |
| 1529 | state->n_rdonly++; |
| 1530 | break; |
| 1531 | case FMODE_READ|FMODE_WRITE: |
| 1532 | state->n_rdwr++; |
| 1533 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1534 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1535 | } |
| 1536 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1537 | #ifdef CONFIG_NFS_V4_1 |
| 1538 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1539 | { |
| 1540 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1541 | return true; |
| 1542 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1543 | return true; |
| 1544 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1545 | return true; |
| 1546 | return false; |
| 1547 | } |
| 1548 | #endif /* CONFIG_NFS_V4_1 */ |
| 1549 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1550 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1551 | { |
| 1552 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1553 | wake_up_all(&state->waitq); |
| 1554 | } |
| 1555 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1556 | 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] | 1557 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1558 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1559 | bool need_recover = false; |
| 1560 | |
| 1561 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1562 | need_recover = true; |
| 1563 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1564 | need_recover = true; |
| 1565 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1566 | need_recover = true; |
| 1567 | if (need_recover) |
| 1568 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1569 | } |
| 1570 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1571 | /* |
| 1572 | * Check for whether or not the caller may update the open stateid |
| 1573 | * to the value passed in by stateid. |
| 1574 | * |
| 1575 | * Note: This function relies heavily on the server implementing |
| 1576 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1577 | * correctly. |
| 1578 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1579 | * are then incremented on every state transition. |
| 1580 | */ |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1581 | static bool nfs_stateid_is_sequential(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1582 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1583 | { |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1584 | if (test_bit(NFS_OPEN_STATE, &state->flags)) { |
| 1585 | /* The common case - we're updating to a new sequence number */ |
| 1586 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1587 | nfs4_stateid_is_next(&state->open_stateid, stateid)) { |
| 1588 | return true; |
| 1589 | } |
| 1590 | } else { |
| 1591 | /* This is the first OPEN in this generation */ |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1592 | if (stateid->seqid == cpu_to_be32(1)) |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1593 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1594 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1595 | return false; |
| 1596 | } |
| 1597 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1598 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1599 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1600 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1601 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1602 | if (state->n_wronly) |
| 1603 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1604 | if (state->n_rdonly) |
| 1605 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1606 | if (state->n_rdwr) |
| 1607 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1608 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1609 | } |
| 1610 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1611 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1612 | nfs4_stateid *stateid, fmode_t fmode) |
| 1613 | { |
| 1614 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1615 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1616 | case FMODE_WRITE: |
| 1617 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1618 | break; |
| 1619 | case FMODE_READ: |
| 1620 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1621 | break; |
| 1622 | case 0: |
| 1623 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1624 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1625 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1626 | } |
| 1627 | if (stateid == NULL) |
| 1628 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1629 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1630 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1631 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1632 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1633 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1634 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1635 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1636 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1637 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1638 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1639 | out: |
| 1640 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1641 | } |
| 1642 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1643 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1644 | nfs4_stateid *arg_stateid, |
| 1645 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1646 | { |
| 1647 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1648 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1649 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1650 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1651 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1652 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1653 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1654 | } |
| 1655 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1656 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1657 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1658 | __must_hold(&state->owner->so_lock) |
| 1659 | __must_hold(&state->seqlock) |
| 1660 | __must_hold(RCU) |
| 1661 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1662 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1663 | DEFINE_WAIT(wait); |
| 1664 | int status = 0; |
| 1665 | for (;;) { |
| 1666 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1667 | if (nfs_stateid_is_sequential(state, stateid)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1668 | break; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1669 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1670 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1671 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1672 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1673 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1674 | break; |
| 1675 | |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 1676 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1677 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1678 | /* |
| 1679 | * Ensure we process the state changes in the same order |
| 1680 | * in which the server processed them by delaying the |
| 1681 | * update of the stateid until we are in sequence. |
| 1682 | */ |
| 1683 | write_sequnlock(&state->seqlock); |
| 1684 | spin_unlock(&state->owner->so_lock); |
| 1685 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1686 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
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 (!signal_pending(current)) { |
| 1689 | if (schedule_timeout(5*HZ) == 0) |
| 1690 | status = -EAGAIN; |
| 1691 | else |
| 1692 | status = 0; |
| 1693 | } else |
| 1694 | status = -EINTR; |
| 1695 | finish_wait(&state->waitq, &wait); |
| 1696 | rcu_read_lock(); |
| 1697 | spin_lock(&state->owner->so_lock); |
| 1698 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1699 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1700 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1701 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1702 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1703 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1704 | nfs_test_and_clear_all_open_stateid(state); |
| 1705 | } |
| 1706 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1707 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1708 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1709 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1710 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1711 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1714 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1715 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1716 | fmode_t fmode, |
| 1717 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1719 | /* |
| 1720 | * Protect the call to nfs4_state_set_mode_locked and |
| 1721 | * serialise the stateid update |
| 1722 | */ |
| 1723 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1724 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1725 | switch (fmode) { |
| 1726 | case FMODE_READ: |
| 1727 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1728 | break; |
| 1729 | case FMODE_WRITE: |
| 1730 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1731 | break; |
| 1732 | case FMODE_READ|FMODE_WRITE: |
| 1733 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1734 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1735 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1736 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1737 | } |
| 1738 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1739 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1740 | { |
| 1741 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1742 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1743 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1744 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1745 | } |
| 1746 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1747 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1748 | const nfs4_stateid *deleg_stateid, |
| 1749 | fmode_t fmode) |
| 1750 | { |
| 1751 | /* |
| 1752 | * Protect the call to nfs4_state_set_mode_locked and |
| 1753 | * serialise the stateid update |
| 1754 | */ |
| 1755 | write_seqlock(&state->seqlock); |
| 1756 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1757 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1758 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1761 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1762 | { |
| 1763 | write_seqlock(&state->seqlock); |
| 1764 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1765 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1766 | write_sequnlock(&state->seqlock); |
| 1767 | } |
| 1768 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1769 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1770 | const nfs4_stateid *open_stateid, |
| 1771 | const nfs4_stateid *delegation, |
| 1772 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1773 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1774 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1775 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1776 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1777 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1778 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1779 | int ret = 0; |
| 1780 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1781 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1782 | |
| 1783 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1784 | spin_lock(&state->owner->so_lock); |
| 1785 | if (open_stateid != NULL) { |
| 1786 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1787 | ret = 1; |
| 1788 | } |
| 1789 | |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1790 | deleg_cur = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1791 | if (deleg_cur == NULL) |
| 1792 | goto no_delegation; |
| 1793 | |
| 1794 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1795 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1796 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1797 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1798 | goto no_delegation_unlock; |
| 1799 | |
| 1800 | if (delegation == NULL) |
| 1801 | delegation = &deleg_cur->stateid; |
Trond Myklebust | 333ac78 | 2019-10-22 12:12:17 -0400 | [diff] [blame] | 1802 | else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1803 | goto no_delegation_unlock; |
| 1804 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1805 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1806 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1807 | ret = 1; |
| 1808 | no_delegation_unlock: |
| 1809 | spin_unlock(&deleg_cur->lock); |
| 1810 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1811 | if (ret) |
| 1812 | update_open_stateflags(state, fmode); |
| 1813 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1814 | rcu_read_unlock(); |
| 1815 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1816 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1817 | nfs4_schedule_state_manager(clp); |
| 1818 | if (freeme.type != 0) |
| 1819 | nfs4_test_and_free_stateid(server, &freeme, |
| 1820 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1821 | |
| 1822 | return ret; |
| 1823 | } |
| 1824 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1825 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1826 | const nfs4_stateid *stateid) |
| 1827 | { |
| 1828 | struct nfs4_state *state = lsp->ls_state; |
| 1829 | bool ret = false; |
| 1830 | |
| 1831 | spin_lock(&state->state_lock); |
| 1832 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1833 | goto out_noupdate; |
| 1834 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1835 | goto out_noupdate; |
| 1836 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1837 | ret = true; |
| 1838 | out_noupdate: |
| 1839 | spin_unlock(&state->state_lock); |
| 1840 | return ret; |
| 1841 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1842 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1843 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1844 | { |
| 1845 | struct nfs_delegation *delegation; |
| 1846 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1847 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1848 | rcu_read_lock(); |
Trond Myklebust | 40e6aa1 | 2019-10-27 13:38:45 -0400 | [diff] [blame] | 1849 | delegation = nfs4_get_valid_delegation(inode); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1850 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1851 | rcu_read_unlock(); |
| 1852 | return; |
| 1853 | } |
| 1854 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1855 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1856 | } |
| 1857 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1858 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1859 | { |
| 1860 | struct nfs4_state *state = opendata->state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1861 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1862 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1863 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1864 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1865 | nfs4_stateid stateid; |
| 1866 | int ret = -EAGAIN; |
| 1867 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1868 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1869 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1870 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1871 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1872 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1873 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1874 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1875 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1876 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 1877 | delegation = nfs4_get_valid_delegation(state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1878 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1879 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1880 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1881 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1882 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1883 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1884 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1885 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1886 | if (!opendata->is_recover) { |
| 1887 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1888 | if (ret != 0) |
| 1889 | goto out; |
| 1890 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1891 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1892 | |
| 1893 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1894 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1895 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1896 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1897 | out: |
| 1898 | return ERR_PTR(ret); |
| 1899 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1900 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1901 | return state; |
| 1902 | } |
| 1903 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1904 | static void |
| 1905 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1906 | { |
| 1907 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1908 | struct nfs_delegation *delegation; |
| 1909 | int delegation_flags = 0; |
| 1910 | |
| 1911 | rcu_read_lock(); |
| 1912 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1913 | if (delegation) |
| 1914 | delegation_flags = delegation->flags; |
| 1915 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1916 | switch (data->o_arg.claim) { |
| 1917 | default: |
| 1918 | break; |
| 1919 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1920 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1921 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1922 | "returning a delegation for " |
| 1923 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1924 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1925 | return; |
| 1926 | } |
| 1927 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1928 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1929 | data->owner->so_cred, |
| 1930 | data->o_res.delegation_type, |
| 1931 | &data->o_res.delegation, |
| 1932 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1933 | else |
| 1934 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1935 | data->owner->so_cred, |
| 1936 | data->o_res.delegation_type, |
| 1937 | &data->o_res.delegation, |
| 1938 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1939 | |
| 1940 | if (data->o_res.do_recall) |
| 1941 | nfs_async_inode_return_delegation(state->inode, |
| 1942 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | /* |
| 1946 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1947 | * and update the nfs4_state. |
| 1948 | */ |
| 1949 | static struct nfs4_state * |
| 1950 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1951 | { |
| 1952 | struct inode *inode = data->state->inode; |
| 1953 | struct nfs4_state *state = data->state; |
| 1954 | int ret; |
| 1955 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1956 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1957 | if (data->rpc_status) |
| 1958 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1959 | /* cached opens have already been processed */ |
| 1960 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1961 | } |
| 1962 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1963 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1964 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1965 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1966 | |
| 1967 | if (data->o_res.delegation_type != 0) |
| 1968 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1969 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1970 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1971 | NULL, data->o_arg.fmode)) |
| 1972 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1973 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1974 | |
| 1975 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1976 | } |
| 1977 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1978 | static struct inode * |
| 1979 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1980 | { |
| 1981 | struct inode *inode; |
| 1982 | |
| 1983 | switch (data->o_arg.claim) { |
| 1984 | case NFS4_OPEN_CLAIM_NULL: |
| 1985 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1986 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1987 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1988 | return ERR_PTR(-EAGAIN); |
| 1989 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1990 | &data->f_attr, data->f_label); |
| 1991 | break; |
| 1992 | default: |
| 1993 | inode = d_inode(data->dentry); |
| 1994 | ihold(inode); |
| 1995 | nfs_refresh_inode(inode, &data->f_attr); |
| 1996 | } |
| 1997 | return inode; |
| 1998 | } |
| 1999 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2000 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2001 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 2002 | { |
| 2003 | struct nfs4_state *state; |
| 2004 | struct inode *inode; |
| 2005 | |
| 2006 | inode = nfs4_opendata_get_inode(data); |
| 2007 | if (IS_ERR(inode)) |
| 2008 | return ERR_CAST(inode); |
| 2009 | if (data->state != NULL && data->state->inode == inode) { |
| 2010 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2011 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2012 | } else |
| 2013 | state = nfs4_get_open_state(inode, data->owner); |
| 2014 | iput(inode); |
| 2015 | if (state == NULL) |
| 2016 | state = ERR_PTR(-ENOMEM); |
| 2017 | return state; |
| 2018 | } |
| 2019 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2020 | static struct nfs4_state * |
| 2021 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2022 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2023 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2024 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2025 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2026 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2027 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2028 | goto out; |
| 2029 | } |
| 2030 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 2031 | state = nfs4_opendata_find_nfs4_state(data); |
| 2032 | if (IS_ERR(state)) |
| 2033 | goto out; |
| 2034 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2035 | if (data->o_res.delegation_type != 0) |
| 2036 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 2037 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 2038 | NULL, data->o_arg.fmode)) { |
| 2039 | nfs4_put_open_state(state); |
| 2040 | state = ERR_PTR(-EAGAIN); |
| 2041 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2042 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 2043 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2044 | return state; |
| 2045 | } |
| 2046 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2047 | static struct nfs4_state * |
| 2048 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2049 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2050 | struct nfs4_state *ret; |
| 2051 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2052 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2053 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2054 | else |
| 2055 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2056 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2057 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2058 | } |
| 2059 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2060 | static struct nfs_open_context * |
| 2061 | 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] | 2062 | { |
| 2063 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2064 | struct nfs_open_context *ctx; |
| 2065 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2066 | rcu_read_lock(); |
| 2067 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2068 | if (ctx->state != state) |
| 2069 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2070 | if ((ctx->mode & mode) != mode) |
| 2071 | continue; |
| 2072 | if (!get_nfs_open_context(ctx)) |
| 2073 | continue; |
| 2074 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2075 | return ctx; |
| 2076 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2077 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2078 | return ERR_PTR(-ENOENT); |
| 2079 | } |
| 2080 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2081 | static struct nfs_open_context * |
| 2082 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2083 | { |
| 2084 | struct nfs_open_context *ctx; |
| 2085 | |
| 2086 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2087 | if (!IS_ERR(ctx)) |
| 2088 | return ctx; |
| 2089 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2090 | if (!IS_ERR(ctx)) |
| 2091 | return ctx; |
| 2092 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2093 | } |
| 2094 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2095 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2096 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2097 | { |
| 2098 | struct nfs4_opendata *opendata; |
| 2099 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2100 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2101 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2102 | if (opendata == NULL) |
| 2103 | return ERR_PTR(-ENOMEM); |
| 2104 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2105 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2106 | return opendata; |
| 2107 | } |
| 2108 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2109 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2110 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2111 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2112 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2113 | int ret; |
| 2114 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2115 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2116 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2117 | opendata->o_arg.open_flags = 0; |
| 2118 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2119 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2120 | NFS_SB(opendata->dentry->d_sb), |
| 2121 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2122 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2123 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2124 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2125 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2126 | if (ret != 0) |
| 2127 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2128 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2129 | if (IS_ERR(newstate)) |
| 2130 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2131 | if (newstate != opendata->state) |
| 2132 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2133 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2134 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2138 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2139 | int ret; |
| 2140 | |
| 2141 | /* memory barrier prior to reading state->n_* */ |
| 2142 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2143 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2144 | if (ret != 0) |
| 2145 | return ret; |
| 2146 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2147 | if (ret != 0) |
| 2148 | return ret; |
| 2149 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2150 | if (ret != 0) |
| 2151 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2152 | /* |
| 2153 | * We may have performed cached opens for all three recoveries. |
| 2154 | * Check if we need to update the current stateid. |
| 2155 | */ |
| 2156 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2157 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2158 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2159 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2160 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2161 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2162 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2163 | return 0; |
| 2164 | } |
| 2165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | /* |
| 2167 | * OPEN_RECLAIM: |
| 2168 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2170 | 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] | 2171 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2172 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2173 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2174 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | int status; |
| 2176 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2177 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2178 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2179 | if (IS_ERR(opendata)) |
| 2180 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2181 | rcu_read_lock(); |
| 2182 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2183 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2184 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2185 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2186 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2187 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2188 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | return status; |
| 2190 | } |
| 2191 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2192 | static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | { |
| 2194 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2195 | struct nfs4_exception exception = { }; |
| 2196 | int err; |
| 2197 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2198 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2199 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2200 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2201 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2202 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2203 | break; |
| 2204 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | } while (exception.retry); |
| 2206 | return err; |
| 2207 | } |
| 2208 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2209 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2210 | { |
| 2211 | struct nfs_open_context *ctx; |
| 2212 | int ret; |
| 2213 | |
| 2214 | ctx = nfs4_state_find_open_context(state); |
| 2215 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2216 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2217 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2218 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2219 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2220 | put_nfs_open_context(ctx); |
| 2221 | return ret; |
| 2222 | } |
| 2223 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2224 | 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] | 2225 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2226 | switch (err) { |
| 2227 | default: |
| 2228 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2229 | "%d.\n", __func__, err); |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame^] | 2230 | fallthrough; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2231 | case 0: |
| 2232 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2233 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2234 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2235 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2236 | break; |
| 2237 | case -NFS4ERR_BADSESSION: |
| 2238 | case -NFS4ERR_BADSLOT: |
| 2239 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2240 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2241 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2242 | return -EAGAIN; |
| 2243 | case -NFS4ERR_STALE_CLIENTID: |
| 2244 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2245 | /* Don't recall a delegation if it was lost */ |
| 2246 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2247 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2248 | case -NFS4ERR_MOVED: |
| 2249 | nfs4_schedule_migration_recovery(server); |
| 2250 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2251 | case -NFS4ERR_LEASE_MOVED: |
| 2252 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2253 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2254 | case -NFS4ERR_DELEG_REVOKED: |
| 2255 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2256 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2257 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2258 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2259 | nfs_inode_find_state_and_recover(state->inode, |
| 2260 | stateid); |
| 2261 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2262 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2263 | case -NFS4ERR_DELAY: |
| 2264 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2265 | ssleep(1); |
| 2266 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2267 | case -ENOMEM: |
| 2268 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2269 | if (fl) { |
| 2270 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2271 | if (lsp) |
| 2272 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2273 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2274 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2275 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | return err; |
| 2277 | } |
| 2278 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2279 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2280 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2281 | { |
| 2282 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2283 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2284 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2285 | |
| 2286 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2287 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2288 | if (IS_ERR(opendata)) |
| 2289 | return PTR_ERR(opendata); |
| 2290 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2291 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2292 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2293 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2294 | goto out; |
| 2295 | } |
| 2296 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2297 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2298 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2299 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2300 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2301 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2302 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2303 | if (err) |
| 2304 | goto out; |
| 2305 | } |
| 2306 | nfs_state_clear_delegation(state); |
| 2307 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2308 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2309 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2310 | } |
| 2311 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2312 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2313 | { |
| 2314 | struct nfs4_opendata *data = calldata; |
| 2315 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2316 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2317 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2318 | } |
| 2319 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2320 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2321 | { |
| 2322 | struct nfs4_opendata *data = calldata; |
| 2323 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2324 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2325 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2326 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2327 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2328 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2329 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2330 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2331 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2332 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | static void nfs4_open_confirm_release(void *calldata) |
| 2336 | { |
| 2337 | struct nfs4_opendata *data = calldata; |
| 2338 | struct nfs4_state *state = NULL; |
| 2339 | |
| 2340 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2341 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2342 | goto out_free; |
| 2343 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2344 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2345 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2346 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2347 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2348 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2349 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2350 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2354 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2355 | .rpc_call_done = nfs4_open_confirm_done, |
| 2356 | .rpc_release = nfs4_open_confirm_release, |
| 2357 | }; |
| 2358 | |
| 2359 | /* |
| 2360 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2361 | */ |
| 2362 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2363 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2364 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2365 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2366 | struct rpc_message msg = { |
| 2367 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2368 | .rpc_argp = &data->c_arg, |
| 2369 | .rpc_resp = &data->c_res, |
| 2370 | .rpc_cred = data->owner->so_cred, |
| 2371 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2372 | struct rpc_task_setup task_setup_data = { |
| 2373 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2374 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2375 | .callback_ops = &nfs4_open_confirm_ops, |
| 2376 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2377 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2378 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2379 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | int status; |
| 2381 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2382 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2383 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2384 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2385 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2386 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2387 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2388 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2389 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2390 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2391 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2392 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2393 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2394 | smp_wmb(); |
| 2395 | } else |
| 2396 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2397 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | return status; |
| 2399 | } |
| 2400 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2401 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2403 | struct nfs4_opendata *data = calldata; |
| 2404 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2405 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2406 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2407 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2408 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2409 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2410 | /* |
| 2411 | * Check if we still need to send an OPEN call, or if we can use |
| 2412 | * a delegation instead. |
| 2413 | */ |
| 2414 | if (data->state != NULL) { |
| 2415 | struct nfs_delegation *delegation; |
| 2416 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2417 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2418 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2419 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2420 | rcu_read_lock(); |
Trond Myklebust | be3df3d | 2019-10-31 18:40:32 -0400 | [diff] [blame] | 2421 | delegation = nfs4_get_valid_delegation(data->state->inode); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2422 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2423 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2424 | rcu_read_unlock(); |
| 2425 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2426 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2427 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2428 | switch (claim) { |
| 2429 | default: |
| 2430 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2431 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2432 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2433 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2434 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2435 | fallthrough; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2436 | case NFS4_OPEN_CLAIM_FH: |
| 2437 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2438 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2439 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2440 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2441 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2442 | &data->o_res.seq_res, |
| 2443 | task) != 0) |
| 2444 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2445 | |
| 2446 | /* Set the create mode (note dependency on the session type) */ |
| 2447 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2448 | if (data->o_arg.open_flags & O_EXCL) { |
| 2449 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2450 | if (nfs4_has_persistent_session(clp)) |
| 2451 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2452 | else if (clp->cl_mvops->minor_version > 0) |
| 2453 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2454 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2455 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2456 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2457 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2458 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2459 | out_no_action: |
| 2460 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2461 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2462 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2463 | } |
| 2464 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2465 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2466 | { |
| 2467 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2469 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2470 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2471 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2472 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2473 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2474 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2475 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2476 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2477 | case S_IFREG: |
| 2478 | break; |
| 2479 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2480 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2481 | break; |
| 2482 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2483 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2484 | break; |
| 2485 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2486 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2487 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2488 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2489 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2490 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2491 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2492 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2493 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2494 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2495 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2496 | static void nfs4_open_release(void *calldata) |
| 2497 | { |
| 2498 | struct nfs4_opendata *data = calldata; |
| 2499 | struct nfs4_state *state = NULL; |
| 2500 | |
| 2501 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2502 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2503 | goto out_free; |
| 2504 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2505 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2506 | goto out_free; |
| 2507 | /* In case we need an open_confirm, no cleanup! */ |
| 2508 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2509 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2510 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2511 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2512 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2513 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2514 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2518 | .rpc_call_prepare = nfs4_open_prepare, |
| 2519 | .rpc_call_done = nfs4_open_done, |
| 2520 | .rpc_release = nfs4_open_release, |
| 2521 | }; |
| 2522 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2523 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2524 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2525 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2526 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2527 | struct nfs_server *server = NFS_SERVER(dir); |
| 2528 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2529 | struct nfs_openres *o_res = &data->o_res; |
| 2530 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2531 | struct rpc_message msg = { |
| 2532 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2533 | .rpc_argp = o_arg, |
| 2534 | .rpc_resp = o_res, |
| 2535 | .rpc_cred = data->owner->so_cred, |
| 2536 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2537 | struct rpc_task_setup task_setup_data = { |
| 2538 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2539 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2540 | .callback_ops = &nfs4_open_ops, |
| 2541 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2542 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 2543 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2544 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2545 | int status; |
| 2546 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2547 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2548 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2549 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2550 | data->cancelled = false; |
| 2551 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2552 | if (!ctx) { |
| 2553 | 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] | 2554 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2555 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2556 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2557 | 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] | 2558 | pnfs_lgopen_prepare(data, ctx); |
| 2559 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2560 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2561 | if (IS_ERR(task)) |
| 2562 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2563 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2564 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2565 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2566 | smp_wmb(); |
| 2567 | } else |
| 2568 | status = data->rpc_status; |
| 2569 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2570 | |
| 2571 | return status; |
| 2572 | } |
| 2573 | |
| 2574 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2575 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2576 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2577 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2578 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2579 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2580 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2581 | if (status != 0 || !data->rpc_done) |
| 2582 | return status; |
| 2583 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2584 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2585 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2586 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2587 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2588 | |
| 2589 | return status; |
| 2590 | } |
| 2591 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2592 | /* |
| 2593 | * Additional permission checks in order to distinguish between an |
| 2594 | * open for read, and an open for execute. This works around the |
| 2595 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2596 | * the same. |
| 2597 | * Note that in the non-execute case, we want to turn off permission |
| 2598 | * checking if we just created a new file (POSIX open() semantics). |
| 2599 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2600 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2601 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2602 | struct nfs4_state *state, fmode_t fmode, |
| 2603 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2604 | { |
| 2605 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2606 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2607 | |
| 2608 | /* access call failed or for some reason the server doesn't |
| 2609 | * support any access modes -- defer access call until later */ |
| 2610 | if (opendata->o_res.access_supported == 0) |
| 2611 | return 0; |
| 2612 | |
| 2613 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2614 | /* |
| 2615 | * Use openflags to check for exec, because fmode won't |
| 2616 | * always have FMODE_EXEC set when file open for exec. |
| 2617 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2618 | if (openflags & __FMODE_EXEC) { |
| 2619 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2620 | if (S_ISDIR(state->inode->i_mode)) |
| 2621 | mask = NFS4_ACCESS_LOOKUP; |
| 2622 | else |
| 2623 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2624 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2625 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2626 | |
| 2627 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2628 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2629 | nfs_access_add_cache(state->inode, &cache); |
| 2630 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2631 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2632 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2633 | return 0; |
| 2634 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2635 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2636 | } |
| 2637 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2638 | /* |
| 2639 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2640 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2641 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2642 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2643 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2644 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2645 | struct nfs_server *server = NFS_SERVER(dir); |
| 2646 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2647 | struct nfs_openres *o_res = &data->o_res; |
| 2648 | int status; |
| 2649 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2650 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2651 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2652 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2653 | if (status != 0) { |
| 2654 | if (status == -NFS4ERR_BADNAME && |
| 2655 | !(o_arg->open_flags & O_CREAT)) |
| 2656 | return -ENOENT; |
| 2657 | return status; |
| 2658 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2659 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2660 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2661 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2662 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2663 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2664 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2665 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2666 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2667 | if (data->file_created || |
| 2668 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 2669 | nfs4_update_changeattr(dir, &o_res->cinfo, |
| 2670 | o_res->f_attr->time_start, |
| 2671 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2672 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2673 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2674 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2676 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2678 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2680 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2681 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2682 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2683 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2684 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2685 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | } |
| 2687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | /* |
| 2689 | * OPEN_EXPIRED: |
| 2690 | * reclaim state on the server after a network partition. |
| 2691 | * Assumes caller holds the appropriate lock |
| 2692 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2693 | 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] | 2694 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2695 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2696 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2698 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2699 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2700 | if (IS_ERR(opendata)) |
| 2701 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2702 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2703 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2704 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2705 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2706 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2709 | 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] | 2710 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2711 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2712 | struct nfs4_exception exception = { }; |
| 2713 | int err; |
| 2714 | |
| 2715 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2716 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2717 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2718 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2719 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2720 | switch (err) { |
| 2721 | default: |
| 2722 | goto out; |
| 2723 | case -NFS4ERR_GRACE: |
| 2724 | case -NFS4ERR_DELAY: |
| 2725 | nfs4_handle_exception(server, err, &exception); |
| 2726 | err = 0; |
| 2727 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2728 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2729 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2730 | return err; |
| 2731 | } |
| 2732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2734 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2736 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2738 | ctx = nfs4_state_find_open_context(state); |
| 2739 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2740 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2741 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2742 | put_nfs_open_context(ctx); |
| 2743 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2746 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2747 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2748 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2749 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2750 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2754 | { |
| 2755 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2756 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2760 | { |
| 2761 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2762 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2763 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2764 | return nfs4_open_expired(sp, state); |
| 2765 | } |
| 2766 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2767 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2768 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2769 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2770 | { |
| 2771 | return -NFS4ERR_BAD_STATEID; |
| 2772 | } |
| 2773 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2774 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2775 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2776 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2777 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2778 | { |
| 2779 | int status; |
| 2780 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2781 | switch (stateid->type) { |
| 2782 | default: |
| 2783 | break; |
| 2784 | case NFS4_INVALID_STATEID_TYPE: |
| 2785 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2786 | return -NFS4ERR_BAD_STATEID; |
| 2787 | case NFS4_REVOKED_STATEID_TYPE: |
| 2788 | goto out_free; |
| 2789 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2790 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2791 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2792 | switch (status) { |
| 2793 | case -NFS4ERR_EXPIRED: |
| 2794 | case -NFS4ERR_ADMIN_REVOKED: |
| 2795 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2796 | break; |
| 2797 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2798 | return status; |
| 2799 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2800 | out_free: |
| 2801 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2802 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2803 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2804 | } |
| 2805 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2806 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2807 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2808 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2809 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2810 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2811 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2812 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2813 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2814 | /* Get the delegation credential for use by test/free_stateid */ |
| 2815 | rcu_read_lock(); |
| 2816 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2817 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2818 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2819 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2820 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2821 | } |
| 2822 | |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2823 | spin_lock(&delegation->lock); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2824 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2825 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2826 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2827 | &delegation->flags)) { |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2828 | spin_unlock(&delegation->lock); |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2829 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2830 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2831 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2832 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2833 | if (delegation->cred) |
| 2834 | cred = get_cred(delegation->cred); |
Trond Myklebust | fc51b1c | 2020-04-02 15:27:09 -0400 | [diff] [blame] | 2835 | spin_unlock(&delegation->lock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2836 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2837 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2838 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2839 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2840 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2841 | else |
| 2842 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2843 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2844 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2845 | return ret; |
| 2846 | } |
| 2847 | |
| 2848 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2849 | { |
| 2850 | nfs4_stateid tmp; |
| 2851 | |
| 2852 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2853 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2854 | &tmp, NULL) && |
| 2855 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2856 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2857 | else |
| 2858 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2862 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2863 | * |
| 2864 | * @state: NFSv4 state for an inode |
| 2865 | * |
| 2866 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2867 | * Otherwise a negative NFS4ERR value is returned. |
| 2868 | */ |
| 2869 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2870 | { |
| 2871 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2872 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2873 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2874 | |
| 2875 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2876 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2877 | |
| 2878 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2879 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2880 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2881 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2882 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2883 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2884 | spin_unlock(&state->state_lock); |
| 2885 | |
| 2886 | nfs4_put_lock_state(prev); |
| 2887 | prev = lsp; |
| 2888 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2889 | status = nfs41_test_and_free_expired_stateid(server, |
| 2890 | &lsp->ls_stateid, |
| 2891 | cred); |
| 2892 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2893 | if (status == -NFS4ERR_EXPIRED || |
| 2894 | status == -NFS4ERR_BAD_STATEID) { |
| 2895 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2896 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2897 | if (!recover_lost_locks) |
| 2898 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2899 | } else if (status != NFS_OK) { |
| 2900 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2901 | nfs4_put_lock_state(prev); |
| 2902 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2903 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2904 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2905 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2906 | } |
| 2907 | spin_unlock(&state->state_lock); |
| 2908 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2909 | out: |
| 2910 | return ret; |
| 2911 | } |
| 2912 | |
| 2913 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2914 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2915 | * |
| 2916 | * @state: NFSv4 state for an inode |
| 2917 | * |
| 2918 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2919 | * Otherwise a negative NFS4ERR value is returned. |
| 2920 | */ |
| 2921 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2922 | { |
| 2923 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2924 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2925 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2926 | int status; |
| 2927 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2928 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2929 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2930 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2931 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2932 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2933 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2934 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2935 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2936 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2937 | if (nfs_open_stateid_recover_openmode(state)) |
| 2938 | return -NFS4ERR_OPENMODE; |
| 2939 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2943 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2944 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2945 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2946 | status = nfs41_check_delegation_stateid(state); |
| 2947 | if (status != NFS_OK) |
| 2948 | return status; |
| 2949 | nfs41_delegation_recover_stateid(state); |
| 2950 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2951 | status = nfs41_check_expired_locks(state); |
| 2952 | if (status != NFS_OK) |
| 2953 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2954 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2955 | if (status != NFS_OK) |
| 2956 | status = nfs4_open_expired(sp, state); |
| 2957 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2958 | } |
| 2959 | #endif |
| 2960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2962 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2963 | * fields corresponding to attributes that were used to store the verifier. |
| 2964 | * Make sure we clobber those fields in the later setattr call |
| 2965 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2966 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2967 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2968 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2969 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2970 | __u32 attrset[3]; |
| 2971 | unsigned ret; |
| 2972 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2973 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2974 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2975 | attrset[i] = opendata->o_res.attrset[i]; |
| 2976 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2977 | attrset[i] &= ~bitmask[i]; |
| 2978 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2979 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2980 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2981 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2982 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2983 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2984 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2985 | ret |= ATTR_ATIME_SET; |
| 2986 | else |
| 2987 | ret |= ATTR_ATIME; |
| 2988 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2989 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2990 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2991 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2992 | ret |= ATTR_MTIME_SET; |
| 2993 | else |
| 2994 | ret |= ATTR_MTIME; |
| 2995 | } |
| 2996 | |
| 2997 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2998 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2999 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3000 | } |
| 3001 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3002 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3003 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3004 | { |
| 3005 | struct nfs4_state_owner *sp = opendata->owner; |
| 3006 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3007 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3008 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3009 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3010 | struct inode *dir = d_inode(opendata->dir); |
| 3011 | unsigned long dir_verifier; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3012 | unsigned int seq; |
| 3013 | int ret; |
| 3014 | |
| 3015 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3016 | dir_verifier = nfs_save_change_attribute(dir); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3017 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 3018 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 3019 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3020 | goto out; |
| 3021 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 3022 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3023 | ret = PTR_ERR(state); |
| 3024 | if (IS_ERR(state)) |
| 3025 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 3026 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3027 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 3028 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 3029 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 3030 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3031 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3032 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3033 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3034 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3035 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3036 | alias = d_exact_alias(dentry, state->inode); |
| 3037 | if (!alias) |
| 3038 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 3039 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 3040 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3041 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 3042 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3043 | } |
Trond Myklebust | cf5b405 | 2020-02-05 09:01:53 -0500 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | switch(opendata->o_arg.claim) { |
| 3047 | default: |
| 3048 | break; |
| 3049 | case NFS4_OPEN_CLAIM_NULL: |
| 3050 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 3051 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 3052 | if (!opendata->rpc_done) |
| 3053 | break; |
| 3054 | if (opendata->o_res.delegation_type != 0) |
| 3055 | dir_verifier = nfs_save_change_attribute(dir); |
| 3056 | nfs_set_verifier(dentry, dir_verifier); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3057 | } |
| 3058 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 3059 | /* Parse layoutget results before we check for access */ |
| 3060 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 3061 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3062 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 3063 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3064 | if (ret != 0) |
| 3065 | goto out; |
| 3066 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3067 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3068 | nfs_inode_attach_open_context(ctx); |
| 3069 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3070 | nfs4_schedule_stateid_recovery(server, state); |
| 3071 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3072 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3073 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3074 | if (!opendata->cancelled) |
| 3075 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3076 | return ret; |
| 3077 | } |
| 3078 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3079 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3080 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3082 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3083 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3084 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3085 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3086 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | { |
| 3088 | struct nfs4_state_owner *sp; |
| 3089 | struct nfs4_state *state = NULL; |
| 3090 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3091 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3092 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3093 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3094 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3095 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3096 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3097 | struct iattr *sattr = c->sattr; |
| 3098 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3099 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3100 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | |
| 3102 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3104 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3105 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3107 | goto out_err; |
| 3108 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3109 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3110 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3111 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3112 | if (d_really_is_positive(dentry)) |
| 3113 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3114 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3115 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3116 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3117 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3118 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3119 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3120 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3122 | if (label) { |
| 3123 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 3124 | if (IS_ERR(olabel)) { |
| 3125 | status = PTR_ERR(olabel); |
| 3126 | goto err_opendata_put; |
| 3127 | } |
| 3128 | } |
| 3129 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3130 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3131 | if (!opendata->f_attr.mdsthreshold) { |
| 3132 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3133 | if (!opendata->f_attr.mdsthreshold) |
| 3134 | goto err_free_label; |
| 3135 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3136 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3137 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3138 | if (d_really_is_positive(dentry)) |
| 3139 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3140 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3141 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3142 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3143 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3144 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3145 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3146 | 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] | 3147 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3148 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3149 | /* |
| 3150 | * send create attributes which was not set by open |
| 3151 | * with an extra setattr. |
| 3152 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3153 | if (attrs || label) { |
| 3154 | unsigned ia_old = sattr->ia_valid; |
| 3155 | |
| 3156 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3157 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3158 | status = nfs4_do_setattr(state->inode, cred, |
| 3159 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3160 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3161 | if (status == 0) { |
| 3162 | nfs_setattr_update_inode(state->inode, sattr, |
| 3163 | opendata->o_res.f_attr); |
| 3164 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 3165 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3166 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3167 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3168 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3169 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3170 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3171 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3172 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3173 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3174 | opendata->f_attr.mdsthreshold = NULL; |
| 3175 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3176 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3177 | nfs4_label_free(olabel); |
| 3178 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3179 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3182 | err_free_label: |
| 3183 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3184 | err_opendata_put: |
| 3185 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3186 | err_put_state_owner: |
| 3187 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | return status; |
| 3190 | } |
| 3191 | |
| 3192 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3193 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3194 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3195 | int flags, |
| 3196 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3197 | struct nfs4_label *label, |
| 3198 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3200 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3201 | struct nfs4_exception exception = { |
| 3202 | .interruptible = true, |
| 3203 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3205 | struct nfs4_open_createattrs c = { |
| 3206 | .label = label, |
| 3207 | .sattr = sattr, |
| 3208 | .verf = { |
| 3209 | [0] = (__u32)jiffies, |
| 3210 | [1] = (__u32)current->pid, |
| 3211 | }, |
| 3212 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | int status; |
| 3214 | |
| 3215 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3216 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3217 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3218 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | if (status == 0) |
| 3220 | break; |
| 3221 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3222 | * book-keeping w.r.t. state-changing operations |
| 3223 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3224 | * It is actually a sign of a bug on the client or on the server. |
| 3225 | * |
| 3226 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3227 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | * have unhashed the old state_owner for us, and that we can |
| 3229 | * therefore safely retry using a new one. We should still warn |
| 3230 | * the user though... |
| 3231 | */ |
| 3232 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3233 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3234 | " returned a bad sequence-id error!\n", |
| 3235 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | exception.retry = 1; |
| 3237 | continue; |
| 3238 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3239 | /* |
| 3240 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3241 | * state before it received the OPEN_CONFIRM. |
| 3242 | * Recover by retrying the request as per the discussion |
| 3243 | * on Page 181 of RFC3530. |
| 3244 | */ |
| 3245 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3246 | exception.retry = 1; |
| 3247 | continue; |
| 3248 | } |
Robert Milkowski | 924491f | 2020-01-28 08:37:47 +0000 | [diff] [blame] | 3249 | if (status == -NFS4ERR_EXPIRED) { |
| 3250 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 3251 | exception.retry = 1; |
| 3252 | continue; |
| 3253 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3254 | if (status == -EAGAIN) { |
| 3255 | /* We must have found a delegation */ |
| 3256 | exception.retry = 1; |
| 3257 | continue; |
| 3258 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3259 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3260 | continue; |
| 3261 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | status, &exception)); |
| 3263 | } while (exception.retry); |
| 3264 | return res; |
| 3265 | } |
| 3266 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3267 | static int _nfs4_do_setattr(struct inode *inode, |
| 3268 | struct nfs_setattrargs *arg, |
| 3269 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3270 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3271 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3272 | { |
| 3273 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3274 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3275 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3276 | .rpc_argp = arg, |
| 3277 | .rpc_resp = res, |
| 3278 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3279 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3280 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3281 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3282 | bool truncate; |
| 3283 | int status; |
| 3284 | |
| 3285 | nfs_fattr_init(res->fattr); |
| 3286 | |
| 3287 | /* Servers should only apply open mode checks for file size changes */ |
| 3288 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3289 | if (!truncate) { |
| 3290 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3291 | goto zero_stateid; |
Chuck Lever | 644c9f4 | 2020-09-04 17:39:12 -0400 | [diff] [blame] | 3292 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3293 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3294 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3295 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3296 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3297 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3298 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3299 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3300 | l_ctx = nfs_get_lock_context(ctx); |
| 3301 | if (IS_ERR(l_ctx)) |
| 3302 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3303 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3304 | &arg->stateid, &delegation_cred); |
| 3305 | nfs_put_lock_context(l_ctx); |
| 3306 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3307 | return -EBADF; |
Olga Kornievskaia | d826e5b | 2019-12-18 16:50:42 -0500 | [diff] [blame] | 3308 | else if (status == -EAGAIN) |
| 3309 | goto zero_stateid; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3310 | } else { |
| 3311 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3312 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3313 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3314 | if (delegation_cred) |
| 3315 | msg.rpc_cred = delegation_cred; |
| 3316 | |
| 3317 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3318 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3319 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3320 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3321 | renew_lease(server, timestamp); |
| 3322 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3323 | return status; |
| 3324 | } |
| 3325 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3326 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3327 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3328 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3329 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3331 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3332 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3333 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3334 | struct nfs_setattrargs arg = { |
| 3335 | .fh = NFS_FH(inode), |
| 3336 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3338 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3339 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3340 | }; |
| 3341 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3343 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3345 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3346 | struct nfs4_exception exception = { |
| 3347 | .state = state, |
| 3348 | .inode = inode, |
| 3349 | .stateid = &arg.stateid, |
| 3350 | }; |
| 3351 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3354 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3355 | nfs4_bitmask(server, olabel), |
| 3356 | inode); |
| 3357 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3358 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3359 | switch (err) { |
| 3360 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3361 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3362 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3363 | "applying open mode checks to " |
| 3364 | "a SETATTR that is not " |
| 3365 | "changing file size.\n", |
| 3366 | server->nfs_client->cl_hostname); |
| 3367 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3368 | if (state && !(state->state & FMODE_WRITE)) { |
| 3369 | err = -EBADF; |
| 3370 | if (sattr->ia_valid & ATTR_OPEN) |
| 3371 | err = -EACCES; |
| 3372 | goto out; |
| 3373 | } |
| 3374 | } |
| 3375 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3377 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | return err; |
| 3379 | } |
| 3380 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3381 | static bool |
| 3382 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3383 | { |
| 3384 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3385 | return false; |
| 3386 | |
| 3387 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3388 | } |
| 3389 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3390 | /* |
| 3391 | * Update the seqid of an open stateid |
| 3392 | */ |
| 3393 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3394 | struct nfs4_state *state) |
| 3395 | { |
| 3396 | __be32 seqid_open; |
| 3397 | u32 dst_seqid; |
| 3398 | int seq; |
| 3399 | |
| 3400 | for (;;) { |
| 3401 | if (!nfs4_valid_open_stateid(state)) |
| 3402 | break; |
| 3403 | seq = read_seqbegin(&state->seqlock); |
| 3404 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3405 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3406 | if (read_seqretry(&state->seqlock, seq)) |
| 3407 | continue; |
| 3408 | break; |
| 3409 | } |
| 3410 | seqid_open = state->open_stateid.seqid; |
| 3411 | if (read_seqretry(&state->seqlock, seq)) |
| 3412 | continue; |
| 3413 | |
| 3414 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3415 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3416 | dst->seqid = seqid_open; |
| 3417 | break; |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | /* |
| 3422 | * Update the seqid of an open stateid after receiving |
| 3423 | * NFS4ERR_OLD_STATEID |
| 3424 | */ |
| 3425 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3426 | struct nfs4_state *state) |
| 3427 | { |
| 3428 | __be32 seqid_open; |
| 3429 | u32 dst_seqid; |
| 3430 | bool ret; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3431 | int seq, status = -EAGAIN; |
| 3432 | DEFINE_WAIT(wait); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3433 | |
| 3434 | for (;;) { |
| 3435 | ret = false; |
| 3436 | if (!nfs4_valid_open_stateid(state)) |
| 3437 | break; |
| 3438 | seq = read_seqbegin(&state->seqlock); |
| 3439 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3440 | if (read_seqretry(&state->seqlock, seq)) |
| 3441 | continue; |
| 3442 | break; |
| 3443 | } |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3444 | |
| 3445 | write_seqlock(&state->seqlock); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3446 | seqid_open = state->open_stateid.seqid; |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3447 | |
| 3448 | dst_seqid = be32_to_cpu(dst->seqid); |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3449 | |
| 3450 | /* Did another OPEN bump the state's seqid? try again: */ |
| 3451 | if ((s32)(be32_to_cpu(seqid_open) - dst_seqid) > 0) { |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3452 | dst->seqid = seqid_open; |
Benjamin Coddington | b4868b4 | 2020-09-25 15:48:39 -0400 | [diff] [blame] | 3453 | write_sequnlock(&state->seqlock); |
| 3454 | ret = true; |
| 3455 | break; |
| 3456 | } |
| 3457 | |
| 3458 | /* server says we're behind but we haven't seen the update yet */ |
| 3459 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 3460 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 3461 | write_sequnlock(&state->seqlock); |
| 3462 | trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); |
| 3463 | |
| 3464 | if (signal_pending(current)) |
| 3465 | status = -EINTR; |
| 3466 | else |
| 3467 | if (schedule_timeout(5*HZ) != 0) |
| 3468 | status = 0; |
| 3469 | |
| 3470 | finish_wait(&state->waitq, &wait); |
| 3471 | |
| 3472 | if (!status) |
| 3473 | continue; |
| 3474 | if (status == -EINTR) |
| 3475 | break; |
| 3476 | |
| 3477 | /* we slept the whole 5 seconds, we must have lost a seqid */ |
| 3478 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3479 | ret = true; |
| 3480 | break; |
| 3481 | } |
| 3482 | |
| 3483 | return ret; |
| 3484 | } |
| 3485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | struct nfs4_closedata { |
| 3487 | struct inode *inode; |
| 3488 | struct nfs4_state *state; |
| 3489 | struct nfs_closeargs arg; |
| 3490 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3491 | struct { |
| 3492 | struct nfs4_layoutreturn_args arg; |
| 3493 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3494 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3495 | u32 roc_barrier; |
| 3496 | bool roc; |
| 3497 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3498 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3499 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | }; |
| 3501 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3502 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3503 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3504 | struct nfs4_closedata *calldata = data; |
| 3505 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3506 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3507 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3508 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3509 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3510 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3511 | nfs4_put_open_state(calldata->state); |
| 3512 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3513 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3514 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3515 | kfree(calldata); |
| 3516 | } |
| 3517 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3518 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3520 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3523 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3524 | struct nfs4_exception exception = { |
| 3525 | .state = state, |
| 3526 | .inode = calldata->inode, |
| 3527 | .stateid = &calldata->arg.stateid, |
| 3528 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3530 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3531 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3532 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3533 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3534 | |
| 3535 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 3536 | if (pnfs_roc_done(task, &calldata->arg.lr_args, &calldata->res.lr_res, |
| 3537 | &calldata->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3538 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3539 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3540 | /* 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] | 3541 | * the state_owner. we keep this around to process errors |
| 3542 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | switch (task->tk_status) { |
| 3544 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3545 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3546 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3547 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3548 | case -NFS4ERR_ACCESS: |
| 3549 | if (calldata->arg.bitmask != NULL) { |
| 3550 | calldata->arg.bitmask = NULL; |
| 3551 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3552 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3553 | |
| 3554 | } |
| 3555 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3556 | case -NFS4ERR_OLD_STATEID: |
| 3557 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3558 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3559 | state)) |
| 3560 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3561 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3562 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3564 | case -NFS4ERR_EXPIRED: |
| 3565 | nfs4_free_revoked_stateid(server, |
| 3566 | &calldata->arg.stateid, |
| 3567 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3568 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3569 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3570 | if (calldata->arg.fmode == 0) |
| 3571 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 3572 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3574 | task->tk_status = nfs4_async_handle_exception(task, |
| 3575 | server, task->tk_status, &exception); |
| 3576 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3577 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3579 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3580 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3581 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3582 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3583 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3584 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3585 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3586 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3587 | out_restart: |
| 3588 | task->tk_status = 0; |
| 3589 | rpc_restart_call_prepare(task); |
| 3590 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | } |
| 3592 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3593 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3595 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3596 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3597 | struct inode *inode = calldata->inode; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3598 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3599 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3600 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3601 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3602 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3603 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3604 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3605 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3606 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3607 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3608 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3609 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3610 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3611 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3612 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3613 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3614 | if (state->n_rdonly == 0) |
| 3615 | call_close |= is_rdonly; |
| 3616 | else if (is_rdonly) |
| 3617 | calldata->arg.fmode |= FMODE_READ; |
| 3618 | if (state->n_wronly == 0) |
| 3619 | call_close |= is_wronly; |
| 3620 | else if (is_wronly) |
| 3621 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3622 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3623 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3624 | } else if (is_rdwr) |
| 3625 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3626 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3627 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3628 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3629 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3630 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3631 | |
| 3632 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3633 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3634 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3635 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3636 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3637 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3638 | nfs_release_seqid(calldata->arg.seqid); |
| 3639 | goto out_wait; |
| 3640 | } |
| 3641 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3642 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3643 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3644 | calldata->arg.lr_args = NULL; |
| 3645 | calldata->res.lr_res = NULL; |
| 3646 | } |
| 3647 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3648 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3649 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3650 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3651 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3652 | /* Close-to-open cache consistency revalidation */ |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3653 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3654 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 3655 | nfs4_bitmask_adjust(calldata->arg.bitmask, inode, NFS_SERVER(inode), NULL); |
| 3656 | } else |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3657 | calldata->arg.bitmask = NULL; |
| 3658 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3659 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3660 | calldata->arg.share_access = |
| 3661 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3662 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3663 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3664 | if (calldata->res.fattr == NULL) |
| 3665 | calldata->arg.bitmask = NULL; |
| 3666 | else if (calldata->arg.bitmask == NULL) |
| 3667 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3668 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3669 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3670 | &calldata->arg.seq_args, |
| 3671 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3672 | task) != 0) |
| 3673 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3674 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3675 | return; |
| 3676 | out_no_action: |
| 3677 | task->tk_action = NULL; |
| 3678 | out_wait: |
| 3679 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3682 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3683 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3684 | .rpc_call_done = nfs4_close_done, |
| 3685 | .rpc_release = nfs4_free_closedata, |
| 3686 | }; |
| 3687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | /* |
| 3689 | * It is possible for data to be read/written from a mem-mapped file |
| 3690 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3691 | * This means that we can't safely call nfsv4 close on a file until |
| 3692 | * the inode is cleared. This in turn means that we are not good |
| 3693 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3694 | * share state even when we are done with one of the three share |
| 3695 | * stateid's in the inode. |
| 3696 | * |
| 3697 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3698 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3699 | 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] | 3700 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3701 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3702 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3704 | struct nfs4_state_owner *sp = state->owner; |
| 3705 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3706 | struct rpc_message msg = { |
| 3707 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3708 | .rpc_cred = state->owner->so_cred, |
| 3709 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3710 | struct rpc_task_setup task_setup_data = { |
| 3711 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3712 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3713 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3714 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 3715 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3716 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3717 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3719 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3720 | &task_setup_data.rpc_client, &msg); |
| 3721 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3722 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3724 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3725 | 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] | 3726 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3728 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3729 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3730 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3732 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3733 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3734 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3735 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3736 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3737 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3738 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3739 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3740 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3741 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3742 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3743 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3744 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3745 | if (calldata->lr.roc) { |
| 3746 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3747 | calldata->res.lr_res = &calldata->lr.res; |
| 3748 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3749 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3750 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3751 | msg.rpc_argp = &calldata->arg; |
| 3752 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3753 | task_setup_data.callback_data = calldata; |
| 3754 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3755 | if (IS_ERR(task)) |
| 3756 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3757 | status = 0; |
| 3758 | if (wait) |
| 3759 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3760 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3761 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3762 | out_free_calldata: |
| 3763 | kfree(calldata); |
| 3764 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3765 | nfs4_put_open_state(state); |
| 3766 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3767 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3770 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3771 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3772 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3775 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3776 | |
| 3777 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3779 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3780 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3781 | |
| 3782 | nfs4_label_release_security(label); |
| 3783 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3784 | if (IS_ERR(state)) |
| 3785 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3786 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3789 | 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] | 3790 | { |
| 3791 | if (ctx->state == NULL) |
| 3792 | return; |
| 3793 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3794 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3795 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3796 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3797 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3799 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3800 | #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] | 3801 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3804 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3805 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3806 | struct nfs4_server_caps_arg args = { |
| 3807 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3808 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3809 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | struct nfs4_server_caps_res res = {}; |
| 3811 | struct rpc_message msg = { |
| 3812 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3813 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | .rpc_resp = &res, |
| 3815 | }; |
| 3816 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3817 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3819 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3820 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3821 | FATTR4_WORD0_LINK_SUPPORT | |
| 3822 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3823 | FATTR4_WORD0_ACLSUPPORT; |
| 3824 | if (minorversion) |
| 3825 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3826 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3827 | 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] | 3828 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3829 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3830 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3831 | case 0: |
| 3832 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3833 | res.attr_bitmask[2] = 0; |
| 3834 | break; |
| 3835 | case 1: |
| 3836 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3837 | break; |
| 3838 | case 2: |
| 3839 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3840 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3842 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3843 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3844 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3845 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3846 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3847 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3848 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3849 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | server->caps |= NFS_CAP_ACLS; |
| 3851 | if (res.has_links != 0) |
| 3852 | server->caps |= NFS_CAP_HARDLINKS; |
| 3853 | if (res.has_symlinks != 0) |
| 3854 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3855 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3856 | server->caps |= NFS_CAP_FILEID; |
| 3857 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3858 | server->caps |= NFS_CAP_MODE; |
| 3859 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3860 | server->caps |= NFS_CAP_NLINK; |
| 3861 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3862 | server->caps |= NFS_CAP_OWNER; |
| 3863 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3864 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3865 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3866 | server->caps |= NFS_CAP_ATIME; |
| 3867 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3868 | server->caps |= NFS_CAP_CTIME; |
| 3869 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3870 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3871 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3872 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3873 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3874 | #endif |
| 3875 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3876 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3877 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3878 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3879 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3880 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3881 | 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] | 3882 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3883 | |
| 3884 | /* Avoid a regression due to buggy server */ |
| 3885 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3886 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3887 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3888 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3891 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3892 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3894 | return status; |
| 3895 | } |
| 3896 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3897 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3899 | struct nfs4_exception exception = { |
| 3900 | .interruptible = true, |
| 3901 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | int err; |
| 3903 | do { |
| 3904 | err = nfs4_handle_exception(server, |
| 3905 | _nfs4_server_capabilities(server, fhandle), |
| 3906 | &exception); |
| 3907 | } while (exception.retry); |
| 3908 | return err; |
| 3909 | } |
| 3910 | |
| 3911 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3912 | struct nfs_fsinfo *info) |
| 3913 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3914 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3916 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | }; |
| 3918 | struct nfs4_lookup_res res = { |
| 3919 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3920 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | .fh = fhandle, |
| 3922 | }; |
| 3923 | struct rpc_message msg = { |
| 3924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3925 | .rpc_argp = &args, |
| 3926 | .rpc_resp = &res, |
| 3927 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3928 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3929 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3930 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3931 | /* |
| 3932 | * Process the label in the upcoming getfattr |
| 3933 | */ |
| 3934 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3935 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3936 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3937 | 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] | 3938 | } |
| 3939 | |
| 3940 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3941 | struct nfs_fsinfo *info) |
| 3942 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3943 | struct nfs4_exception exception = { |
| 3944 | .interruptible = true, |
| 3945 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3946 | int err; |
| 3947 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3948 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3949 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3950 | switch (err) { |
| 3951 | case 0: |
| 3952 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3953 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3954 | default: |
| 3955 | err = nfs4_handle_exception(server, err, &exception); |
| 3956 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3958 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | return err; |
| 3960 | } |
| 3961 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3962 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3963 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3964 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3965 | struct rpc_auth_create_args auth_args = { |
| 3966 | .pseudoflavor = flavor, |
| 3967 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3968 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3969 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3970 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3971 | if (IS_ERR(auth)) |
| 3972 | return -EACCES; |
| 3973 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3974 | } |
| 3975 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3976 | /* |
| 3977 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3978 | * |
| 3979 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3980 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3981 | * |
| 3982 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3983 | * negative errno value. |
| 3984 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3985 | 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] | 3986 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3988 | /* Per 3530bis 15.33.5 */ |
| 3989 | static const rpc_authflavor_t flav_array[] = { |
| 3990 | RPC_AUTH_GSS_KRB5P, |
| 3991 | RPC_AUTH_GSS_KRB5I, |
| 3992 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3993 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3994 | RPC_AUTH_NULL, |
| 3995 | }; |
| 3996 | int status = -EPERM; |
| 3997 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3999 | if (server->auth_info.flavor_len > 0) { |
| 4000 | /* try each flavor specified by user */ |
| 4001 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 4002 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4003 | server->auth_info.flavors[i]); |
| 4004 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4005 | continue; |
| 4006 | break; |
| 4007 | } |
| 4008 | } else { |
| 4009 | /* no flavors specified by user, try default list */ |
| 4010 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 4011 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 4012 | flav_array[i]); |
| 4013 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 4014 | continue; |
| 4015 | break; |
| 4016 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 4017 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 4018 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4019 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 4020 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 4021 | * to access the mount. It could also mean that we tried to mount |
| 4022 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 4023 | * existing mount programs don't handle -EACCES very well so it should |
| 4024 | * be mapped to -EPERM instead. |
| 4025 | */ |
| 4026 | if (status == -EACCES) |
| 4027 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4028 | return status; |
| 4029 | } |
| 4030 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4031 | /** |
| 4032 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 4033 | * @server: initialized nfs_server handle |
| 4034 | * @fhandle: we fill in the pseudo-fs root file handle |
| 4035 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4036 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4037 | * |
| 4038 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4039 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 4040 | 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] | 4041 | struct nfs_fsinfo *info, |
| 4042 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 4043 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4044 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4045 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4046 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 4047 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 4048 | |
| 4049 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 4050 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 4051 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | if (status == 0) |
| 4054 | status = nfs4_server_capabilities(server, fhandle); |
| 4055 | if (status == 0) |
| 4056 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 4057 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 4058 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4061 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 4062 | struct nfs_fsinfo *info) |
| 4063 | { |
| 4064 | int error; |
| 4065 | struct nfs_fattr *fattr = info->fattr; |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4066 | struct nfs4_label *label = fattr->label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4067 | |
| 4068 | error = nfs4_server_capabilities(server, mntfh); |
| 4069 | if (error < 0) { |
| 4070 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 4071 | return error; |
| 4072 | } |
| 4073 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4074 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4075 | if (error < 0) { |
| 4076 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4077 | goto out; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 4081 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 4082 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 4083 | |
Scott Mayhew | 779df6a | 2020-03-03 17:58:37 -0500 | [diff] [blame] | 4084 | out: |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 4085 | return error; |
| 4086 | } |
| 4087 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4088 | /* |
| 4089 | * Get locations and (maybe) other attributes of a referral. |
| 4090 | * Note that we'll actually follow the referral later when |
| 4091 | * we detect fsid mismatch in inode revalidation |
| 4092 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4093 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4094 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4095 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4096 | { |
| 4097 | int status = -ENOMEM; |
| 4098 | struct page *page = NULL; |
| 4099 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4100 | |
| 4101 | page = alloc_page(GFP_KERNEL); |
| 4102 | if (page == NULL) |
| 4103 | goto out; |
| 4104 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4105 | if (locations == NULL) |
| 4106 | goto out; |
| 4107 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4108 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4109 | if (status != 0) |
| 4110 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4111 | |
| 4112 | /* |
| 4113 | * If the fsid didn't change, this is a migration event, not a |
| 4114 | * referral. Cause us to drop into the exception handler, which |
| 4115 | * will kick off migration recovery. |
| 4116 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4117 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4118 | dprintk("%s: server did not return a different fsid for" |
| 4119 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4120 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4121 | goto out; |
| 4122 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4123 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4124 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4125 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4126 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4127 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4128 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4129 | out: |
| 4130 | if (page) |
| 4131 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4132 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4133 | return status; |
| 4134 | } |
| 4135 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4136 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4137 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4138 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4140 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | struct nfs4_getattr_arg args = { |
| 4142 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4143 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | }; |
| 4145 | struct nfs4_getattr_res res = { |
| 4146 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4147 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | .server = server, |
| 4149 | }; |
| 4150 | struct rpc_message msg = { |
| 4151 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4152 | .rpc_argp = &args, |
| 4153 | .rpc_resp = &res, |
| 4154 | }; |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4155 | unsigned short task_flags = 0; |
| 4156 | |
| 4157 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4158 | if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
| 4159 | task_flags |= RPC_TASK_TIMEOUT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4160 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4161 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4162 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4163 | nfs_fattr_init(fattr); |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame] | 4164 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4165 | return nfs4_do_call_sync(server->client, server, &msg, |
| 4166 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | } |
| 4168 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4169 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4170 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4171 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4173 | struct nfs4_exception exception = { |
| 4174 | .interruptible = true, |
| 4175 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | int err; |
| 4177 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4178 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4179 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4180 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | &exception); |
| 4182 | } while (exception.retry); |
| 4183 | return err; |
| 4184 | } |
| 4185 | |
| 4186 | /* |
| 4187 | * The file is not closed if it is opened due to the a request to change |
| 4188 | * the size of the file. The open call will not be needed once the |
| 4189 | * VFS layer lookup-intents are implemented. |
| 4190 | * |
| 4191 | * Close is called when the inode is destroyed. |
| 4192 | * If we haven't opened the file for O_WRONLY, we |
| 4193 | * need to in the size_change case to obtain a stateid. |
| 4194 | * |
| 4195 | * Got race? |
| 4196 | * Because OPEN is always done by name in nfsv4, it is |
| 4197 | * possible that we opened a different file by the same |
| 4198 | * name. We can recognize this race condition, but we |
| 4199 | * can't do anything about it besides returning an error. |
| 4200 | * |
| 4201 | * This will be fixed with VFS changes (lookup-intent). |
| 4202 | */ |
| 4203 | static int |
| 4204 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4205 | struct iattr *sattr) |
| 4206 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4207 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4208 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4209 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4210 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | int status; |
| 4212 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4213 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4214 | sattr->ia_valid & ATTR_SIZE && |
| 4215 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4216 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4217 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4218 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4220 | /* Deal with open(O_TRUNC) */ |
| 4221 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4222 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4223 | |
| 4224 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4225 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4226 | return 0; |
| 4227 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4228 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4229 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4230 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4231 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4232 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4233 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4234 | } |
| 4235 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4236 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4237 | if (IS_ERR(label)) |
| 4238 | return PTR_ERR(label); |
| 4239 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4240 | /* Return any delegations if we're going to change ACLs */ |
| 4241 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4242 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4243 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4244 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4245 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4246 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4247 | nfs_setsecurity(inode, fattr, label); |
| 4248 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4249 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | return status; |
| 4251 | } |
| 4252 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4253 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4254 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4255 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4256 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4257 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4258 | int status; |
| 4259 | struct nfs4_lookup_arg args = { |
| 4260 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4261 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4262 | .name = &dentry->d_name, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4263 | }; |
| 4264 | struct nfs4_lookup_res res = { |
| 4265 | .server = server, |
| 4266 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4267 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4268 | .fh = fhandle, |
| 4269 | }; |
| 4270 | struct rpc_message msg = { |
| 4271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4272 | .rpc_argp = &args, |
| 4273 | .rpc_resp = &res, |
| 4274 | }; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4275 | unsigned short task_flags = 0; |
| 4276 | |
| 4277 | /* Is this is an attribute revalidation, subject to softreval? */ |
| 4278 | if (nfs_lookup_is_soft_revalidate(dentry)) |
| 4279 | task_flags |= RPC_TASK_TIMEOUT; |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4280 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4281 | args.bitmask = nfs4_bitmask(server, label); |
| 4282 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4283 | nfs_fattr_init(fattr); |
| 4284 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4285 | dprintk("NFS call lookup %pd2\n", dentry); |
| 4286 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 4287 | status = nfs4_do_call_sync(clnt, server, &msg, |
| 4288 | &args.seq_args, &res.seq_res, task_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | dprintk("NFS reply lookup: %d\n", status); |
| 4290 | return status; |
| 4291 | } |
| 4292 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4293 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4294 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4295 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4296 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4297 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4298 | fattr->nlink = 2; |
| 4299 | } |
| 4300 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4301 | 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] | 4302 | struct dentry *dentry, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4303 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4304 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4305 | struct nfs4_exception exception = { |
| 4306 | .interruptible = true, |
| 4307 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4308 | struct rpc_clnt *client = *clnt; |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4309 | const struct qstr *name = &dentry->d_name; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4310 | int err; |
| 4311 | do { |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4312 | err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4313 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4314 | switch (err) { |
| 4315 | case -NFS4ERR_BADNAME: |
| 4316 | err = -ENOENT; |
| 4317 | goto out; |
| 4318 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4319 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4320 | if (err == -NFS4ERR_MOVED) |
| 4321 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4322 | goto out; |
| 4323 | case -NFS4ERR_WRONGSEC: |
| 4324 | err = -EPERM; |
| 4325 | if (client != *clnt) |
| 4326 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4327 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4328 | if (IS_ERR(client)) |
| 4329 | return PTR_ERR(client); |
| 4330 | |
| 4331 | exception.retry = 1; |
| 4332 | break; |
| 4333 | default: |
| 4334 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4335 | } |
| 4336 | } while (exception.retry); |
| 4337 | |
| 4338 | out: |
| 4339 | if (err == 0) |
| 4340 | *clnt = client; |
| 4341 | else if (client != *clnt) |
| 4342 | rpc_shutdown_client(client); |
| 4343 | |
| 4344 | return err; |
| 4345 | } |
| 4346 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4347 | static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4348 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4349 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4351 | int status; |
| 4352 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4353 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4354 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4355 | if (client != NFS_CLIENT(dir)) { |
| 4356 | rpc_shutdown_client(client); |
| 4357 | nfs_fixup_secinfo_attributes(fattr); |
| 4358 | } |
| 4359 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | } |
| 4361 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4362 | struct rpc_clnt * |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4363 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4364 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4365 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4366 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4367 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4368 | |
Trond Myklebust | f7b37b8 | 2020-01-14 12:06:34 -0500 | [diff] [blame] | 4369 | status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4370 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4371 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4372 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4373 | } |
| 4374 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4375 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4376 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4377 | struct nfs4_label *label) |
| 4378 | { |
| 4379 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4380 | struct nfs_server *server = NFS_SERVER(inode); |
| 4381 | int status; |
| 4382 | struct nfs4_lookupp_arg args = { |
| 4383 | .bitmask = server->attr_bitmask, |
| 4384 | .fh = NFS_FH(inode), |
| 4385 | }; |
| 4386 | struct nfs4_lookupp_res res = { |
| 4387 | .server = server, |
| 4388 | .fattr = fattr, |
| 4389 | .label = label, |
| 4390 | .fh = fhandle, |
| 4391 | }; |
| 4392 | struct rpc_message msg = { |
| 4393 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4394 | .rpc_argp = &args, |
| 4395 | .rpc_resp = &res, |
| 4396 | }; |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4397 | unsigned short task_flags = 0; |
| 4398 | |
| 4399 | if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL) |
| 4400 | task_flags |= RPC_TASK_TIMEOUT; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4401 | |
| 4402 | args.bitmask = nfs4_bitmask(server, label); |
| 4403 | |
| 4404 | nfs_fattr_init(fattr); |
| 4405 | |
| 4406 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4407 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
Trond Myklebust | 76998eb | 2020-10-20 14:30:35 -0400 | [diff] [blame] | 4408 | &res.seq_res, task_flags); |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4409 | dprintk("NFS reply lookupp: %d\n", status); |
| 4410 | return status; |
| 4411 | } |
| 4412 | |
| 4413 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4414 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4415 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4416 | struct nfs4_exception exception = { |
| 4417 | .interruptible = true, |
| 4418 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4419 | int err; |
| 4420 | do { |
| 4421 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4422 | trace_nfs4_lookupp(inode, err); |
| 4423 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4424 | &exception); |
| 4425 | } while (exception.retry); |
| 4426 | return err; |
| 4427 | } |
| 4428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4430 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4431 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | struct nfs4_accessargs args = { |
| 4433 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4434 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4436 | struct nfs4_accessres res = { |
| 4437 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4438 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | struct rpc_message msg = { |
| 4440 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4441 | .rpc_argp = &args, |
| 4442 | .rpc_resp = &res, |
| 4443 | .rpc_cred = entry->cred, |
| 4444 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4445 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4447 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4448 | res.fattr = nfs_alloc_fattr(); |
| 4449 | if (res.fattr == NULL) |
| 4450 | return -ENOMEM; |
| 4451 | args.bitmask = server->cache_consistency_bitmask; |
| 4452 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4453 | 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] | 4454 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4455 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4456 | if (res.fattr) |
| 4457 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4459 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | return status; |
| 4461 | } |
| 4462 | |
| 4463 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4464 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4465 | struct nfs4_exception exception = { |
| 4466 | .interruptible = true, |
| 4467 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | int err; |
| 4469 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4470 | err = _nfs4_proc_access(inode, entry); |
| 4471 | trace_nfs4_access(inode, err); |
| 4472 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | &exception); |
| 4474 | } while (exception.retry); |
| 4475 | return err; |
| 4476 | } |
| 4477 | |
| 4478 | /* |
| 4479 | * TODO: For the time being, we don't try to get any attributes |
| 4480 | * along with any of the zero-copy operations READ, READDIR, |
| 4481 | * READLINK, WRITE. |
| 4482 | * |
| 4483 | * In the case of the first three, we want to put the GETATTR |
| 4484 | * after the read-type operation -- this is because it is hard |
| 4485 | * to predict the length of a GETATTR response in v4, and thus |
| 4486 | * align the READ data correctly. This means that the GETATTR |
| 4487 | * may end up partially falling into the page cache, and we should |
| 4488 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4489 | * To do this efficiently, we need to know the total length |
| 4490 | * of data received, which doesn't seem to be available outside |
| 4491 | * of the RPC layer. |
| 4492 | * |
| 4493 | * In the case of WRITE, we also want to put the GETATTR after |
| 4494 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4495 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | * |
| 4497 | * Both of these changes to the XDR layer would in fact be quite |
| 4498 | * minor, but I decided to leave them for a subsequent patch. |
| 4499 | */ |
| 4500 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4501 | unsigned int pgbase, unsigned int pglen) |
| 4502 | { |
| 4503 | struct nfs4_readlink args = { |
| 4504 | .fh = NFS_FH(inode), |
| 4505 | .pgbase = pgbase, |
| 4506 | .pglen = pglen, |
| 4507 | .pages = &page, |
| 4508 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4509 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | struct rpc_message msg = { |
| 4511 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4512 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4513 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | }; |
| 4515 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4516 | 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] | 4517 | } |
| 4518 | |
| 4519 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4520 | unsigned int pgbase, unsigned int pglen) |
| 4521 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4522 | struct nfs4_exception exception = { |
| 4523 | .interruptible = true, |
| 4524 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | int err; |
| 4526 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4527 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4528 | trace_nfs4_readlink(inode, err); |
| 4529 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | &exception); |
| 4531 | } while (exception.retry); |
| 4532 | return err; |
| 4533 | } |
| 4534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4536 | * 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] | 4537 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | static int |
| 4539 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4540 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4542 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4543 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4544 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | int status = 0; |
| 4547 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4548 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4549 | if (IS_ERR(ctx)) |
| 4550 | return PTR_ERR(ctx); |
| 4551 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4552 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4553 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4554 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4555 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4556 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | if (IS_ERR(state)) { |
| 4558 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4559 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4562 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4563 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | return status; |
| 4565 | } |
| 4566 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4567 | static int |
| 4568 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4570 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4571 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4573 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4575 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4576 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4577 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4579 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4580 | .rpc_argp = &args, |
| 4581 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4583 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4584 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4585 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4586 | 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] | 4587 | if (status == 0) { |
| 4588 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4589 | nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, |
| 4590 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4591 | /* Removing a directory decrements nlink in the parent */ |
| 4592 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4593 | nfs4_dec_nlink_locked(dir); |
| 4594 | spin_unlock(&dir->i_lock); |
| 4595 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | return status; |
| 4597 | } |
| 4598 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4599 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4600 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4601 | struct nfs4_exception exception = { |
| 4602 | .interruptible = true, |
| 4603 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4604 | struct inode *inode = d_inode(dentry); |
| 4605 | int err; |
| 4606 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4607 | if (inode) { |
| 4608 | if (inode->i_nlink == 1) |
| 4609 | nfs4_inode_return_delegation(inode); |
| 4610 | else |
| 4611 | nfs4_inode_make_writeable(inode); |
| 4612 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4613 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4614 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4615 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4616 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4617 | &exception); |
| 4618 | } while (exception.retry); |
| 4619 | return err; |
| 4620 | } |
| 4621 | |
| 4622 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4624 | struct nfs4_exception exception = { |
| 4625 | .interruptible = true, |
| 4626 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4630 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4631 | trace_nfs4_remove(dir, name, err); |
| 4632 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | &exception); |
| 4634 | } while (exception.retry); |
| 4635 | return err; |
| 4636 | } |
| 4637 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4638 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4639 | struct dentry *dentry, |
| 4640 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4642 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4643 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4645 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4647 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4648 | |
| 4649 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4650 | |
| 4651 | if (inode) |
| 4652 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4655 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4656 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4657 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4658 | &data->args.seq_args, |
| 4659 | &data->res.seq_res, |
| 4660 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | } |
| 4662 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4663 | 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] | 4664 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4665 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4666 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4667 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4668 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4669 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4670 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4671 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4672 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4673 | if (task->tk_status == 0) |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4674 | nfs4_update_changeattr(dir, &res->cinfo, |
| 4675 | res->dir_attr->time_start, |
| 4676 | NFS_INO_INVALID_DATA); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4677 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4680 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4681 | struct dentry *old_dentry, |
| 4682 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4683 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4684 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4685 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4686 | struct inode *old_inode = d_inode(old_dentry); |
| 4687 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4688 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4689 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4690 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4691 | if (new_inode) |
| 4692 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4693 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4694 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4695 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4696 | } |
| 4697 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4698 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4699 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4700 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4701 | &data->args.seq_args, |
| 4702 | &data->res.seq_res, |
| 4703 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4704 | } |
| 4705 | |
| 4706 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4707 | struct inode *new_dir) |
| 4708 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4709 | struct nfs_renamedata *data = task->tk_calldata; |
| 4710 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4711 | |
| 4712 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4713 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4714 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4715 | return 0; |
| 4716 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4717 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4718 | if (new_dir != old_dir) { |
| 4719 | /* Note: If we moved a directory, nlink will change */ |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4720 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4721 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4722 | NFS_INO_INVALID_OTHER | |
| 4723 | NFS_INO_INVALID_DATA); |
| 4724 | nfs4_update_changeattr(new_dir, &res->new_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4725 | res->new_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4726 | NFS_INO_INVALID_OTHER | |
| 4727 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4728 | } else |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4729 | nfs4_update_changeattr(old_dir, &res->old_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4730 | res->old_fattr->time_start, |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4731 | NFS_INO_INVALID_DATA); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4732 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4733 | return 1; |
| 4734 | } |
| 4735 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4736 | 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] | 4737 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4738 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4739 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | struct nfs4_link_arg arg = { |
| 4741 | .fh = NFS_FH(inode), |
| 4742 | .dir_fh = NFS_FH(dir), |
| 4743 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4744 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4746 | struct nfs4_link_res res = { |
| 4747 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4748 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4749 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | struct rpc_message msg = { |
| 4751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4752 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4753 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4755 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4757 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4758 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4759 | goto out; |
| 4760 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4761 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4762 | if (IS_ERR(res.label)) { |
| 4763 | status = PTR_ERR(res.label); |
| 4764 | goto out; |
| 4765 | } |
| 4766 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4767 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4768 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4769 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4770 | 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] | 4771 | if (!status) { |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4772 | nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, |
| 4773 | NFS_INO_INVALID_DATA); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4774 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4775 | if (!status) |
| 4776 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4777 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4778 | |
| 4779 | |
| 4780 | nfs4_label_free(res.label); |
| 4781 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4782 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4783 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | return status; |
| 4785 | } |
| 4786 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4787 | 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] | 4788 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4789 | struct nfs4_exception exception = { |
| 4790 | .interruptible = true, |
| 4791 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | int err; |
| 4793 | do { |
| 4794 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4795 | _nfs4_proc_link(inode, dir, name), |
| 4796 | &exception); |
| 4797 | } while (exception.retry); |
| 4798 | return err; |
| 4799 | } |
| 4800 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4801 | struct nfs4_createdata { |
| 4802 | struct rpc_message msg; |
| 4803 | struct nfs4_create_arg arg; |
| 4804 | struct nfs4_create_res res; |
| 4805 | struct nfs_fh fh; |
| 4806 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4807 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4808 | }; |
| 4809 | |
| 4810 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4811 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4812 | { |
| 4813 | struct nfs4_createdata *data; |
| 4814 | |
| 4815 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4816 | if (data != NULL) { |
| 4817 | struct nfs_server *server = NFS_SERVER(dir); |
| 4818 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4819 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4820 | if (IS_ERR(data->label)) |
| 4821 | goto out_free; |
| 4822 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4823 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4824 | data->msg.rpc_argp = &data->arg; |
| 4825 | data->msg.rpc_resp = &data->res; |
| 4826 | data->arg.dir_fh = NFS_FH(dir); |
| 4827 | data->arg.server = server; |
| 4828 | data->arg.name = name; |
| 4829 | data->arg.attrs = sattr; |
| 4830 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4831 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4832 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4833 | data->res.server = server; |
| 4834 | data->res.fh = &data->fh; |
| 4835 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4836 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4837 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4838 | } |
| 4839 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4840 | out_free: |
| 4841 | kfree(data); |
| 4842 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4846 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4847 | 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] | 4848 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4849 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4850 | spin_lock(&dir->i_lock); |
Frank van der Linden | 1b523ca | 2020-06-23 22:38:59 +0000 | [diff] [blame] | 4851 | nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, |
| 4852 | data->res.fattr->time_start, |
| 4853 | NFS_INO_INVALID_DATA); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4854 | /* Creating a directory bumps nlink in the parent */ |
| 4855 | if (data->arg.ftype == NF4DIR) |
| 4856 | nfs4_inc_nlink_locked(dir); |
| 4857 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4858 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4859 | } |
| 4860 | return status; |
| 4861 | } |
| 4862 | |
| 4863 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4864 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4865 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4866 | kfree(data); |
| 4867 | } |
| 4868 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4869 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4870 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4871 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4873 | struct nfs4_createdata *data; |
| 4874 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4876 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4877 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4878 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4879 | status = -ENOMEM; |
| 4880 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4881 | if (data == NULL) |
| 4882 | goto out; |
| 4883 | |
| 4884 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4885 | data->arg.u.symlink.pages = &page; |
| 4886 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4887 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4889 | status = nfs4_do_create(dir, dentry, data); |
| 4890 | |
| 4891 | nfs4_free_createdata(data); |
| 4892 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | return status; |
| 4894 | } |
| 4895 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4896 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4897 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4899 | struct nfs4_exception exception = { |
| 4900 | .interruptible = true, |
| 4901 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4902 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4904 | |
| 4905 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4908 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4909 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4910 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | &exception); |
| 4912 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4913 | |
| 4914 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | return err; |
| 4916 | } |
| 4917 | |
| 4918 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4919 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4921 | struct nfs4_createdata *data; |
| 4922 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4924 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4925 | if (data == NULL) |
| 4926 | goto out; |
| 4927 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4928 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4929 | status = nfs4_do_create(dir, dentry, data); |
| 4930 | |
| 4931 | nfs4_free_createdata(data); |
| 4932 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | return status; |
| 4934 | } |
| 4935 | |
| 4936 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4937 | struct iattr *sattr) |
| 4938 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4939 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4940 | struct nfs4_exception exception = { |
| 4941 | .interruptible = true, |
| 4942 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4943 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4945 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4946 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4947 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4948 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4949 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4951 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4952 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4953 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | &exception); |
| 4955 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4956 | nfs4_label_release_security(label); |
| 4957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | return err; |
| 4959 | } |
| 4960 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4961 | static int _nfs4_proc_readdir(struct nfs_readdir_arg *nr_arg, |
| 4962 | struct nfs_readdir_res *nr_res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4964 | struct inode *dir = d_inode(nr_arg->dentry); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4965 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4966 | struct nfs4_readdir_arg args = { |
| 4967 | .fh = NFS_FH(dir), |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4968 | .pages = nr_arg->pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | .pgbase = 0, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4970 | .count = nr_arg->page_len, |
| 4971 | .plus = nr_arg->plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | }; |
| 4973 | struct nfs4_readdir_res res; |
| 4974 | struct rpc_message msg = { |
| 4975 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4976 | .rpc_argp = &args, |
| 4977 | .rpc_resp = &res, |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4978 | .rpc_cred = nr_arg->cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | }; |
| 4980 | int status; |
| 4981 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4982 | dprintk("%s: dentry = %pd2, cookie = %llu\n", __func__, |
| 4983 | nr_arg->dentry, (unsigned long long)nr_arg->cookie); |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4984 | if (!(server->caps & NFS_CAP_SECURITY_LABEL)) |
| 4985 | args.bitmask = server->attr_bitmask_nl; |
| 4986 | else |
| 4987 | args.bitmask = server->attr_bitmask; |
| 4988 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4989 | 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] | 4990 | res.pgbase = args.pgbase; |
Olga Kornievskaia | 05ad917 | 2020-11-06 16:03:38 -0500 | [diff] [blame] | 4991 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 4992 | &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4993 | if (status >= 0) { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 4994 | memcpy(nr_res->verf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4995 | status += args.pgbase; |
| 4996 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4997 | |
| 4998 | nfs_invalidate_atime(dir); |
| 4999 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5000 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 | return status; |
| 5002 | } |
| 5003 | |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5004 | static int nfs4_proc_readdir(struct nfs_readdir_arg *arg, |
| 5005 | struct nfs_readdir_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5007 | struct nfs4_exception exception = { |
| 5008 | .interruptible = true, |
| 5009 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | int err; |
| 5011 | do { |
Trond Myklebust | 82e22a5 | 2020-11-02 17:34:23 -0500 | [diff] [blame] | 5012 | err = _nfs4_proc_readdir(arg, res); |
| 5013 | trace_nfs4_readdir(d_inode(arg->dentry), err); |
| 5014 | err = nfs4_handle_exception(NFS_SERVER(d_inode(arg->dentry)), |
| 5015 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | } while (exception.retry); |
| 5017 | return err; |
| 5018 | } |
| 5019 | |
| 5020 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5021 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5023 | struct nfs4_createdata *data; |
| 5024 | int mode = sattr->ia_mode; |
| 5025 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5027 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 5028 | if (data == NULL) |
| 5029 | goto out; |
| 5030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5032 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5034 | data->arg.ftype = NF4BLK; |
| 5035 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5036 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | } |
| 5038 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5039 | data->arg.ftype = NF4CHR; |
| 5040 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 5041 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5042 | } else if (!S_ISSOCK(mode)) { |
| 5043 | status = -EINVAL; |
| 5044 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 5046 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5047 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5048 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 5049 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 5050 | nfs4_free_createdata(data); |
| 5051 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | return status; |
| 5053 | } |
| 5054 | |
| 5055 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 5056 | struct iattr *sattr, dev_t rdev) |
| 5057 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5058 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5059 | struct nfs4_exception exception = { |
| 5060 | .interruptible = true, |
| 5061 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5062 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5063 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 5064 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5065 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 5066 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 5067 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 5068 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5070 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 5071 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 5072 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | &exception); |
| 5074 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5075 | |
| 5076 | nfs4_label_release_security(label); |
| 5077 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5078 | return err; |
| 5079 | } |
| 5080 | |
| 5081 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5082 | struct nfs_fsstat *fsstat) |
| 5083 | { |
| 5084 | struct nfs4_statfs_arg args = { |
| 5085 | .fh = fhandle, |
| 5086 | .bitmask = server->attr_bitmask, |
| 5087 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5088 | struct nfs4_statfs_res res = { |
| 5089 | .fsstat = fsstat, |
| 5090 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5091 | struct rpc_message msg = { |
| 5092 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 5093 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 5094 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | }; |
| 5096 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5097 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5098 | 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] | 5099 | } |
| 5100 | |
| 5101 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 5102 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5103 | struct nfs4_exception exception = { |
| 5104 | .interruptible = true, |
| 5105 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | int err; |
| 5107 | do { |
| 5108 | err = nfs4_handle_exception(server, |
| 5109 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 5110 | &exception); |
| 5111 | } while (exception.retry); |
| 5112 | return err; |
| 5113 | } |
| 5114 | |
| 5115 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5116 | struct nfs_fsinfo *fsinfo) |
| 5117 | { |
| 5118 | struct nfs4_fsinfo_arg args = { |
| 5119 | .fh = fhandle, |
| 5120 | .bitmask = server->attr_bitmask, |
| 5121 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5122 | struct nfs4_fsinfo_res res = { |
| 5123 | .fsinfo = fsinfo, |
| 5124 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | struct rpc_message msg = { |
| 5126 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5127 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5128 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | }; |
| 5130 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5131 | 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] | 5132 | } |
| 5133 | |
| 5134 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5135 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5136 | struct nfs4_exception exception = { |
| 5137 | .interruptible = true, |
| 5138 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | int err; |
| 5140 | |
| 5141 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5142 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5143 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5144 | if (err == 0) { |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 5145 | nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5146 | break; |
| 5147 | } |
| 5148 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | } while (exception.retry); |
| 5150 | return err; |
| 5151 | } |
| 5152 | |
| 5153 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5154 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5155 | int error; |
| 5156 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5157 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5158 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5159 | if (error == 0) { |
| 5160 | /* block layout checks this! */ |
| 5161 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5162 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5163 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5164 | |
| 5165 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5169 | struct nfs_pathconf *pathconf) |
| 5170 | { |
| 5171 | struct nfs4_pathconf_arg args = { |
| 5172 | .fh = fhandle, |
| 5173 | .bitmask = server->attr_bitmask, |
| 5174 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5175 | struct nfs4_pathconf_res res = { |
| 5176 | .pathconf = pathconf, |
| 5177 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | struct rpc_message msg = { |
| 5179 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5180 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5181 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | }; |
| 5183 | |
| 5184 | /* None of the pathconf attributes are mandatory to implement */ |
| 5185 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5186 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5187 | return 0; |
| 5188 | } |
| 5189 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5190 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5191 | 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] | 5192 | } |
| 5193 | |
| 5194 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5195 | struct nfs_pathconf *pathconf) |
| 5196 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5197 | struct nfs4_exception exception = { |
| 5198 | .interruptible = true, |
| 5199 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | int err; |
| 5201 | |
| 5202 | do { |
| 5203 | err = nfs4_handle_exception(server, |
| 5204 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5205 | &exception); |
| 5206 | } while (exception.retry); |
| 5207 | return err; |
| 5208 | } |
| 5209 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5210 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5211 | const struct nfs_open_context *ctx, |
| 5212 | const struct nfs_lock_context *l_ctx, |
| 5213 | fmode_t fmode) |
| 5214 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5215 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5216 | } |
| 5217 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5218 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5219 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5220 | const struct nfs_open_context *ctx, |
| 5221 | const struct nfs_lock_context *l_ctx, |
| 5222 | fmode_t fmode) |
| 5223 | { |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5224 | nfs4_stateid _current_stateid; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5225 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5226 | /* If the current stateid represents a lost lock, then exit */ |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5227 | if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5228 | return true; |
Ben Dooks | d49dd11 | 2019-10-16 17:28:21 +0100 | [diff] [blame] | 5229 | return nfs4_stateid_match(stateid, &_current_stateid); |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | static bool nfs4_error_stateid_expired(int err) |
| 5233 | { |
| 5234 | switch (err) { |
| 5235 | case -NFS4ERR_DELEG_REVOKED: |
| 5236 | case -NFS4ERR_ADMIN_REVOKED: |
| 5237 | case -NFS4ERR_BAD_STATEID: |
| 5238 | case -NFS4ERR_STALE_STATEID: |
| 5239 | case -NFS4ERR_OLD_STATEID: |
| 5240 | case -NFS4ERR_OPENMODE: |
| 5241 | case -NFS4ERR_EXPIRED: |
| 5242 | return true; |
| 5243 | } |
| 5244 | return false; |
| 5245 | } |
| 5246 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5247 | 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] | 5248 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5249 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5250 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5251 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5252 | if (task->tk_status < 0) { |
| 5253 | struct nfs4_exception exception = { |
| 5254 | .inode = hdr->inode, |
| 5255 | .state = hdr->args.context->state, |
| 5256 | .stateid = &hdr->args.stateid, |
| 5257 | }; |
| 5258 | task->tk_status = nfs4_async_handle_exception(task, |
| 5259 | server, task->tk_status, &exception); |
| 5260 | if (exception.retry) { |
| 5261 | rpc_restart_call_prepare(task); |
| 5262 | return -EAGAIN; |
| 5263 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5266 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5267 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5268 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5271 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5272 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5273 | { |
| 5274 | |
| 5275 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5276 | nfs4_stateid_is_current(&args->stateid, |
| 5277 | args->context, |
| 5278 | args->lock_context, |
| 5279 | FMODE_READ)) |
| 5280 | return false; |
| 5281 | rpc_restart_call_prepare(task); |
| 5282 | return true; |
| 5283 | } |
| 5284 | |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5285 | static bool nfs4_read_plus_not_supported(struct rpc_task *task, |
| 5286 | struct nfs_pgio_header *hdr) |
| 5287 | { |
| 5288 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
| 5289 | struct rpc_message *msg = &task->tk_msg; |
| 5290 | |
| 5291 | if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS] && |
| 5292 | server->caps & NFS_CAP_READ_PLUS && task->tk_status == -ENOTSUPP) { |
| 5293 | server->caps &= ~NFS_CAP_READ_PLUS; |
| 5294 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5295 | rpc_restart_call_prepare(task); |
| 5296 | return true; |
| 5297 | } |
| 5298 | return false; |
| 5299 | } |
| 5300 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5301 | 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] | 5302 | { |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5303 | dprintk("--> %s\n", __func__); |
| 5304 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5305 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5306 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5307 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5308 | return -EAGAIN; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5309 | if (nfs4_read_plus_not_supported(task, hdr)) |
| 5310 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5311 | if (task->tk_status > 0) |
| 5312 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5313 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5314 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5315 | } |
| 5316 | |
Anna Schumaker | 21e3140 | 2020-12-03 15:18:39 -0500 | [diff] [blame] | 5317 | #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] | 5318 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5319 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5320 | { |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5321 | /* Note: We don't use READ_PLUS with pNFS yet */ |
| 5322 | 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] | 5323 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS]; |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5324 | } |
| 5325 | #else |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5326 | static void nfs42_read_plus_support(struct nfs_pgio_header *hdr, |
| 5327 | struct rpc_message *msg) |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5328 | { |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 5329 | } |
| 5330 | #endif /* CONFIG_NFS_V4_2 */ |
| 5331 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5332 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5333 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5335 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5336 | if (!hdr->pgio_done_cb) |
| 5337 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | 5c3485b | 2020-12-10 09:34:34 -0500 | [diff] [blame] | 5338 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
| 5339 | nfs42_read_plus_support(hdr, msg); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5340 | 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] | 5341 | } |
| 5342 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5343 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5344 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5345 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5346 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5347 | &hdr->args.seq_args, |
| 5348 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5349 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5350 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5351 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5352 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5353 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5354 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5355 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5356 | return -EIO; |
| 5357 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | } |
| 5359 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5360 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5361 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5363 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5364 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5365 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5366 | if (task->tk_status < 0) { |
| 5367 | struct nfs4_exception exception = { |
| 5368 | .inode = hdr->inode, |
| 5369 | .state = hdr->args.context->state, |
| 5370 | .stateid = &hdr->args.stateid, |
| 5371 | }; |
| 5372 | task->tk_status = nfs4_async_handle_exception(task, |
| 5373 | NFS_SERVER(inode), task->tk_status, |
| 5374 | &exception); |
| 5375 | if (exception.retry) { |
| 5376 | rpc_restart_call_prepare(task); |
| 5377 | return -EAGAIN; |
| 5378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5380 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5381 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5382 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5383 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5384 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5387 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5388 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5389 | { |
| 5390 | |
| 5391 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5392 | nfs4_stateid_is_current(&args->stateid, |
| 5393 | args->context, |
| 5394 | args->lock_context, |
| 5395 | FMODE_WRITE)) |
| 5396 | return false; |
| 5397 | rpc_restart_call_prepare(task); |
| 5398 | return true; |
| 5399 | } |
| 5400 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5401 | 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] | 5402 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5403 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5404 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5405 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5406 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5407 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5408 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5409 | } |
| 5410 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5411 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5412 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5413 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5414 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5415 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5416 | return false; |
| 5417 | /* Otherwise, request attributes if and only if we don't hold |
| 5418 | * a delegation |
| 5419 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5420 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5421 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5422 | |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5423 | static void nfs4_bitmask_adjust(__u32 *bitmask, struct inode *inode, |
| 5424 | struct nfs_server *server, |
| 5425 | struct nfs4_label *label) |
| 5426 | { |
| 5427 | |
| 5428 | unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 5429 | |
| 5430 | if ((cache_validity & NFS_INO_INVALID_DATA) || |
| 5431 | (cache_validity & NFS_INO_REVAL_PAGECACHE) || |
| 5432 | (cache_validity & NFS_INO_REVAL_FORCED) || |
| 5433 | (cache_validity & NFS_INO_INVALID_OTHER)) |
| 5434 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
| 5435 | |
| 5436 | if (cache_validity & NFS_INO_INVALID_ATIME) |
| 5437 | bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; |
| 5438 | if (cache_validity & NFS_INO_INVALID_ACCESS) |
| 5439 | bitmask[0] |= FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | |
| 5440 | FATTR4_WORD1_OWNER_GROUP; |
| 5441 | if (cache_validity & NFS_INO_INVALID_ACL) |
| 5442 | bitmask[0] |= FATTR4_WORD0_ACL; |
| 5443 | if (cache_validity & NFS_INO_INVALID_LABEL) |
| 5444 | bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; |
| 5445 | if (cache_validity & NFS_INO_INVALID_CTIME) |
| 5446 | bitmask[0] |= FATTR4_WORD0_CHANGE; |
| 5447 | if (cache_validity & NFS_INO_INVALID_MTIME) |
| 5448 | bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; |
| 5449 | if (cache_validity & NFS_INO_INVALID_SIZE) |
| 5450 | bitmask[0] |= FATTR4_WORD0_SIZE; |
| 5451 | if (cache_validity & NFS_INO_INVALID_BLOCKS) |
| 5452 | bitmask[1] |= FATTR4_WORD1_SPACE_USED; |
| 5453 | } |
| 5454 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5455 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5456 | struct rpc_message *msg, |
| 5457 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5459 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5460 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5461 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5462 | hdr->args.bitmask = NULL; |
| 5463 | hdr->res.fattr = NULL; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5464 | } else { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5465 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 5466 | nfs4_bitmask_adjust(hdr->args.bitmask, hdr->inode, server, NULL); |
| 5467 | } |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5468 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5469 | if (!hdr->pgio_done_cb) |
| 5470 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5471 | hdr->res.server = server; |
| 5472 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5474 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Olga Kornievskaia | cd1b659 | 2020-02-12 17:32:12 -0500 | [diff] [blame] | 5475 | 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] | 5476 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | } |
| 5478 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5479 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5480 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5481 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5482 | &data->args.seq_args, |
| 5483 | &data->res.seq_res, |
| 5484 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5485 | } |
| 5486 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5487 | 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] | 5488 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5490 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5491 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5492 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5493 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5494 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5495 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5497 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | } |
| 5499 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5500 | 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] | 5501 | { |
| 5502 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5503 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5504 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5505 | } |
| 5506 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5507 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5508 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5510 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5511 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5512 | if (data->commit_done_cb == NULL) |
| 5513 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5514 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5515 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5516 | 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] | 5517 | 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] | 5518 | } |
| 5519 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5520 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5521 | struct nfs_commitres *res) |
| 5522 | { |
| 5523 | struct inode *dst_inode = file_inode(dst); |
| 5524 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5525 | struct rpc_message msg = { |
| 5526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5527 | .rpc_argp = args, |
| 5528 | .rpc_resp = res, |
| 5529 | }; |
| 5530 | |
| 5531 | args->fh = NFS_FH(dst_inode); |
| 5532 | return nfs4_call_sync(server->client, server, &msg, |
| 5533 | &args->seq_args, &res->seq_res, 1); |
| 5534 | } |
| 5535 | |
| 5536 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5537 | { |
| 5538 | struct nfs_commitargs args = { |
| 5539 | .offset = offset, |
| 5540 | .count = count, |
| 5541 | }; |
| 5542 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5543 | struct nfs4_exception exception = { }; |
| 5544 | int status; |
| 5545 | |
| 5546 | do { |
| 5547 | status = _nfs4_proc_commit(dst, &args, res); |
| 5548 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5549 | } while (exception.retry); |
| 5550 | |
| 5551 | return status; |
| 5552 | } |
| 5553 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5554 | struct nfs4_renewdata { |
| 5555 | struct nfs_client *client; |
| 5556 | unsigned long timestamp; |
| 5557 | }; |
| 5558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5559 | /* |
| 5560 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5561 | * standalone procedure for queueing an asynchronous RENEW. |
| 5562 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5563 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5564 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5565 | struct nfs4_renewdata *data = calldata; |
| 5566 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5567 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5568 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5569 | nfs4_schedule_state_renewal(clp); |
| 5570 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5571 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5572 | } |
| 5573 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5574 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5576 | struct nfs4_renewdata *data = calldata; |
| 5577 | struct nfs_client *clp = data->client; |
| 5578 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5579 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5580 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5581 | switch (task->tk_status) { |
| 5582 | case 0: |
| 5583 | break; |
| 5584 | case -NFS4ERR_LEASE_MOVED: |
| 5585 | nfs4_schedule_lease_moved_recovery(clp); |
| 5586 | break; |
| 5587 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5588 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5589 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5590 | return; |
| 5591 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5592 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5593 | return; |
| 5594 | } |
| 5595 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5597 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | } |
| 5599 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5600 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5601 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5602 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5603 | }; |
| 5604 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5605 | 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] | 5606 | { |
| 5607 | struct rpc_message msg = { |
| 5608 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5609 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5610 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5612 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5613 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5614 | if (renew_flags == 0) |
| 5615 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5616 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5617 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5618 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5619 | if (data == NULL) { |
| 5620 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5621 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5622 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5623 | data->client = clp; |
| 5624 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5625 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5626 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | } |
| 5628 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5629 | 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] | 5630 | { |
| 5631 | struct rpc_message msg = { |
| 5632 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5633 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5634 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | }; |
| 5636 | unsigned long now = jiffies; |
| 5637 | int status; |
| 5638 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5639 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5640 | if (status < 0) |
| 5641 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5642 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | return 0; |
| 5644 | } |
| 5645 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5646 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5647 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5648 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5649 | } |
| 5650 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5651 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5652 | * 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] | 5653 | * the stack. |
| 5654 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5655 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5656 | |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5657 | int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5658 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5659 | { |
| 5660 | struct page *newpage, **spages; |
| 5661 | int rc = 0; |
| 5662 | size_t len; |
| 5663 | spages = pages; |
| 5664 | |
| 5665 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5666 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5667 | newpage = alloc_page(GFP_KERNEL); |
| 5668 | |
| 5669 | if (newpage == NULL) |
| 5670 | goto unwind; |
| 5671 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5672 | buf += len; |
| 5673 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5674 | *pages++ = newpage; |
| 5675 | rc++; |
| 5676 | } while (buflen != 0); |
| 5677 | |
| 5678 | return rc; |
| 5679 | |
| 5680 | unwind: |
| 5681 | for(; rc > 0; rc--) |
| 5682 | __free_page(spages[rc-1]); |
| 5683 | return -ENOMEM; |
| 5684 | } |
| 5685 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5686 | struct nfs4_cached_acl { |
| 5687 | int cached; |
| 5688 | size_t len; |
Gustavo A. R. Silva | 5601cda | 2020-03-09 13:24:42 -0500 | [diff] [blame] | 5689 | char data[]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5690 | }; |
| 5691 | |
| 5692 | 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] | 5693 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5694 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5695 | |
| 5696 | spin_lock(&inode->i_lock); |
| 5697 | kfree(nfsi->nfs4_acl); |
| 5698 | nfsi->nfs4_acl = acl; |
| 5699 | spin_unlock(&inode->i_lock); |
| 5700 | } |
| 5701 | |
| 5702 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5703 | { |
| 5704 | nfs4_set_cached_acl(inode, NULL); |
| 5705 | } |
| 5706 | |
| 5707 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5708 | { |
| 5709 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5710 | struct nfs4_cached_acl *acl; |
| 5711 | int ret = -ENOENT; |
| 5712 | |
| 5713 | spin_lock(&inode->i_lock); |
| 5714 | acl = nfsi->nfs4_acl; |
| 5715 | if (acl == NULL) |
| 5716 | goto out; |
| 5717 | if (buf == NULL) /* user is just asking for length */ |
| 5718 | goto out_len; |
| 5719 | if (acl->cached == 0) |
| 5720 | goto out; |
| 5721 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5722 | if (acl->len > buflen) |
| 5723 | goto out; |
| 5724 | memcpy(buf, acl->data, acl->len); |
| 5725 | out_len: |
| 5726 | ret = acl->len; |
| 5727 | out: |
| 5728 | spin_unlock(&inode->i_lock); |
| 5729 | return ret; |
| 5730 | } |
| 5731 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5732 | 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] | 5733 | { |
| 5734 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5735 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5736 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5737 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5738 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5739 | if (acl == NULL) |
| 5740 | goto out; |
| 5741 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5742 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5743 | } else { |
| 5744 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5745 | if (acl == NULL) |
| 5746 | goto out; |
| 5747 | acl->cached = 0; |
| 5748 | } |
| 5749 | acl->len = acl_len; |
| 5750 | out: |
| 5751 | nfs4_set_cached_acl(inode, acl); |
| 5752 | } |
| 5753 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5754 | /* |
| 5755 | * The getxattr API returns the required buffer length when called with a |
| 5756 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5757 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5758 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5759 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5760 | * the cache. If not so, we throw away the page, and cache the required |
| 5761 | * length. The next getxattr call will then produce another round trip to |
| 5762 | * the server, this time with the input buf of the required size. |
| 5763 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5764 | 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] | 5765 | { |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5766 | struct page **pages; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5767 | struct nfs_getaclargs args = { |
| 5768 | .fh = NFS_FH(inode), |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5769 | .acl_len = buflen, |
| 5770 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5771 | struct nfs_getaclres res = { |
| 5772 | .acl_len = buflen, |
| 5773 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5774 | struct rpc_message msg = { |
| 5775 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5776 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5777 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5778 | }; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5779 | unsigned int npages; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5780 | int ret = -ENOMEM, i; |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5781 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5782 | |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5783 | if (buflen == 0) |
| 5784 | buflen = server->rsize; |
| 5785 | |
| 5786 | npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
| 5787 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
| 5788 | if (!pages) |
| 5789 | return -ENOMEM; |
| 5790 | |
| 5791 | args.acl_pages = pages; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5792 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5793 | for (i = 0; i < npages; i++) { |
| 5794 | pages[i] = alloc_page(GFP_KERNEL); |
| 5795 | if (!pages[i]) |
| 5796 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5797 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5798 | |
| 5799 | /* for decoding across pages */ |
| 5800 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5801 | if (!res.acl_scratch) |
| 5802 | goto out_free; |
| 5803 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5804 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5805 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5806 | 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] | 5807 | __func__, buf, buflen, npages, args.acl_len); |
| 5808 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5809 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5810 | if (ret) |
| 5811 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5812 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5813 | /* Handle the case where the passed-in buffer is too short */ |
| 5814 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5815 | /* Did the user only issue a request for the acl length? */ |
| 5816 | if (buf == NULL) |
| 5817 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5818 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5819 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5820 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5821 | 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] | 5822 | if (buf) { |
| 5823 | if (res.acl_len > buflen) { |
| 5824 | ret = -ERANGE; |
| 5825 | goto out_free; |
| 5826 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5827 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5828 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5829 | out_ok: |
| 5830 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5831 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5832 | for (i = 0; i < npages; i++) |
| 5833 | if (pages[i]) |
| 5834 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5835 | if (res.acl_scratch) |
| 5836 | __free_page(res.acl_scratch); |
Olga Kornievskaia | 62a1573 | 2020-01-02 17:09:54 -0500 | [diff] [blame] | 5837 | kfree(pages); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5838 | return ret; |
| 5839 | } |
| 5840 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5841 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5842 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5843 | struct nfs4_exception exception = { |
| 5844 | .interruptible = true, |
| 5845 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5846 | ssize_t ret; |
| 5847 | do { |
| 5848 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5849 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5850 | if (ret >= 0) |
| 5851 | break; |
| 5852 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5853 | } while (exception.retry); |
| 5854 | return ret; |
| 5855 | } |
| 5856 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5857 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5858 | { |
| 5859 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5860 | int ret; |
| 5861 | |
| 5862 | if (!nfs4_server_supports_acls(server)) |
| 5863 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5864 | ret = nfs_revalidate_inode(server, inode); |
| 5865 | if (ret < 0) |
| 5866 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5867 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5868 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5869 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5870 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5871 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5872 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5873 | return ret; |
| 5874 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5875 | } |
| 5876 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5877 | 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] | 5878 | { |
| 5879 | struct nfs_server *server = NFS_SERVER(inode); |
| 5880 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5881 | struct nfs_setaclargs arg = { |
| 5882 | .fh = NFS_FH(inode), |
| 5883 | .acl_pages = pages, |
| 5884 | .acl_len = buflen, |
| 5885 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5886 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5887 | struct rpc_message msg = { |
| 5888 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5889 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5890 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5891 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5892 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5893 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5894 | |
| 5895 | if (!nfs4_server_supports_acls(server)) |
| 5896 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5897 | if (npages > ARRAY_SIZE(pages)) |
| 5898 | return -ERANGE; |
Frank van der Linden | ccde1e9 | 2020-06-23 22:39:01 +0000 | [diff] [blame] | 5899 | i = nfs4_buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5900 | if (i < 0) |
| 5901 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5902 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5903 | 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] | 5904 | |
| 5905 | /* |
| 5906 | * Free each page after tx, so the only ref left is |
| 5907 | * held by the network stack |
| 5908 | */ |
| 5909 | for (; i > 0; i--) |
| 5910 | put_page(pages[i-1]); |
| 5911 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5912 | /* |
| 5913 | * Acl update can result in inode attribute update. |
| 5914 | * so mark the attribute cache invalid. |
| 5915 | */ |
| 5916 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5917 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5918 | | NFS_INO_INVALID_CTIME |
| 5919 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5920 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5921 | nfs_access_zap_cache(inode); |
| 5922 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5923 | return ret; |
| 5924 | } |
| 5925 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5926 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5927 | { |
| 5928 | struct nfs4_exception exception = { }; |
| 5929 | int err; |
| 5930 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5931 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5932 | trace_nfs4_set_acl(inode, err); |
| 5933 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5934 | &exception); |
| 5935 | } while (exception.retry); |
| 5936 | return err; |
| 5937 | } |
| 5938 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5939 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5940 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5941 | size_t buflen) |
| 5942 | { |
| 5943 | struct nfs_server *server = NFS_SERVER(inode); |
| 5944 | struct nfs_fattr fattr; |
| 5945 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5946 | |
| 5947 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5948 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5949 | .fh = NFS_FH(inode), |
| 5950 | .bitmask = bitmask, |
| 5951 | }; |
| 5952 | struct nfs4_getattr_res res = { |
| 5953 | .fattr = &fattr, |
| 5954 | .label = &label, |
| 5955 | .server = server, |
| 5956 | }; |
| 5957 | struct rpc_message msg = { |
| 5958 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5959 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5960 | .rpc_resp = &res, |
| 5961 | }; |
| 5962 | int ret; |
| 5963 | |
| 5964 | nfs_fattr_init(&fattr); |
| 5965 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5966 | 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] | 5967 | if (ret) |
| 5968 | return ret; |
| 5969 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5970 | return -ENOENT; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5971 | return 0; |
| 5972 | } |
| 5973 | |
| 5974 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5975 | size_t buflen) |
| 5976 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5977 | struct nfs4_exception exception = { |
| 5978 | .interruptible = true, |
| 5979 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5980 | int err; |
| 5981 | |
| 5982 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5983 | return -EOPNOTSUPP; |
| 5984 | |
| 5985 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5986 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5987 | trace_nfs4_get_security_label(inode, err); |
| 5988 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5989 | &exception); |
| 5990 | } while (exception.retry); |
| 5991 | return err; |
| 5992 | } |
| 5993 | |
| 5994 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5995 | struct nfs4_label *ilabel, |
| 5996 | struct nfs_fattr *fattr, |
| 5997 | struct nfs4_label *olabel) |
| 5998 | { |
| 5999 | |
| 6000 | struct iattr sattr = {0}; |
| 6001 | struct nfs_server *server = NFS_SERVER(inode); |
| 6002 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6003 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6004 | .fh = NFS_FH(inode), |
| 6005 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6006 | .server = server, |
| 6007 | .bitmask = bitmask, |
| 6008 | .label = ilabel, |
| 6009 | }; |
| 6010 | struct nfs_setattrres res = { |
| 6011 | .fattr = fattr, |
| 6012 | .label = olabel, |
| 6013 | .server = server, |
| 6014 | }; |
| 6015 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6016 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 6017 | .rpc_argp = &arg, |
| 6018 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6019 | }; |
| 6020 | int status; |
| 6021 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6022 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6023 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 6024 | 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] | 6025 | if (status) |
| 6026 | dprintk("%s failed: %d\n", __func__, status); |
| 6027 | |
| 6028 | return status; |
| 6029 | } |
| 6030 | |
| 6031 | static int nfs4_do_set_security_label(struct inode *inode, |
| 6032 | struct nfs4_label *ilabel, |
| 6033 | struct nfs_fattr *fattr, |
| 6034 | struct nfs4_label *olabel) |
| 6035 | { |
| 6036 | struct nfs4_exception exception = { }; |
| 6037 | int err; |
| 6038 | |
| 6039 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 6040 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 6041 | fattr, olabel); |
| 6042 | trace_nfs4_set_security_label(inode, err); |
| 6043 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6044 | &exception); |
| 6045 | } while (exception.retry); |
| 6046 | return err; |
| 6047 | } |
| 6048 | |
| 6049 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6050 | 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] | 6051 | { |
| 6052 | struct nfs4_label ilabel, *olabel = NULL; |
| 6053 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6054 | int status; |
| 6055 | |
| 6056 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 6057 | return -EOPNOTSUPP; |
| 6058 | |
| 6059 | nfs_fattr_init(&fattr); |
| 6060 | |
| 6061 | ilabel.pi = 0; |
| 6062 | ilabel.lfs = 0; |
| 6063 | ilabel.label = (char *)buf; |
| 6064 | ilabel.len = buflen; |
| 6065 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6066 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 6067 | if (IS_ERR(olabel)) { |
| 6068 | status = -PTR_ERR(olabel); |
| 6069 | goto out; |
| 6070 | } |
| 6071 | |
| 6072 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 6073 | if (status == 0) |
| 6074 | nfs_setsecurity(inode, &fattr, olabel); |
| 6075 | |
| 6076 | nfs4_label_free(olabel); |
| 6077 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 6078 | return status; |
| 6079 | } |
| 6080 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 6081 | |
| 6082 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6083 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 6084 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6085 | { |
| 6086 | __be32 verf[2]; |
| 6087 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6088 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 6089 | /* An impossible timestamp guarantees this value |
| 6090 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6091 | verf[0] = cpu_to_be32(U32_MAX); |
| 6092 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6093 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6094 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 6095 | u64 ns = ktime_to_ns(nn->boot_time); |
| 6096 | |
| 6097 | verf[0] = cpu_to_be32(ns >> 32); |
| 6098 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 6099 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6100 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 6101 | } |
| 6102 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6103 | static size_t |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6104 | nfs4_get_uniquifier(struct nfs_client *clp, char *buf, size_t buflen) |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6105 | { |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6106 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 6107 | struct nfs_netns_client *nn_clp = nn->nfs_client; |
| 6108 | const char *id; |
| 6109 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6110 | buf[0] = '\0'; |
| 6111 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6112 | if (nn_clp) { |
| 6113 | rcu_read_lock(); |
| 6114 | id = rcu_dereference(nn_clp->identifier); |
| 6115 | if (id) |
| 6116 | strscpy(buf, id, buflen); |
| 6117 | rcu_read_unlock(); |
| 6118 | } |
| 6119 | |
| 6120 | if (nfs4_client_id_uniquifier[0] != '\0' && buf[0] == '\0') |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6121 | strscpy(buf, nfs4_client_id_uniquifier, buflen); |
| 6122 | |
| 6123 | return strlen(buf); |
| 6124 | } |
| 6125 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6126 | static int |
| 6127 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6128 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6129 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6130 | size_t buflen; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6131 | size_t len; |
| 6132 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6133 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6134 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6135 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 6136 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6137 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6138 | len = 14 + |
| 6139 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 6140 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6141 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6142 | 1; |
| 6143 | rcu_read_unlock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6144 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6145 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6146 | if (buflen) |
| 6147 | len += buflen + 1; |
| 6148 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6149 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6150 | return -EINVAL; |
| 6151 | |
| 6152 | /* |
| 6153 | * Since this string is allocated at mount time, and held until the |
| 6154 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6155 | * about a memory-reclaim deadlock. |
| 6156 | */ |
| 6157 | str = kmalloc(len, GFP_KERNEL); |
| 6158 | if (!str) |
| 6159 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6160 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6161 | rcu_read_lock(); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6162 | if (buflen) |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6163 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6164 | clp->cl_rpcclient->cl_nodename, buf, |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6165 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6166 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6167 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6168 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 6169 | clp->cl_rpcclient->cl_nodename, |
| 6170 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 6171 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6172 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6173 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6174 | clp->cl_owner_id = str; |
| 6175 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6176 | } |
| 6177 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6178 | static int |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6179 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 6180 | { |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6181 | char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
| 6182 | size_t buflen; |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6183 | size_t len; |
| 6184 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 6185 | |
| 6186 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6187 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 6188 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6189 | len = 10 + 10 + 1 + 10 + 1 + |
| 6190 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6191 | |
Trond Myklebust | 39d43d1 | 2020-10-07 18:24:18 -0400 | [diff] [blame] | 6192 | buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6193 | if (buflen) |
| 6194 | len += buflen + 1; |
| 6195 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6196 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6197 | return -EINVAL; |
| 6198 | |
| 6199 | /* |
| 6200 | * Since this string is allocated at mount time, and held until the |
| 6201 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6202 | * about a memory-reclaim deadlock. |
| 6203 | */ |
| 6204 | str = kmalloc(len, GFP_KERNEL); |
| 6205 | if (!str) |
| 6206 | return -ENOMEM; |
| 6207 | |
Trond Myklebust | 1aee551 | 2020-10-07 18:24:17 -0400 | [diff] [blame] | 6208 | if (buflen) |
| 6209 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
| 6210 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6211 | buf, clp->cl_rpcclient->cl_nodename); |
| 6212 | else |
| 6213 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
| 6214 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6215 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6216 | clp->cl_owner_id = str; |
| 6217 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6218 | } |
| 6219 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6220 | /* |
| 6221 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6222 | * services. Advertise one based on the address family of the |
| 6223 | * clientaddr. |
| 6224 | */ |
| 6225 | static unsigned int |
| 6226 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6227 | { |
| 6228 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6229 | return scnprintf(buf, len, "tcp6"); |
| 6230 | else |
| 6231 | return scnprintf(buf, len, "tcp"); |
| 6232 | } |
| 6233 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6234 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6235 | { |
| 6236 | struct nfs4_setclientid *sc = calldata; |
| 6237 | |
| 6238 | if (task->tk_status == 0) |
| 6239 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6240 | } |
| 6241 | |
| 6242 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6243 | .rpc_call_done = nfs4_setclientid_done, |
| 6244 | }; |
| 6245 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6246 | /** |
| 6247 | * nfs4_proc_setclientid - Negotiate client ID |
| 6248 | * @clp: state data structure |
| 6249 | * @program: RPC program for NFSv4 callback service |
| 6250 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6251 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6252 | * @res: where to place the result |
| 6253 | * |
| 6254 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6255 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6256 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6257 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6258 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6259 | { |
| 6260 | nfs4_verifier sc_verifier; |
| 6261 | struct nfs4_setclientid setclientid = { |
| 6262 | .sc_verifier = &sc_verifier, |
| 6263 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6264 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6265 | }; |
| 6266 | struct rpc_message msg = { |
| 6267 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6268 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6269 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6270 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6271 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6272 | struct rpc_task_setup task_setup_data = { |
| 6273 | .rpc_client = clp->cl_rpcclient, |
| 6274 | .rpc_message = &msg, |
| 6275 | .callback_ops = &nfs4_setclientid_ops, |
| 6276 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6277 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6278 | }; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6279 | unsigned long now = jiffies; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6280 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6281 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6282 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6283 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6284 | |
| 6285 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6286 | status = nfs4_init_uniform_client_string(clp); |
| 6287 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6288 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6289 | |
| 6290 | if (status) |
| 6291 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6292 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6293 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6294 | setclientid.sc_netid_len = |
| 6295 | nfs4_init_callback_netid(clp, |
| 6296 | setclientid.sc_netid, |
| 6297 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6298 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6299 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6301 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6302 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6303 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6304 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6305 | |
| 6306 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6307 | if (setclientid.sc_cred) { |
Chuck Lever | 1047ec8 | 2019-10-04 09:58:54 -0400 | [diff] [blame] | 6308 | kfree(clp->cl_acceptor); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6309 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6310 | put_rpccred(setclientid.sc_cred); |
| 6311 | } |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 6312 | |
| 6313 | if (status == 0) |
| 6314 | do_renew_lease(clp, now); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6315 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6316 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6317 | dprintk("NFS reply setclientid: %d\n", status); |
| 6318 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6319 | } |
| 6320 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6321 | /** |
| 6322 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6323 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6324 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6325 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6326 | * |
| 6327 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6328 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6329 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6330 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6331 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6332 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6333 | struct rpc_message msg = { |
| 6334 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6335 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6336 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6337 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6338 | int status; |
| 6339 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6340 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6341 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6342 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6343 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6344 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6345 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6346 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | return status; |
| 6348 | } |
| 6349 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6350 | struct nfs4_delegreturndata { |
| 6351 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6352 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6353 | struct nfs_fh fh; |
| 6354 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6355 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6356 | struct { |
| 6357 | struct nfs4_layoutreturn_args arg; |
| 6358 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6359 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6360 | u32 roc_barrier; |
| 6361 | bool roc; |
| 6362 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6363 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6364 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6365 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6366 | }; |
| 6367 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6368 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6369 | { |
| 6370 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6371 | struct nfs4_exception exception = { |
| 6372 | .inode = data->inode, |
| 6373 | .stateid = &data->stateid, |
| 6374 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6375 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6376 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6377 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6378 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6379 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6380 | |
| 6381 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6382 | if (pnfs_roc_done(task, &data->args.lr_args, &data->res.lr_res, |
| 6383 | &data->res.lr_ret) == -EAGAIN) |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6384 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6385 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6386 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6387 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6388 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6389 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6390 | case -NFS4ERR_ADMIN_REVOKED: |
| 6391 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6392 | case -NFS4ERR_EXPIRED: |
| 6393 | nfs4_free_revoked_stateid(data->res.server, |
| 6394 | data->args.stateid, |
| 6395 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6396 | fallthrough; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6397 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6398 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 244fcd2 | 2019-12-20 10:43:37 -0500 | [diff] [blame] | 6399 | case -ETIMEDOUT: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6400 | task->tk_status = 0; |
| 6401 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6402 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6403 | if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6404 | nfs4_stateid_seqid_inc(&data->stateid); |
Trond Myklebust | 70d136b | 2019-10-26 22:37:40 -0400 | [diff] [blame] | 6405 | if (data->args.bitmask) { |
| 6406 | data->args.bitmask = NULL; |
| 6407 | data->res.fattr = NULL; |
| 6408 | } |
Trond Myklebust | 246afc0a | 2019-10-24 18:00:35 -0400 | [diff] [blame] | 6409 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6410 | case -NFS4ERR_ACCESS: |
| 6411 | if (data->args.bitmask) { |
| 6412 | data->args.bitmask = NULL; |
| 6413 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6414 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6415 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6416 | fallthrough; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6417 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6418 | task->tk_status = nfs4_async_handle_exception(task, |
| 6419 | data->res.server, task->tk_status, |
| 6420 | &exception); |
| 6421 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6422 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6423 | } |
Trond Myklebust | d51f91d | 2019-10-21 14:22:14 -0400 | [diff] [blame] | 6424 | nfs_delegation_mark_returned(data->inode, data->args.stateid); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6425 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6426 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6427 | out_restart: |
| 6428 | task->tk_status = 0; |
| 6429 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | static void nfs4_delegreturn_release(void *calldata) |
| 6433 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6434 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6435 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6436 | |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6437 | if (data->lr.roc) |
| 6438 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6439 | data->res.lr_ret); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6440 | if (inode) { |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6441 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6442 | nfs_iput_and_deactive(inode); |
| 6443 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6444 | kfree(calldata); |
| 6445 | } |
| 6446 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6447 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6448 | { |
| 6449 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6450 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6451 | |
| 6452 | d_data = (struct nfs4_delegreturndata *)data; |
| 6453 | |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6454 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) { |
| 6455 | nfs4_sequence_done(task, &d_data->res.seq_res); |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6456 | return; |
Trond Myklebust | 5326de9 | 2019-11-13 09:39:36 +0100 | [diff] [blame] | 6457 | } |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6458 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6459 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6460 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6461 | d_data->args.lr_args = NULL; |
| 6462 | d_data->res.lr_res = NULL; |
| 6463 | } |
| 6464 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6465 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6466 | &d_data->args.seq_args, |
| 6467 | &d_data->res.seq_res, |
| 6468 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6469 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6470 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6471 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6472 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6473 | .rpc_call_done = nfs4_delegreturn_done, |
| 6474 | .rpc_release = nfs4_delegreturn_release, |
| 6475 | }; |
| 6476 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6477 | 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] | 6478 | { |
| 6479 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6480 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6481 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6482 | struct rpc_message msg = { |
| 6483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6484 | .rpc_cred = cred, |
| 6485 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6486 | struct rpc_task_setup task_setup_data = { |
| 6487 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6488 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6489 | .callback_ops = &nfs4_delegreturn_ops, |
Trond Myklebust | f304a80 | 2020-05-11 10:42:04 -0400 | [diff] [blame] | 6490 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6491 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6492 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6493 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6494 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6495 | if (data == NULL) |
| 6496 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6497 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6498 | |
| 6499 | nfs4_state_protect(server->nfs_client, |
| 6500 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6501 | &task_setup_data.rpc_client, &msg); |
| 6502 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6503 | data->args.fhandle = &data->fh; |
| 6504 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6505 | data->args.bitmask = server->cache_consistency_bitmask; |
Olga Kornievskaia | 76bd5c0 | 2020-09-14 17:05:08 -0400 | [diff] [blame] | 6506 | nfs4_bitmask_adjust(data->args.bitmask, inode, server, NULL); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6507 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6508 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6509 | data->res.fattr = &data->fattr; |
| 6510 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6511 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6512 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6513 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6514 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6515 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6516 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 078000d | 2021-01-04 13:18:03 -0500 | [diff] [blame] | 6517 | if (data->inode || issync) { |
| 6518 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, |
| 6519 | cred); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6520 | if (data->lr.roc) { |
| 6521 | data->args.lr_args = &data->lr.arg; |
| 6522 | data->res.lr_res = &data->lr.res; |
| 6523 | } |
| 6524 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6525 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6526 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6527 | msg.rpc_argp = &data->args; |
| 6528 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6529 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6530 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6531 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6532 | if (!issync) |
| 6533 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6534 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6535 | if (status != 0) |
| 6536 | goto out; |
| 6537 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6538 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6539 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6540 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6541 | } |
| 6542 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6543 | 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] | 6544 | { |
| 6545 | struct nfs_server *server = NFS_SERVER(inode); |
| 6546 | struct nfs4_exception exception = { }; |
| 6547 | int err; |
| 6548 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6549 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6550 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6551 | switch (err) { |
| 6552 | case -NFS4ERR_STALE_STATEID: |
| 6553 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6554 | case 0: |
| 6555 | return 0; |
| 6556 | } |
| 6557 | err = nfs4_handle_exception(server, err, &exception); |
| 6558 | } while (exception.retry); |
| 6559 | return err; |
| 6560 | } |
| 6561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6562 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6563 | { |
| 6564 | struct inode *inode = state->inode; |
| 6565 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6566 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6567 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6568 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6569 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6570 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6571 | struct nfs_lockt_res res = { |
| 6572 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6573 | }; |
| 6574 | struct rpc_message msg = { |
| 6575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6576 | .rpc_argp = &arg, |
| 6577 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6578 | .rpc_cred = state->owner->so_cred, |
| 6579 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6580 | struct nfs4_lock_state *lsp; |
| 6581 | int status; |
| 6582 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6583 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6584 | status = nfs4_set_lock_state(state, request); |
| 6585 | if (status != 0) |
| 6586 | goto out; |
| 6587 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6588 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6589 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6590 | 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] | 6591 | switch (status) { |
| 6592 | case 0: |
| 6593 | request->fl_type = F_UNLCK; |
| 6594 | break; |
| 6595 | case -NFS4ERR_DENIED: |
| 6596 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6597 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6598 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6599 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6600 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6601 | return status; |
| 6602 | } |
| 6603 | |
| 6604 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6605 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6606 | struct nfs4_exception exception = { |
| 6607 | .interruptible = true, |
| 6608 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6609 | int err; |
| 6610 | |
| 6611 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6612 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6613 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6614 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6615 | &exception); |
| 6616 | } while (exception.retry); |
| 6617 | return err; |
| 6618 | } |
| 6619 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6620 | /* |
| 6621 | * Update the seqid of a lock stateid after receiving |
| 6622 | * NFS4ERR_OLD_STATEID |
| 6623 | */ |
| 6624 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6625 | struct nfs4_lock_state *lsp) |
| 6626 | { |
| 6627 | struct nfs4_state *state = lsp->ls_state; |
| 6628 | bool ret = false; |
| 6629 | |
| 6630 | spin_lock(&state->state_lock); |
| 6631 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6632 | goto out; |
| 6633 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6634 | nfs4_stateid_seqid_inc(dst); |
| 6635 | else |
| 6636 | dst->seqid = lsp->ls_stateid.seqid; |
| 6637 | ret = true; |
| 6638 | out: |
| 6639 | spin_unlock(&state->state_lock); |
| 6640 | return ret; |
| 6641 | } |
| 6642 | |
| 6643 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6644 | struct nfs4_lock_state *lsp) |
| 6645 | { |
| 6646 | struct nfs4_state *state = lsp->ls_state; |
| 6647 | bool ret; |
| 6648 | |
| 6649 | spin_lock(&state->state_lock); |
| 6650 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6651 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6652 | spin_unlock(&state->state_lock); |
| 6653 | return ret; |
| 6654 | } |
| 6655 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6656 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6657 | struct nfs_locku_args arg; |
| 6658 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6659 | struct nfs4_lock_state *lsp; |
| 6660 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6661 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6662 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6663 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6664 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6665 | }; |
| 6666 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6667 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6668 | struct nfs_open_context *ctx, |
| 6669 | struct nfs4_lock_state *lsp, |
| 6670 | struct nfs_seqid *seqid) |
| 6671 | { |
| 6672 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6673 | struct nfs4_state *state = lsp->ls_state; |
| 6674 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6675 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6676 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6677 | if (p == NULL) |
| 6678 | return NULL; |
| 6679 | p->arg.fh = NFS_FH(inode); |
| 6680 | p->arg.fl = &p->fl; |
| 6681 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6682 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6683 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6684 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6685 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6686 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6687 | locks_init_lock(&p->fl); |
| 6688 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6689 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6690 | spin_lock(&state->state_lock); |
| 6691 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6692 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6693 | return p; |
| 6694 | } |
| 6695 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6696 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6697 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6698 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6699 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6700 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6701 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6702 | put_nfs_open_context(calldata->ctx); |
| 6703 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6704 | } |
| 6705 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6706 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6707 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6708 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6709 | struct nfs4_exception exception = { |
| 6710 | .inode = calldata->lsp->ls_state->inode, |
| 6711 | .stateid = &calldata->arg.stateid, |
| 6712 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6713 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6714 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6715 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6716 | switch (task->tk_status) { |
| 6717 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6718 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6719 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6720 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6721 | &calldata->res.stateid)) |
| 6722 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6723 | fallthrough; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6724 | case -NFS4ERR_ADMIN_REVOKED: |
| 6725 | case -NFS4ERR_EXPIRED: |
| 6726 | nfs4_free_revoked_stateid(calldata->server, |
| 6727 | &calldata->arg.stateid, |
| 6728 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 6729 | fallthrough; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6730 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6731 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6732 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6733 | calldata->lsp)) |
| 6734 | rpc_restart_call_prepare(task); |
| 6735 | break; |
| 6736 | case -NFS4ERR_OLD_STATEID: |
| 6737 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6738 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6739 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6740 | break; |
| 6741 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6742 | task->tk_status = nfs4_async_handle_exception(task, |
| 6743 | calldata->server, task->tk_status, |
| 6744 | &exception); |
| 6745 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6746 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6747 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6748 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6749 | } |
| 6750 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6751 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6752 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6753 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6754 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6755 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6756 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6757 | return; |
| 6758 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6759 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6760 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6761 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6762 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6763 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6764 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6765 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6766 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6767 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6768 | &calldata->res.seq_res, |
| 6769 | task) != 0) |
| 6770 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6771 | return; |
| 6772 | out_no_action: |
| 6773 | task->tk_action = NULL; |
| 6774 | out_wait: |
| 6775 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6776 | } |
| 6777 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6778 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6779 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6780 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6781 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6782 | }; |
| 6783 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6784 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6785 | struct nfs_open_context *ctx, |
| 6786 | struct nfs4_lock_state *lsp, |
| 6787 | struct nfs_seqid *seqid) |
| 6788 | { |
| 6789 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6790 | struct rpc_message msg = { |
| 6791 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6792 | .rpc_cred = ctx->cred, |
| 6793 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6794 | struct rpc_task_setup task_setup_data = { |
| 6795 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6796 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6797 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6798 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6799 | .flags = RPC_TASK_ASYNC, |
| 6800 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6801 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6802 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6803 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6804 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6805 | /* Ensure this is an unlock - when canceling a lock, the |
| 6806 | * canceled lock is passed in, and it won't be an unlock. |
| 6807 | */ |
| 6808 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6809 | if (fl->fl_flags & FL_CLOSE) |
| 6810 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6811 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6812 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6813 | if (data == NULL) { |
| 6814 | nfs_free_seqid(seqid); |
| 6815 | return ERR_PTR(-ENOMEM); |
| 6816 | } |
| 6817 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6818 | 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] | 6819 | msg.rpc_argp = &data->arg; |
| 6820 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6821 | task_setup_data.callback_data = data; |
| 6822 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6823 | } |
| 6824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6825 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6826 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6827 | struct inode *inode = state->inode; |
| 6828 | struct nfs4_state_owner *sp = state->owner; |
| 6829 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6830 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6831 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6832 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6833 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6834 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6835 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6836 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6837 | status = nfs4_set_lock_state(state, request); |
| 6838 | /* Unlock _before_ we do the RPC call */ |
| 6839 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6840 | /* Exclude nfs_delegation_claim_locks() */ |
| 6841 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6842 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6843 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6844 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6845 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6846 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6847 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6848 | } |
| 6849 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6850 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6851 | if (status != 0) |
| 6852 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6853 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6854 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6855 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6856 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6857 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6858 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6859 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6860 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6861 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6862 | 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] | 6863 | status = PTR_ERR(task); |
| 6864 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6865 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6866 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6867 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6868 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6869 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6870 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6871 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6872 | } |
| 6873 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6874 | struct nfs4_lockdata { |
| 6875 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6876 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6877 | struct nfs4_lock_state *lsp; |
| 6878 | struct nfs_open_context *ctx; |
| 6879 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6880 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6881 | int rpc_status; |
| 6882 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6883 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6884 | }; |
| 6885 | |
| 6886 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6887 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6888 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6889 | { |
| 6890 | struct nfs4_lockdata *p; |
| 6891 | struct inode *inode = lsp->ls_state->inode; |
| 6892 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6893 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6894 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6895 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6896 | if (p == NULL) |
| 6897 | return NULL; |
| 6898 | |
| 6899 | p->arg.fh = NFS_FH(inode); |
| 6900 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6901 | 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] | 6902 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6903 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6904 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6905 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6906 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6907 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6908 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6909 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6910 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6911 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6912 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6913 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6914 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6915 | locks_init_lock(&p->fl); |
| 6916 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6917 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6918 | out_free_seqid: |
| 6919 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6920 | out_free: |
| 6921 | kfree(p); |
| 6922 | return NULL; |
| 6923 | } |
| 6924 | |
| 6925 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6926 | { |
| 6927 | struct nfs4_lockdata *data = calldata; |
| 6928 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6929 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6930 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6931 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6932 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6933 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6934 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6935 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6936 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6937 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6938 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6939 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6940 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6941 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6942 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6943 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6944 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6945 | &data->lsp->ls_stateid); |
| 6946 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6947 | if (!nfs4_valid_open_stateid(state)) { |
| 6948 | data->rpc_status = -EBADF; |
| 6949 | task->tk_action = NULL; |
| 6950 | goto out_release_open_seqid; |
| 6951 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6952 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6953 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6954 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6955 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6956 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6957 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6958 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6959 | nfs_release_seqid(data->arg.open_seqid); |
| 6960 | out_release_lock_seqid: |
| 6961 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6962 | out_wait: |
| 6963 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6964 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6965 | } |
| 6966 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6967 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6968 | { |
| 6969 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6970 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6971 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6972 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6973 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6974 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6975 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6976 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6977 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6978 | switch (task->tk_status) { |
| 6979 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6980 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6981 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6982 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6983 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6984 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6985 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6986 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6987 | if (data->arg.new_lock_owner != 0) { |
| 6988 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6989 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6990 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6991 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6992 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6993 | break; |
| 6994 | case -NFS4ERR_BAD_STATEID: |
| 6995 | case -NFS4ERR_OLD_STATEID: |
| 6996 | case -NFS4ERR_STALE_STATEID: |
| 6997 | case -NFS4ERR_EXPIRED: |
| 6998 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6999 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7000 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7001 | goto out_restart; |
| 7002 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 7003 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7004 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7005 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 7006 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7007 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7008 | return; |
| 7009 | out_restart: |
| 7010 | if (!data->cancelled) |
| 7011 | rpc_restart_call_prepare(task); |
| 7012 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7013 | } |
| 7014 | |
| 7015 | static void nfs4_lock_release(void *calldata) |
| 7016 | { |
| 7017 | struct nfs4_lockdata *data = calldata; |
| 7018 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7019 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 7020 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 7021 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7022 | struct rpc_task *task; |
| 7023 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 7024 | data->arg.lock_seqid); |
| 7025 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7026 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7027 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7028 | } else |
| 7029 | nfs_free_seqid(data->arg.lock_seqid); |
| 7030 | nfs4_put_lock_state(data->lsp); |
| 7031 | put_nfs_open_context(data->ctx); |
| 7032 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7033 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7034 | } |
| 7035 | |
| 7036 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 7037 | .rpc_call_prepare = nfs4_lock_prepare, |
| 7038 | .rpc_call_done = nfs4_lock_done, |
| 7039 | .rpc_release = nfs4_lock_release, |
| 7040 | }; |
| 7041 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7042 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 7043 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7044 | switch (error) { |
| 7045 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 7046 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7047 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7048 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7049 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 7050 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7051 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7052 | break; |
| 7053 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 7054 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 7055 | nfs4_schedule_lease_recovery(server->nfs_client); |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 7056 | } |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7057 | } |
| 7058 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7059 | 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] | 7060 | { |
| 7061 | struct nfs4_lockdata *data; |
| 7062 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7063 | struct rpc_message msg = { |
| 7064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 7065 | .rpc_cred = state->owner->so_cred, |
| 7066 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7067 | struct rpc_task_setup task_setup_data = { |
| 7068 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 7069 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7070 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 7071 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | 6129650 | 2020-02-07 19:38:12 -0500 | [diff] [blame] | 7072 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7073 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7074 | int ret; |
| 7075 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7076 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7077 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7078 | fl->fl_u.nfs4_fl.owner, |
| 7079 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7080 | if (data == NULL) |
| 7081 | return -ENOMEM; |
| 7082 | if (IS_SETLKW(cmd)) |
| 7083 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7084 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 7085 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 7086 | msg.rpc_argp = &data->arg; |
| 7087 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7088 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7089 | if (recovery_type > NFS_LOCK_NEW) { |
| 7090 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 7091 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7092 | } else |
| 7093 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 7094 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 7095 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7096 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 7097 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7098 | if (ret == 0) { |
| 7099 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 7100 | if (ret) |
| 7101 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 7102 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7103 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 7104 | data->cancelled = true; |
Dave Wysochanski | 3d1a90a | 2020-12-11 05:12:51 -0500 | [diff] [blame] | 7105 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 7106 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7107 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 7108 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7109 | } |
| 7110 | |
| 7111 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 7112 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7113 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7114 | struct nfs4_exception exception = { |
| 7115 | .inode = state->inode, |
| 7116 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7117 | int err; |
| 7118 | |
| 7119 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7120 | /* Cache the lock if possible... */ |
| 7121 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7122 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7123 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 7124 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7125 | break; |
| 7126 | nfs4_handle_exception(server, err, &exception); |
| 7127 | } while (exception.retry); |
| 7128 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7129 | } |
| 7130 | |
| 7131 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7132 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7133 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7134 | struct nfs4_exception exception = { |
| 7135 | .inode = state->inode, |
| 7136 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7137 | int err; |
| 7138 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 7139 | err = nfs4_set_lock_state(state, request); |
| 7140 | if (err != 0) |
| 7141 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 7142 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 7143 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 7144 | return 0; |
| 7145 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7146 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 7147 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 7148 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7149 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7150 | switch (err) { |
| 7151 | default: |
| 7152 | goto out; |
| 7153 | case -NFS4ERR_GRACE: |
| 7154 | case -NFS4ERR_DELAY: |
| 7155 | nfs4_handle_exception(server, err, &exception); |
| 7156 | err = 0; |
| 7157 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7158 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 7159 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 7160 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7161 | } |
| 7162 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7163 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7164 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 7165 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7166 | struct nfs4_lock_state *lsp; |
| 7167 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 7168 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 7169 | status = nfs4_set_lock_state(state, request); |
| 7170 | if (status != 0) |
| 7171 | return status; |
| 7172 | lsp = request->fl_u.nfs4_fl.owner; |
| 7173 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 7174 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 7175 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 7176 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7177 | } |
| 7178 | #endif |
| 7179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7180 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7181 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7182 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7183 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7184 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7185 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7186 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7187 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7188 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7189 | if (status < 0) |
| 7190 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7191 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7192 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7193 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7194 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7195 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 7196 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 7197 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7198 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7199 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 7200 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7201 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 7202 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 7203 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 7204 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 7205 | out: |
| 7206 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7207 | return status; |
| 7208 | } |
| 7209 | |
| 7210 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7211 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7212 | struct nfs4_exception exception = { |
| 7213 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7214 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7215 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7216 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7217 | int err; |
| 7218 | |
| 7219 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7220 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7221 | if (err == -NFS4ERR_DENIED) |
| 7222 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7223 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7224 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7225 | } while (exception.retry); |
| 7226 | return err; |
| 7227 | } |
| 7228 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7229 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7230 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7231 | |
| 7232 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7233 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7234 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7235 | { |
| 7236 | int status = -ERESTARTSYS; |
| 7237 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7238 | |
| 7239 | while(!signalled()) { |
| 7240 | status = nfs4_proc_setlk(state, cmd, request); |
| 7241 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7242 | break; |
| 7243 | freezable_schedule_timeout_interruptible(timeout); |
| 7244 | timeout *= 2; |
| 7245 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7246 | status = -ERESTARTSYS; |
| 7247 | } |
| 7248 | return status; |
| 7249 | } |
| 7250 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7251 | #ifdef CONFIG_NFS_V4_1 |
| 7252 | struct nfs4_lock_waiter { |
| 7253 | struct task_struct *task; |
| 7254 | struct inode *inode; |
| 7255 | struct nfs_lowner *owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7256 | }; |
| 7257 | |
| 7258 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7259 | 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] | 7260 | { |
| 7261 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7262 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7263 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7264 | /* NULL key means to wake up everyone */ |
| 7265 | if (key) { |
| 7266 | struct cb_notify_lock_args *cbnl = key; |
| 7267 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 7268 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7269 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7270 | /* Only wake if the callback was for the same owner. */ |
| 7271 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7272 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7273 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7274 | /* Make sure it's for the right inode */ |
| 7275 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7276 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7277 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7278 | |
| 7279 | /* override "private" so we can use default_wake_function */ |
| 7280 | wait->private = waiter->task; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7281 | ret = woken_wake_function(wait, mode, flags, key); |
| 7282 | if (ret) |
| 7283 | list_del_init(&wait->entry); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7284 | wait->private = waiter; |
| 7285 | return ret; |
| 7286 | } |
| 7287 | |
| 7288 | static int |
| 7289 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7290 | { |
| 7291 | int status = -ERESTARTSYS; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7292 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7293 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7294 | struct nfs_client *clp = server->nfs_client; |
| 7295 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 7296 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 7297 | .id = lsp->ls_seqid.owner_id, |
| 7298 | .s_dev = server->s_dev }; |
| 7299 | struct nfs4_lock_waiter waiter = { .task = current, |
| 7300 | .inode = state->inode, |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7301 | .owner = &owner}; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7302 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7303 | |
| 7304 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7305 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7306 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7307 | |
| 7308 | init_wait(&wait); |
| 7309 | wait.private = &waiter; |
| 7310 | wait.func = nfs4_wake_lock_waiter; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7311 | |
| 7312 | while(!signalled()) { |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7313 | add_wait_queue(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7314 | status = nfs4_proc_setlk(state, cmd, request); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7315 | if ((status != -EAGAIN) || IS_SETLK(cmd)) { |
| 7316 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7317 | break; |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7318 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7319 | |
| 7320 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7321 | freezer_do_not_count(); |
| 7322 | wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT); |
| 7323 | freezer_count(); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7324 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7325 | } |
| 7326 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7327 | return status; |
| 7328 | } |
| 7329 | #else /* !CONFIG_NFS_V4_1 */ |
| 7330 | static inline int |
| 7331 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7332 | { |
| 7333 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7334 | } |
| 7335 | #endif |
| 7336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7337 | static int |
| 7338 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7339 | { |
| 7340 | struct nfs_open_context *ctx; |
| 7341 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7342 | int status; |
| 7343 | |
| 7344 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7345 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7346 | state = ctx->state; |
| 7347 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7348 | if (IS_GETLK(cmd)) { |
| 7349 | if (state != NULL) |
| 7350 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7351 | return 0; |
| 7352 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7353 | |
| 7354 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7355 | return -EINVAL; |
| 7356 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7357 | if (request->fl_type == F_UNLCK) { |
| 7358 | if (state != NULL) |
| 7359 | return nfs4_proc_unlck(state, cmd, request); |
| 7360 | return 0; |
| 7361 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7362 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7363 | if (state == NULL) |
| 7364 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7365 | |
| 7366 | if ((request->fl_flags & FL_POSIX) && |
| 7367 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7368 | return -ENOLCK; |
| 7369 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7370 | /* |
| 7371 | * Don't rely on the VFS having checked the file open mode, |
| 7372 | * since it won't do this for flock() locks. |
| 7373 | */ |
| 7374 | switch (request->fl_type) { |
| 7375 | case F_RDLCK: |
| 7376 | if (!(filp->f_mode & FMODE_READ)) |
| 7377 | return -EBADF; |
| 7378 | break; |
| 7379 | case F_WRLCK: |
| 7380 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7381 | return -EBADF; |
| 7382 | } |
| 7383 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7384 | status = nfs4_set_lock_state(state, request); |
| 7385 | if (status != 0) |
| 7386 | return status; |
| 7387 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7388 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7389 | } |
| 7390 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7391 | 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] | 7392 | { |
| 7393 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7394 | int err; |
| 7395 | |
| 7396 | err = nfs4_set_lock_state(state, fl); |
| 7397 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7398 | return err; |
Olga Kornievskaia | 3d7a952 | 2020-08-20 18:52:43 -0400 | [diff] [blame] | 7399 | do { |
| 7400 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
| 7401 | if (err != -NFS4ERR_DELAY) |
| 7402 | break; |
| 7403 | ssleep(1); |
| 7404 | } while (err == -NFS4ERR_DELAY); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7405 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7406 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7407 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7408 | struct nfs_release_lockowner_data { |
| 7409 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7410 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7411 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7412 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7413 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7414 | }; |
| 7415 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7416 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7417 | { |
| 7418 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7419 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7420 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7421 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7422 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7423 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7424 | } |
| 7425 | |
| 7426 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7427 | { |
| 7428 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7429 | struct nfs_server *server = data->server; |
| 7430 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7431 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7432 | |
| 7433 | switch (task->tk_status) { |
| 7434 | case 0: |
| 7435 | renew_lease(server, data->timestamp); |
| 7436 | break; |
| 7437 | case -NFS4ERR_STALE_CLIENTID: |
| 7438 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7439 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7440 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7441 | case -NFS4ERR_LEASE_MOVED: |
| 7442 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7443 | if (nfs4_async_handle_error(task, server, |
| 7444 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7445 | rpc_restart_call_prepare(task); |
| 7446 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7447 | } |
| 7448 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7449 | static void nfs4_release_lockowner_release(void *calldata) |
| 7450 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7451 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7452 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7453 | kfree(calldata); |
| 7454 | } |
| 7455 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7456 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7457 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7458 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7459 | .rpc_release = nfs4_release_lockowner_release, |
| 7460 | }; |
| 7461 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7462 | static void |
| 7463 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7464 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7465 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7466 | struct rpc_message msg = { |
| 7467 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7468 | }; |
| 7469 | |
| 7470 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7471 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7472 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7473 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7474 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7475 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7476 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7477 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7478 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7479 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7480 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7481 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7482 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7483 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7484 | 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] | 7485 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7486 | } |
| 7487 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7488 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7489 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7490 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7491 | struct dentry *unused, struct inode *inode, |
| 7492 | const char *key, const void *buf, |
| 7493 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7494 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7495 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7496 | } |
| 7497 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7498 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7499 | struct dentry *unused, struct inode *inode, |
| 7500 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7501 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7502 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7503 | } |
| 7504 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7505 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7506 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7507 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7508 | } |
| 7509 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7510 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7511 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7512 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7513 | struct dentry *unused, struct inode *inode, |
| 7514 | const char *key, const void *buf, |
| 7515 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7516 | { |
| 7517 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7518 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7519 | |
| 7520 | return -EOPNOTSUPP; |
| 7521 | } |
| 7522 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7523 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7524 | struct dentry *unused, struct inode *inode, |
| 7525 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7526 | { |
| 7527 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7528 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7529 | return -EOPNOTSUPP; |
| 7530 | } |
| 7531 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7532 | static ssize_t |
| 7533 | 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] | 7534 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7535 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7536 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7537 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7538 | len = security_inode_listsecurity(inode, list, list_len); |
Chengguang Xu | 82c596e | 2020-06-17 09:09:39 +0800 | [diff] [blame] | 7539 | if (len >= 0 && list_len && len > list_len) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7540 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7541 | } |
| 7542 | return len; |
| 7543 | } |
| 7544 | |
| 7545 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7546 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7547 | .get = nfs4_xattr_get_nfs4_label, |
| 7548 | .set = nfs4_xattr_set_nfs4_label, |
| 7549 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7550 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7551 | #else |
| 7552 | |
| 7553 | static ssize_t |
| 7554 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7555 | { |
| 7556 | return 0; |
| 7557 | } |
| 7558 | |
| 7559 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7560 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7561 | #ifdef CONFIG_NFS_V4_2 |
| 7562 | static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler, |
| 7563 | struct dentry *unused, struct inode *inode, |
| 7564 | const char *key, const void *buf, |
| 7565 | size_t buflen, int flags) |
| 7566 | { |
| 7567 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7568 | int ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7569 | |
| 7570 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7571 | return -EOPNOTSUPP; |
| 7572 | |
| 7573 | /* |
| 7574 | * There is no mapping from the MAY_* flags to the NFS_ACCESS_XA* |
| 7575 | * flags right now. Handling of xattr operations use the normal |
| 7576 | * file read/write permissions. |
| 7577 | * |
| 7578 | * Just in case the server has other ideas (which RFC 8276 allows), |
| 7579 | * do a cached access check for the XA* flags to possibly avoid |
| 7580 | * doing an RPC and getting EACCES back. |
| 7581 | */ |
| 7582 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7583 | if (!(cache.mask & NFS_ACCESS_XAWRITE)) |
| 7584 | return -EACCES; |
| 7585 | } |
| 7586 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7587 | if (buf == NULL) { |
| 7588 | ret = nfs42_proc_removexattr(inode, key); |
| 7589 | if (!ret) |
| 7590 | nfs4_xattr_cache_remove(inode, key); |
| 7591 | } else { |
| 7592 | ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags); |
| 7593 | if (!ret) |
| 7594 | nfs4_xattr_cache_add(inode, key, buf, NULL, buflen); |
| 7595 | } |
| 7596 | |
| 7597 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7598 | } |
| 7599 | |
| 7600 | static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler, |
| 7601 | struct dentry *unused, struct inode *inode, |
| 7602 | const char *key, void *buf, size_t buflen) |
| 7603 | { |
| 7604 | struct nfs_access_entry cache; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7605 | ssize_t ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7606 | |
| 7607 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7608 | return -EOPNOTSUPP; |
| 7609 | |
| 7610 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7611 | if (!(cache.mask & NFS_ACCESS_XAREAD)) |
| 7612 | return -EACCES; |
| 7613 | } |
| 7614 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7615 | ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); |
| 7616 | if (ret) |
| 7617 | return ret; |
| 7618 | |
| 7619 | ret = nfs4_xattr_cache_get(inode, key, buf, buflen); |
| 7620 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7621 | return ret; |
| 7622 | |
| 7623 | ret = nfs42_proc_getxattr(inode, key, buf, buflen); |
| 7624 | |
| 7625 | return ret; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7626 | } |
| 7627 | |
| 7628 | static ssize_t |
| 7629 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7630 | { |
| 7631 | u64 cookie; |
| 7632 | bool eof; |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7633 | ssize_t ret, size; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7634 | char *buf; |
| 7635 | size_t buflen; |
| 7636 | struct nfs_access_entry cache; |
| 7637 | |
| 7638 | if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
| 7639 | return 0; |
| 7640 | |
| 7641 | if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) { |
| 7642 | if (!(cache.mask & NFS_ACCESS_XALIST)) |
| 7643 | return 0; |
| 7644 | } |
| 7645 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7646 | ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); |
| 7647 | if (ret) |
| 7648 | return ret; |
| 7649 | |
| 7650 | ret = nfs4_xattr_cache_list(inode, list, list_len); |
| 7651 | if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
| 7652 | return ret; |
| 7653 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7654 | cookie = 0; |
| 7655 | eof = false; |
| 7656 | buflen = list_len ? list_len : XATTR_LIST_MAX; |
| 7657 | buf = list_len ? list : NULL; |
| 7658 | size = 0; |
| 7659 | |
| 7660 | while (!eof) { |
| 7661 | ret = nfs42_proc_listxattrs(inode, buf, buflen, |
| 7662 | &cookie, &eof); |
| 7663 | if (ret < 0) |
| 7664 | return ret; |
| 7665 | |
| 7666 | if (list_len) { |
| 7667 | buf += ret; |
| 7668 | buflen -= ret; |
| 7669 | } |
| 7670 | size += ret; |
| 7671 | } |
| 7672 | |
Frank van der Linden | 95ad37f | 2020-06-23 22:39:04 +0000 | [diff] [blame] | 7673 | if (list_len) |
| 7674 | nfs4_xattr_cache_set_list(inode, list, size); |
| 7675 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 7676 | return size; |
| 7677 | } |
| 7678 | |
| 7679 | #else |
| 7680 | |
| 7681 | static ssize_t |
| 7682 | nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
| 7683 | { |
| 7684 | return 0; |
| 7685 | } |
| 7686 | #endif /* CONFIG_NFS_V4_2 */ |
| 7687 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7688 | /* |
| 7689 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7690 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7691 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7692 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7693 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7694 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7695 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7696 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7697 | return; |
| 7698 | |
| 7699 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7700 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7701 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7702 | fattr->nlink = 2; |
| 7703 | } |
| 7704 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7705 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7706 | const struct qstr *name, |
| 7707 | struct nfs4_fs_locations *fs_locations, |
| 7708 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7709 | { |
| 7710 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7711 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7712 | struct nfs4_fs_locations_arg args = { |
| 7713 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7714 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7715 | .page = page, |
| 7716 | .bitmask = bitmask, |
| 7717 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7718 | struct nfs4_fs_locations_res res = { |
| 7719 | .fs_locations = fs_locations, |
| 7720 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7721 | struct rpc_message msg = { |
| 7722 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7723 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7724 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7725 | }; |
| 7726 | int status; |
| 7727 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7728 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7729 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7730 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7731 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7732 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7733 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7734 | * is not supported */ |
| 7735 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7736 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7737 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7738 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7739 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7740 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7741 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7742 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7743 | 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] | 7744 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7745 | return status; |
| 7746 | } |
| 7747 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7748 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7749 | const struct qstr *name, |
| 7750 | struct nfs4_fs_locations *fs_locations, |
| 7751 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7752 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7753 | struct nfs4_exception exception = { |
| 7754 | .interruptible = true, |
| 7755 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7756 | int err; |
| 7757 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7758 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7759 | fs_locations, page); |
| 7760 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7761 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7762 | &exception); |
| 7763 | } while (exception.retry); |
| 7764 | return err; |
| 7765 | } |
| 7766 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7767 | /* |
| 7768 | * This operation also signals the server that this client is |
| 7769 | * performing migration recovery. The server can stop returning |
| 7770 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7771 | * appended to this compound to identify the client ID which is |
| 7772 | * performing recovery. |
| 7773 | */ |
| 7774 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7775 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7776 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7777 | { |
| 7778 | struct nfs_server *server = NFS_SERVER(inode); |
| 7779 | struct rpc_clnt *clnt = server->client; |
| 7780 | u32 bitmask[2] = { |
| 7781 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7782 | }; |
| 7783 | struct nfs4_fs_locations_arg args = { |
| 7784 | .clientid = server->nfs_client->cl_clientid, |
| 7785 | .fh = NFS_FH(inode), |
| 7786 | .page = page, |
| 7787 | .bitmask = bitmask, |
| 7788 | .migration = 1, /* skip LOOKUP */ |
| 7789 | .renew = 1, /* append RENEW */ |
| 7790 | }; |
| 7791 | struct nfs4_fs_locations_res res = { |
| 7792 | .fs_locations = locations, |
| 7793 | .migration = 1, |
| 7794 | .renew = 1, |
| 7795 | }; |
| 7796 | struct rpc_message msg = { |
| 7797 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7798 | .rpc_argp = &args, |
| 7799 | .rpc_resp = &res, |
| 7800 | .rpc_cred = cred, |
| 7801 | }; |
| 7802 | unsigned long now = jiffies; |
| 7803 | int status; |
| 7804 | |
| 7805 | nfs_fattr_init(&locations->fattr); |
| 7806 | locations->server = server; |
| 7807 | locations->nlocations = 0; |
| 7808 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7809 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7810 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7811 | &args.seq_args, &res.seq_res); |
| 7812 | if (status) |
| 7813 | return status; |
| 7814 | |
| 7815 | renew_lease(server, now); |
| 7816 | return 0; |
| 7817 | } |
| 7818 | |
| 7819 | #ifdef CONFIG_NFS_V4_1 |
| 7820 | |
| 7821 | /* |
| 7822 | * This operation also signals the server that this client is |
| 7823 | * performing migration recovery. The server can stop asserting |
| 7824 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7825 | * performing this operation is identified in the SEQUENCE |
| 7826 | * operation in this compound. |
| 7827 | * |
| 7828 | * When the client supports GETATTR(fs_locations_info), it can |
| 7829 | * be plumbed in here. |
| 7830 | */ |
| 7831 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7832 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7833 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7834 | { |
| 7835 | struct nfs_server *server = NFS_SERVER(inode); |
| 7836 | struct rpc_clnt *clnt = server->client; |
| 7837 | u32 bitmask[2] = { |
| 7838 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7839 | }; |
| 7840 | struct nfs4_fs_locations_arg args = { |
| 7841 | .fh = NFS_FH(inode), |
| 7842 | .page = page, |
| 7843 | .bitmask = bitmask, |
| 7844 | .migration = 1, /* skip LOOKUP */ |
| 7845 | }; |
| 7846 | struct nfs4_fs_locations_res res = { |
| 7847 | .fs_locations = locations, |
| 7848 | .migration = 1, |
| 7849 | }; |
| 7850 | struct rpc_message msg = { |
| 7851 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7852 | .rpc_argp = &args, |
| 7853 | .rpc_resp = &res, |
| 7854 | .rpc_cred = cred, |
| 7855 | }; |
| 7856 | int status; |
| 7857 | |
| 7858 | nfs_fattr_init(&locations->fattr); |
| 7859 | locations->server = server; |
| 7860 | locations->nlocations = 0; |
| 7861 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7862 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7863 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7864 | &args.seq_args, &res.seq_res); |
| 7865 | if (status == NFS4_OK && |
| 7866 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7867 | status = -NFS4ERR_LEASE_MOVED; |
| 7868 | return status; |
| 7869 | } |
| 7870 | |
| 7871 | #endif /* CONFIG_NFS_V4_1 */ |
| 7872 | |
| 7873 | /** |
| 7874 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7875 | * @inode: inode on FSID that is migrating |
| 7876 | * @locations: result of query |
| 7877 | * @page: buffer |
| 7878 | * @cred: credential to use for this operation |
| 7879 | * |
| 7880 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7881 | * operation failed, or a negative errno if a local error occurred. |
| 7882 | * |
| 7883 | * On success, "locations" is filled in, but if the server has |
| 7884 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7885 | * asserted. |
| 7886 | * |
| 7887 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7888 | * from this client that require migration recovery. |
| 7889 | */ |
| 7890 | int nfs4_proc_get_locations(struct inode *inode, |
| 7891 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7892 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7893 | { |
| 7894 | struct nfs_server *server = NFS_SERVER(inode); |
| 7895 | struct nfs_client *clp = server->nfs_client; |
| 7896 | const struct nfs4_mig_recovery_ops *ops = |
| 7897 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7898 | struct nfs4_exception exception = { |
| 7899 | .interruptible = true, |
| 7900 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7901 | int status; |
| 7902 | |
| 7903 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7904 | (unsigned long long)server->fsid.major, |
| 7905 | (unsigned long long)server->fsid.minor, |
| 7906 | clp->cl_hostname); |
| 7907 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7908 | |
| 7909 | do { |
| 7910 | status = ops->get_locations(inode, locations, page, cred); |
| 7911 | if (status != -NFS4ERR_DELAY) |
| 7912 | break; |
| 7913 | nfs4_handle_exception(server, status, &exception); |
| 7914 | } while (exception.retry); |
| 7915 | return status; |
| 7916 | } |
| 7917 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7918 | /* |
| 7919 | * This operation also signals the server that this client is |
| 7920 | * performing "lease moved" recovery. The server can stop |
| 7921 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7922 | * is appended to this compound to identify the client ID which is |
| 7923 | * performing recovery. |
| 7924 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7925 | 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] | 7926 | { |
| 7927 | struct nfs_server *server = NFS_SERVER(inode); |
| 7928 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7929 | struct rpc_clnt *clnt = server->client; |
| 7930 | struct nfs4_fsid_present_arg args = { |
| 7931 | .fh = NFS_FH(inode), |
| 7932 | .clientid = clp->cl_clientid, |
| 7933 | .renew = 1, /* append RENEW */ |
| 7934 | }; |
| 7935 | struct nfs4_fsid_present_res res = { |
| 7936 | .renew = 1, |
| 7937 | }; |
| 7938 | struct rpc_message msg = { |
| 7939 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7940 | .rpc_argp = &args, |
| 7941 | .rpc_resp = &res, |
| 7942 | .rpc_cred = cred, |
| 7943 | }; |
| 7944 | unsigned long now = jiffies; |
| 7945 | int status; |
| 7946 | |
| 7947 | res.fh = nfs_alloc_fhandle(); |
| 7948 | if (res.fh == NULL) |
| 7949 | return -ENOMEM; |
| 7950 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7951 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7952 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7953 | &args.seq_args, &res.seq_res); |
| 7954 | nfs_free_fhandle(res.fh); |
| 7955 | if (status) |
| 7956 | return status; |
| 7957 | |
| 7958 | do_renew_lease(clp, now); |
| 7959 | return 0; |
| 7960 | } |
| 7961 | |
| 7962 | #ifdef CONFIG_NFS_V4_1 |
| 7963 | |
| 7964 | /* |
| 7965 | * This operation also signals the server that this client is |
| 7966 | * performing "lease moved" recovery. The server can stop asserting |
| 7967 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7968 | * this operation is identified in the SEQUENCE operation in this |
| 7969 | * compound. |
| 7970 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7971 | 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] | 7972 | { |
| 7973 | struct nfs_server *server = NFS_SERVER(inode); |
| 7974 | struct rpc_clnt *clnt = server->client; |
| 7975 | struct nfs4_fsid_present_arg args = { |
| 7976 | .fh = NFS_FH(inode), |
| 7977 | }; |
| 7978 | struct nfs4_fsid_present_res res = { |
| 7979 | }; |
| 7980 | struct rpc_message msg = { |
| 7981 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7982 | .rpc_argp = &args, |
| 7983 | .rpc_resp = &res, |
| 7984 | .rpc_cred = cred, |
| 7985 | }; |
| 7986 | int status; |
| 7987 | |
| 7988 | res.fh = nfs_alloc_fhandle(); |
| 7989 | if (res.fh == NULL) |
| 7990 | return -ENOMEM; |
| 7991 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7992 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7993 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7994 | &args.seq_args, &res.seq_res); |
| 7995 | nfs_free_fhandle(res.fh); |
| 7996 | if (status == NFS4_OK && |
| 7997 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7998 | status = -NFS4ERR_LEASE_MOVED; |
| 7999 | return status; |
| 8000 | } |
| 8001 | |
| 8002 | #endif /* CONFIG_NFS_V4_1 */ |
| 8003 | |
| 8004 | /** |
| 8005 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 8006 | * @inode: inode on FSID to check |
| 8007 | * @cred: credential to use for this operation |
| 8008 | * |
| 8009 | * Server indicates whether the FSID is present, moved, or not |
| 8010 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 8011 | * condition for this client ID. |
| 8012 | * |
| 8013 | * Returns NFS4_OK if the FSID is present on this server, |
| 8014 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 8015 | * NFS4ERR code if some error occurred on the server, or a |
| 8016 | * negative errno if a local failure occurred. |
| 8017 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8018 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8019 | { |
| 8020 | struct nfs_server *server = NFS_SERVER(inode); |
| 8021 | struct nfs_client *clp = server->nfs_client; |
| 8022 | const struct nfs4_mig_recovery_ops *ops = |
| 8023 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8024 | struct nfs4_exception exception = { |
| 8025 | .interruptible = true, |
| 8026 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8027 | int status; |
| 8028 | |
| 8029 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 8030 | (unsigned long long)server->fsid.major, |
| 8031 | (unsigned long long)server->fsid.minor, |
| 8032 | clp->cl_hostname); |
| 8033 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 8034 | |
| 8035 | do { |
| 8036 | status = ops->fsid_present(inode, cred); |
| 8037 | if (status != -NFS4ERR_DELAY) |
| 8038 | break; |
| 8039 | nfs4_handle_exception(server, status, &exception); |
| 8040 | } while (exception.retry); |
| 8041 | return status; |
| 8042 | } |
| 8043 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 8044 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8045 | * If 'use_integrity' is true and the state managment nfs_client |
| 8046 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 8047 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 8048 | * Considerations sections. Otherwise, just use the user cred with the |
| 8049 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 8050 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8051 | 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] | 8052 | { |
| 8053 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8054 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 8055 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8056 | struct nfs4_secinfo_arg args = { |
| 8057 | .dir_fh = NFS_FH(dir), |
| 8058 | .name = name, |
| 8059 | }; |
| 8060 | struct nfs4_secinfo_res res = { |
| 8061 | .flavors = flavors, |
| 8062 | }; |
| 8063 | struct rpc_message msg = { |
| 8064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 8065 | .rpc_argp = &args, |
| 8066 | .rpc_resp = &res, |
| 8067 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8068 | struct nfs4_call_sync_data data = { |
| 8069 | .seq_server = NFS_SERVER(dir), |
| 8070 | .seq_args = &args.seq_args, |
| 8071 | .seq_res = &res.seq_res, |
| 8072 | }; |
| 8073 | struct rpc_task_setup task_setup = { |
| 8074 | .rpc_client = clnt, |
| 8075 | .rpc_message = &msg, |
| 8076 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 8077 | .callback_data = &data, |
| 8078 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 8079 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8080 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8081 | |
| 8082 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8083 | clnt = clp->cl_rpcclient; |
| 8084 | task_setup.rpc_client = clnt; |
| 8085 | |
| 8086 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8087 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8088 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8089 | |
| 8090 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8091 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 8092 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 8093 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 8094 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8095 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8096 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8097 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8098 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8099 | return status; |
| 8100 | } |
| 8101 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 8102 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 8103 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8104 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 8105 | struct nfs4_exception exception = { |
| 8106 | .interruptible = true, |
| 8107 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8108 | int err; |
| 8109 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 8110 | err = -NFS4ERR_WRONGSEC; |
| 8111 | |
| 8112 | /* try to use integrity protection with machine cred */ |
| 8113 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 8114 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 8115 | |
| 8116 | /* |
| 8117 | * if unable to use integrity protection, or SECINFO with |
| 8118 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8119 | * disallowed by spec, but exists in deployed servers) use |
| 8120 | * the current filesystem's rpc_client and the user cred. |
| 8121 | */ |
| 8122 | if (err == -NFS4ERR_WRONGSEC) |
| 8123 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 8124 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 8125 | trace_nfs4_secinfo(dir, name, err); |
| 8126 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 8127 | &exception); |
| 8128 | } while (exception.retry); |
| 8129 | return err; |
| 8130 | } |
| 8131 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8132 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8133 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8134 | * Check the exchange flags returned by the server for invalid flags, having |
| 8135 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 8136 | * DS flags set. |
| 8137 | */ |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8138 | static int nfs4_check_cl_exchange_flags(u32 flags, u32 version) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8139 | { |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8140 | if (version >= 2 && (flags & ~EXCHGID4_2_FLAG_MASK_R)) |
| 8141 | goto out_inval; |
| 8142 | else if (version < 2 && (flags & ~EXCHGID4_FLAG_MASK_R)) |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8143 | goto out_inval; |
| 8144 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 8145 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 8146 | goto out_inval; |
| 8147 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 8148 | goto out_inval; |
| 8149 | return NFS_OK; |
| 8150 | out_inval: |
| 8151 | return -NFS4ERR_INVAL; |
| 8152 | } |
| 8153 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8154 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 8155 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 8156 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8157 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 8158 | if (a->server_scope_sz != b->server_scope_sz) |
| 8159 | return false; |
| 8160 | 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] | 8161 | } |
| 8162 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8163 | static void |
| 8164 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 8165 | { |
Trond Myklebust | 5c44154 | 2019-11-13 08:34:00 +0100 | [diff] [blame] | 8166 | 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] | 8167 | 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] | 8168 | struct nfs_client *clp = args->client; |
| 8169 | |
| 8170 | switch (task->tk_status) { |
| 8171 | case -NFS4ERR_BADSESSION: |
| 8172 | case -NFS4ERR_DEADSESSION: |
| 8173 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8174 | task->tk_status); |
| 8175 | } |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8176 | if (args->dir == NFS4_CDFC4_FORE_OR_BOTH && |
| 8177 | res->dir != NFS4_CDFS4_BOTH) { |
| 8178 | rpc_task_close_connection(task); |
| 8179 | if (args->retries++ < MAX_BIND_CONN_TO_SESSION_RETRIES) |
| 8180 | rpc_restart_call(task); |
| 8181 | } |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8182 | } |
| 8183 | |
| 8184 | 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] | 8185 | .rpc_call_done = nfs4_bind_one_conn_to_session_done, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8186 | }; |
| 8187 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 8188 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8189 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8190 | * |
| 8191 | * The 4.1 client currently uses the same TCP connection for the |
| 8192 | * fore and backchannel. |
| 8193 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8194 | static |
| 8195 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 8196 | struct rpc_xprt *xprt, |
| 8197 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8198 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8199 | { |
| 8200 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8201 | struct nfs41_bind_conn_to_session_args args = { |
| 8202 | .client = clp, |
| 8203 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
Olga Kornievskaia | dff5853 | 2020-04-24 17:45:50 -0400 | [diff] [blame] | 8204 | .retries = 0, |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8205 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8206 | struct nfs41_bind_conn_to_session_res res; |
| 8207 | struct rpc_message msg = { |
| 8208 | .rpc_proc = |
| 8209 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8210 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8211 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 8212 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8213 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8214 | struct rpc_task_setup task_setup_data = { |
| 8215 | .rpc_client = clnt, |
| 8216 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 8217 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8218 | .rpc_message = &msg, |
| 8219 | .flags = RPC_TASK_TIMEOUT, |
| 8220 | }; |
| 8221 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8222 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8223 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 8224 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 8225 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8226 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8227 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 8228 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 8229 | args.dir = NFS4_CDFC4_FORE; |
| 8230 | |
| 8231 | task = rpc_run_task(&task_setup_data); |
| 8232 | if (!IS_ERR(task)) { |
| 8233 | status = task->tk_status; |
| 8234 | rpc_put_task(task); |
| 8235 | } else |
| 8236 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8237 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8238 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8239 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8240 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 8241 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8242 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8243 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8244 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8245 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 8246 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8247 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8248 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 8249 | if (res.use_conn_in_rdma_mode != args.use_conn_in_rdma_mode) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8250 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 8251 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8252 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8253 | } |
| 8254 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 8255 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8256 | return status; |
| 8257 | } |
| 8258 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8259 | struct rpc_bind_conn_calldata { |
| 8260 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8261 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 8262 | }; |
| 8263 | |
| 8264 | static int |
| 8265 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 8266 | struct rpc_xprt *xprt, |
| 8267 | void *calldata) |
| 8268 | { |
| 8269 | struct rpc_bind_conn_calldata *p = calldata; |
| 8270 | |
| 8271 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 8272 | } |
| 8273 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8274 | 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] | 8275 | { |
| 8276 | struct rpc_bind_conn_calldata data = { |
| 8277 | .clp = clp, |
| 8278 | .cred = cred, |
| 8279 | }; |
| 8280 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 8281 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 8282 | } |
| 8283 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 8284 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8285 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 8286 | * 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] | 8287 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8288 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 8289 | .how = SP4_MACH_CRED, |
| 8290 | .enforce.u.words = { |
| 8291 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8292 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8293 | 1 << (OP_CREATE_SESSION - 32) | |
| 8294 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8295 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8296 | }, |
| 8297 | .allow.u.words = { |
| 8298 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8299 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8300 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8301 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8302 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8303 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8304 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8305 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8306 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 8307 | 1 << (OP_FREE_STATEID - 32) | |
| 8308 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8309 | } |
| 8310 | }; |
| 8311 | |
| 8312 | /* |
| 8313 | * Select the state protection mode for client `clp' given the server results |
| 8314 | * from exchange_id in `sp'. |
| 8315 | * |
| 8316 | * Returns 0 on success, negative errno otherwise. |
| 8317 | */ |
| 8318 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 8319 | struct nfs41_state_protection *sp) |
| 8320 | { |
| 8321 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 8322 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 8323 | 1 << (OP_EXCHANGE_ID - 32) | |
| 8324 | 1 << (OP_CREATE_SESSION - 32) | |
| 8325 | 1 << (OP_DESTROY_SESSION - 32) | |
| 8326 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 8327 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8328 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8329 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8330 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8331 | |
| 8332 | if (sp->how == SP4_MACH_CRED) { |
| 8333 | /* Print state protect result */ |
| 8334 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 8335 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 8336 | if (test_bit(i, sp->enforce.u.longs)) |
| 8337 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 8338 | if (test_bit(i, sp->allow.u.longs)) |
| 8339 | dfprintk(MOUNT, " allow op %d\n", i); |
| 8340 | } |
| 8341 | |
| 8342 | /* make sure nothing is on enforce list that isn't supported */ |
| 8343 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 8344 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 8345 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8346 | ret = -EINVAL; |
| 8347 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8348 | } |
| 8349 | } |
| 8350 | |
| 8351 | /* |
| 8352 | * Minimal mode - state operations are allowed to use machine |
| 8353 | * credential. Note this already happens by default, so the |
| 8354 | * client doesn't have to do anything more than the negotiation. |
| 8355 | * |
| 8356 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 8357 | * we're already using the machine cred for exchange_id |
| 8358 | * and will never use a different cred. |
| 8359 | */ |
| 8360 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8361 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8362 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8363 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8364 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8365 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8366 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8367 | } else { |
| 8368 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8369 | ret = -EINVAL; |
| 8370 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8371 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8372 | |
| 8373 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8374 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8375 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8376 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8377 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8378 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8379 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8380 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8381 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8382 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8383 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8384 | } |
| 8385 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8386 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8387 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8388 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8389 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8390 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8391 | |
| 8392 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8393 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8394 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8395 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8396 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8397 | |
| 8398 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8399 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8400 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8401 | } |
| 8402 | |
| 8403 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8404 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8405 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8406 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8407 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8408 | out: |
| 8409 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8410 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8411 | } |
| 8412 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8413 | struct nfs41_exchange_id_data { |
| 8414 | struct nfs41_exchange_id_res res; |
| 8415 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8416 | }; |
| 8417 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8418 | static void nfs4_exchange_id_release(void *data) |
| 8419 | { |
| 8420 | struct nfs41_exchange_id_data *cdata = |
| 8421 | (struct nfs41_exchange_id_data *)data; |
| 8422 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8423 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8424 | kfree(cdata->res.impl_id); |
| 8425 | kfree(cdata->res.server_scope); |
| 8426 | kfree(cdata->res.server_owner); |
| 8427 | kfree(cdata); |
| 8428 | } |
| 8429 | |
| 8430 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8431 | .rpc_release = nfs4_exchange_id_release, |
| 8432 | }; |
| 8433 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8434 | /* |
| 8435 | * _nfs4_proc_exchange_id() |
| 8436 | * |
| 8437 | * Wrapper for EXCHANGE_ID operation. |
| 8438 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8439 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8440 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8441 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8442 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8443 | struct rpc_message msg = { |
| 8444 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8445 | .rpc_cred = cred, |
| 8446 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8447 | struct rpc_task_setup task_setup_data = { |
| 8448 | .rpc_client = clp->cl_rpcclient, |
| 8449 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8450 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8451 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8452 | }; |
| 8453 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8454 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8455 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8456 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8457 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8458 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8459 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8460 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8461 | if (!calldata) |
| 8462 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8463 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8464 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8465 | |
| 8466 | status = nfs4_init_uniform_client_string(clp); |
| 8467 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8468 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8469 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8470 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8471 | GFP_NOFS); |
| 8472 | status = -ENOMEM; |
| 8473 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8474 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8475 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8476 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8477 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8478 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8479 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8480 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8481 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8482 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8483 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8484 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8485 | switch (sp4_how) { |
| 8486 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8487 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8488 | break; |
| 8489 | |
| 8490 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8491 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8492 | break; |
| 8493 | |
| 8494 | default: |
| 8495 | /* unsupported! */ |
| 8496 | WARN_ON_ONCE(1); |
| 8497 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8498 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8499 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8500 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8501 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8502 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8503 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8504 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8505 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8506 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8507 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8508 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8509 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8510 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8511 | #endif |
| 8512 | msg.rpc_argp = &calldata->args; |
| 8513 | msg.rpc_resp = &calldata->res; |
| 8514 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8515 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8516 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8517 | |
| 8518 | out_impl_id: |
| 8519 | kfree(calldata->res.impl_id); |
| 8520 | out_server_scope: |
| 8521 | kfree(calldata->res.server_scope); |
| 8522 | out_server_owner: |
| 8523 | kfree(calldata->res.server_owner); |
| 8524 | out_calldata: |
| 8525 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8526 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8527 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8528 | return ERR_PTR(status); |
| 8529 | } |
| 8530 | |
| 8531 | /* |
| 8532 | * _nfs4_proc_exchange_id() |
| 8533 | * |
| 8534 | * Wrapper for EXCHANGE_ID operation. |
| 8535 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8536 | 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] | 8537 | u32 sp4_how) |
| 8538 | { |
| 8539 | struct rpc_task *task; |
| 8540 | struct nfs41_exchange_id_args *argp; |
| 8541 | struct nfs41_exchange_id_res *resp; |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8542 | unsigned long now = jiffies; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8543 | int status; |
| 8544 | |
| 8545 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8546 | if (IS_ERR(task)) |
| 8547 | return PTR_ERR(task); |
| 8548 | |
| 8549 | argp = task->tk_msg.rpc_argp; |
| 8550 | resp = task->tk_msg.rpc_resp; |
| 8551 | status = task->tk_status; |
| 8552 | if (status != 0) |
| 8553 | goto out; |
| 8554 | |
Olga Kornievskaia | 8c39076 | 2020-10-16 09:25:45 -0400 | [diff] [blame] | 8555 | status = nfs4_check_cl_exchange_flags(resp->flags, |
| 8556 | clp->cl_mvops->minor_version); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8557 | if (status != 0) |
| 8558 | goto out; |
| 8559 | |
| 8560 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8561 | if (status != 0) |
| 8562 | goto out; |
| 8563 | |
Robert Milkowski | 7dc2993 | 2020-01-30 09:43:25 +0000 | [diff] [blame] | 8564 | do_renew_lease(clp, now); |
| 8565 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8566 | clp->cl_clientid = resp->clientid; |
| 8567 | clp->cl_exchange_flags = resp->flags; |
| 8568 | clp->cl_seqid = resp->seqid; |
| 8569 | /* Client ID is not confirmed */ |
| 8570 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8571 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8572 | &clp->cl_session->session_state); |
| 8573 | |
| 8574 | if (clp->cl_serverscope != NULL && |
| 8575 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8576 | resp->server_scope)) { |
| 8577 | dprintk("%s: server_scope mismatch detected\n", |
| 8578 | __func__); |
| 8579 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8580 | } |
| 8581 | |
| 8582 | swap(clp->cl_serverowner, resp->server_owner); |
| 8583 | swap(clp->cl_serverscope, resp->server_scope); |
| 8584 | swap(clp->cl_implid, resp->impl_id); |
| 8585 | |
| 8586 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8587 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8588 | sizeof(clp->cl_confirm.data)); |
| 8589 | out: |
| 8590 | trace_nfs4_exchange_id(clp, status); |
| 8591 | rpc_put_task(task); |
| 8592 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8593 | } |
| 8594 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8595 | /* |
| 8596 | * nfs4_proc_exchange_id() |
| 8597 | * |
| 8598 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8599 | * |
| 8600 | * Since the clientid has expired, all compounds using sessions |
| 8601 | * associated with the stale clientid will be returning |
| 8602 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8603 | * be in some phase of session reset. |
| 8604 | * |
| 8605 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8606 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8607 | 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] | 8608 | { |
| 8609 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8610 | int status; |
| 8611 | |
| 8612 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8613 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8614 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8615 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8616 | if (!status) |
| 8617 | return 0; |
| 8618 | } |
| 8619 | |
| 8620 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8621 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8622 | } |
| 8623 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8624 | /** |
| 8625 | * nfs4_test_session_trunk |
| 8626 | * |
| 8627 | * This is an add_xprt_test() test function called from |
| 8628 | * rpc_clnt_setup_test_and_add_xprt. |
| 8629 | * |
| 8630 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8631 | * and is dereferrenced in nfs4_exchange_id_release |
| 8632 | * |
| 8633 | * Upon success, add the new transport to the rpc_clnt |
| 8634 | * |
| 8635 | * @clnt: struct rpc_clnt to get new transport |
| 8636 | * @xprt: the rpc_xprt to test |
| 8637 | * @data: call data for _nfs4_proc_exchange_id. |
| 8638 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8639 | 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] | 8640 | void *data) |
| 8641 | { |
| 8642 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8643 | struct rpc_task *task; |
| 8644 | int status; |
| 8645 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8646 | u32 sp4_how; |
| 8647 | |
| 8648 | dprintk("--> %s try %s\n", __func__, |
| 8649 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8650 | |
| 8651 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8652 | |
| 8653 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8654 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8655 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8656 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8657 | |
| 8658 | status = task->tk_status; |
| 8659 | if (status == 0) |
| 8660 | status = nfs4_detect_session_trunking(adata->clp, |
| 8661 | task->tk_msg.rpc_resp, xprt); |
| 8662 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8663 | if (status == 0) |
| 8664 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8665 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8666 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8667 | } |
| 8668 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8669 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8670 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8671 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8672 | { |
| 8673 | struct rpc_message msg = { |
| 8674 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8675 | .rpc_argp = clp, |
| 8676 | .rpc_cred = cred, |
| 8677 | }; |
| 8678 | int status; |
| 8679 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8680 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8681 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8682 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8683 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8684 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8685 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8686 | return status; |
| 8687 | } |
| 8688 | |
| 8689 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8690 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8691 | { |
| 8692 | unsigned int loop; |
| 8693 | int ret; |
| 8694 | |
| 8695 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8696 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8697 | switch (ret) { |
| 8698 | case -NFS4ERR_DELAY: |
| 8699 | case -NFS4ERR_CLIENTID_BUSY: |
| 8700 | ssleep(1); |
| 8701 | break; |
| 8702 | default: |
| 8703 | return ret; |
| 8704 | } |
| 8705 | } |
| 8706 | return 0; |
| 8707 | } |
| 8708 | |
| 8709 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8710 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8711 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8712 | int ret = 0; |
| 8713 | |
| 8714 | if (clp->cl_mvops->minor_version < 1) |
| 8715 | goto out; |
| 8716 | if (clp->cl_exchange_flags == 0) |
| 8717 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8718 | if (clp->cl_preserve_clid) |
| 8719 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8720 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8721 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8722 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8723 | switch (ret) { |
| 8724 | case 0: |
| 8725 | case -NFS4ERR_STALE_CLIENTID: |
| 8726 | clp->cl_exchange_flags = 0; |
| 8727 | } |
| 8728 | out: |
| 8729 | return ret; |
| 8730 | } |
| 8731 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8732 | #endif /* CONFIG_NFS_V4_1 */ |
| 8733 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8734 | struct nfs4_get_lease_time_data { |
| 8735 | struct nfs4_get_lease_time_args *args; |
| 8736 | struct nfs4_get_lease_time_res *res; |
| 8737 | struct nfs_client *clp; |
| 8738 | }; |
| 8739 | |
| 8740 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8741 | void *calldata) |
| 8742 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8743 | struct nfs4_get_lease_time_data *data = |
| 8744 | (struct nfs4_get_lease_time_data *)calldata; |
| 8745 | |
| 8746 | dprintk("--> %s\n", __func__); |
| 8747 | /* just setup sequence, do not trigger session recovery |
| 8748 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8749 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8750 | &data->args->la_seq_args, |
| 8751 | &data->res->lr_seq_res, |
| 8752 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8753 | dprintk("<-- %s\n", __func__); |
| 8754 | } |
| 8755 | |
| 8756 | /* |
| 8757 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8758 | * from sequence operation or clientid errors. |
| 8759 | */ |
| 8760 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8761 | { |
| 8762 | struct nfs4_get_lease_time_data *data = |
| 8763 | (struct nfs4_get_lease_time_data *)calldata; |
| 8764 | |
| 8765 | dprintk("--> %s\n", __func__); |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8766 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8767 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8768 | switch (task->tk_status) { |
| 8769 | case -NFS4ERR_DELAY: |
| 8770 | case -NFS4ERR_GRACE: |
| 8771 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8772 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8773 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 8774 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8775 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8776 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8777 | return; |
| 8778 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8779 | dprintk("<-- %s\n", __func__); |
| 8780 | } |
| 8781 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8782 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8783 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8784 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8785 | }; |
| 8786 | |
| 8787 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8788 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8789 | struct nfs4_get_lease_time_args args; |
| 8790 | struct nfs4_get_lease_time_res res = { |
| 8791 | .lr_fsinfo = fsinfo, |
| 8792 | }; |
| 8793 | struct nfs4_get_lease_time_data data = { |
| 8794 | .args = &args, |
| 8795 | .res = &res, |
| 8796 | .clp = clp, |
| 8797 | }; |
| 8798 | struct rpc_message msg = { |
| 8799 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8800 | .rpc_argp = &args, |
| 8801 | .rpc_resp = &res, |
| 8802 | }; |
| 8803 | struct rpc_task_setup task_setup = { |
| 8804 | .rpc_client = clp->cl_rpcclient, |
| 8805 | .rpc_message = &msg, |
| 8806 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8807 | .callback_data = &data, |
| 8808 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8809 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8810 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8811 | 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] | 8812 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8813 | } |
| 8814 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8815 | #ifdef CONFIG_NFS_V4_1 |
| 8816 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8817 | /* |
| 8818 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8819 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8820 | * use them. |
| 8821 | * |
| 8822 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8823 | * always set csa_cachethis to FALSE because the current implementation |
| 8824 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8825 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8826 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8827 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8828 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8829 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8830 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8831 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8832 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8833 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8834 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8835 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8836 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8837 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8838 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8839 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8840 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8841 | |
| 8842 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8843 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8844 | __func__, |
| 8845 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8846 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8847 | |
| 8848 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8849 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8850 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8851 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8852 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8853 | 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] | 8854 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8855 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8856 | |
| 8857 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8858 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8859 | __func__, |
| 8860 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8861 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8862 | args->bc_attrs.max_reqs); |
| 8863 | } |
| 8864 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8865 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8866 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8867 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8868 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8869 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8870 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8871 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8872 | return -EINVAL; |
| 8873 | /* |
| 8874 | * Our requested max_ops is the minimum we need; we're not |
| 8875 | * prepared to break up compounds into smaller pieces than that. |
| 8876 | * So, no point even trying to continue if the server won't |
| 8877 | * cooperate: |
| 8878 | */ |
| 8879 | if (rcvd->max_ops < sent->max_ops) |
| 8880 | return -EINVAL; |
| 8881 | if (rcvd->max_reqs == 0) |
| 8882 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8883 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8884 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8885 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8886 | } |
| 8887 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8888 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8889 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8890 | { |
| 8891 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8892 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8893 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8894 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8895 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8896 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8897 | return -EINVAL; |
| 8898 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8899 | return -EINVAL; |
| 8900 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8901 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8902 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8903 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8904 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8905 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8906 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8907 | return 0; |
| 8908 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8909 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8910 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8911 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8912 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8913 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8914 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8915 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8916 | if (ret) |
| 8917 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8918 | return nfs4_verify_back_channel_attrs(args, res); |
| 8919 | } |
| 8920 | |
| 8921 | static void nfs4_update_session(struct nfs4_session *session, |
| 8922 | struct nfs41_create_session_res *res) |
| 8923 | { |
| 8924 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8925 | /* Mark client id and session as being confirmed */ |
| 8926 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8927 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8928 | session->flags = res->flags; |
| 8929 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8930 | if (res->flags & SESSION4_BACK_CHAN) |
| 8931 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8932 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8933 | } |
| 8934 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8935 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8936 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8937 | { |
| 8938 | struct nfs4_session *session = clp->cl_session; |
| 8939 | struct nfs41_create_session_args args = { |
| 8940 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8941 | .clientid = clp->cl_clientid, |
| 8942 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8943 | .cb_program = NFS4_CALLBACK, |
| 8944 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8945 | struct nfs41_create_session_res res; |
| 8946 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8947 | struct rpc_message msg = { |
| 8948 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8949 | .rpc_argp = &args, |
| 8950 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8951 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8952 | }; |
| 8953 | int status; |
| 8954 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8955 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8956 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8957 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8958 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8959 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8960 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8961 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8962 | switch (status) { |
| 8963 | case -NFS4ERR_STALE_CLIENTID: |
| 8964 | case -NFS4ERR_DELAY: |
| 8965 | case -ETIMEDOUT: |
| 8966 | case -EACCES: |
| 8967 | case -EAGAIN: |
| 8968 | goto out; |
zhengbin | 8b98a53 | 2019-12-19 18:34:47 +0800 | [diff] [blame] | 8969 | } |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8970 | |
| 8971 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8972 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8973 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8974 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8975 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8976 | if (status) |
| 8977 | goto out; |
| 8978 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8979 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8980 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8981 | return status; |
| 8982 | } |
| 8983 | |
| 8984 | /* |
| 8985 | * Issues a CREATE_SESSION operation to the server. |
| 8986 | * It is the responsibility of the caller to verify the session is |
| 8987 | * expired before calling this routine. |
| 8988 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8989 | 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] | 8990 | { |
| 8991 | int status; |
| 8992 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8993 | struct nfs4_session *session = clp->cl_session; |
| 8994 | |
| 8995 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8996 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8997 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8998 | if (status) |
| 8999 | goto out; |
| 9000 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 9001 | /* Init or reset the session slot tables */ |
| 9002 | status = nfs4_setup_session_slot_tables(session); |
| 9003 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9004 | if (status) |
| 9005 | goto out; |
| 9006 | |
| 9007 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 9008 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 9009 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 9010 | out: |
| 9011 | dprintk("<-- %s\n", __func__); |
| 9012 | return status; |
| 9013 | } |
| 9014 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9015 | /* |
| 9016 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 9017 | * The caller must serialize access to this routine. |
| 9018 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9019 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9020 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9021 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 9022 | struct rpc_message msg = { |
| 9023 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 9024 | .rpc_argp = session, |
| 9025 | .rpc_cred = cred, |
| 9026 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9027 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9028 | |
| 9029 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 9030 | |
| 9031 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 9032 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 9033 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9034 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9035 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 9036 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9037 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9038 | |
| 9039 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 9040 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 9041 | "Session has been destroyed regardless...\n", status); |
| 9042 | |
| 9043 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 9044 | return status; |
| 9045 | } |
| 9046 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 9047 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9048 | * Renew the cl_session lease. |
| 9049 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9050 | struct nfs4_sequence_data { |
| 9051 | struct nfs_client *clp; |
| 9052 | struct nfs4_sequence_args args; |
| 9053 | struct nfs4_sequence_res res; |
| 9054 | }; |
| 9055 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9056 | static void nfs41_sequence_release(void *data) |
| 9057 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9058 | struct nfs4_sequence_data *calldata = data; |
| 9059 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9060 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9061 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9062 | nfs4_schedule_state_renewal(clp); |
| 9063 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9064 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9065 | } |
| 9066 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9067 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9068 | { |
| 9069 | switch(task->tk_status) { |
| 9070 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9071 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 9072 | return -EAGAIN; |
| 9073 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9074 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9075 | } |
| 9076 | return 0; |
| 9077 | } |
| 9078 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9079 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9080 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9081 | struct nfs4_sequence_data *calldata = data; |
| 9082 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9083 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9084 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 9085 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9086 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9087 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9088 | if (task->tk_status < 0) { |
| 9089 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9090 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9091 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9092 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9093 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 9094 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9095 | return; |
| 9096 | } |
| 9097 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9098 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 9099 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9100 | dprintk("<-- %s\n", __func__); |
| 9101 | } |
| 9102 | |
| 9103 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 9104 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9105 | struct nfs4_sequence_data *calldata = data; |
| 9106 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9107 | struct nfs4_sequence_args *args; |
| 9108 | struct nfs4_sequence_res *res; |
| 9109 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9110 | args = task->tk_msg.rpc_argp; |
| 9111 | res = task->tk_msg.rpc_resp; |
| 9112 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9113 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9114 | } |
| 9115 | |
| 9116 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 9117 | .rpc_call_done = nfs41_sequence_call_done, |
| 9118 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 9119 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9120 | }; |
| 9121 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9122 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9123 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9124 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9125 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9126 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9127 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9128 | struct rpc_message msg = { |
| 9129 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 9130 | .rpc_cred = cred, |
| 9131 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9132 | struct rpc_task_setup task_setup_data = { |
| 9133 | .rpc_client = clp->cl_rpcclient, |
| 9134 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9135 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 9136 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9137 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9138 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9139 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9140 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 9141 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9142 | goto out_err; |
| 9143 | |
| 9144 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 9145 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9146 | if (calldata == NULL) |
| 9147 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9148 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9149 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9150 | msg.rpc_argp = &calldata->args; |
| 9151 | msg.rpc_resp = &calldata->res; |
| 9152 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9153 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9154 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9155 | ret = rpc_run_task(&task_setup_data); |
| 9156 | if (IS_ERR(ret)) |
| 9157 | goto out_err; |
| 9158 | return ret; |
| 9159 | out_put_clp: |
| 9160 | nfs_put_client(clp); |
| 9161 | out_err: |
| 9162 | nfs41_release_slot(slot); |
| 9163 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9164 | } |
| 9165 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9166 | 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] | 9167 | { |
| 9168 | struct rpc_task *task; |
| 9169 | int ret = 0; |
| 9170 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 9171 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 9172 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9173 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9174 | if (IS_ERR(task)) |
| 9175 | ret = PTR_ERR(task); |
| 9176 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 9177 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9178 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9179 | return ret; |
| 9180 | } |
| 9181 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9182 | 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] | 9183 | { |
| 9184 | struct rpc_task *task; |
| 9185 | int ret; |
| 9186 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 9187 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9188 | if (IS_ERR(task)) { |
| 9189 | ret = PTR_ERR(task); |
| 9190 | goto out; |
| 9191 | } |
| 9192 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 9193 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9194 | ret = task->tk_status; |
| 9195 | rpc_put_task(task); |
| 9196 | out: |
| 9197 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 9198 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 9199 | } |
| 9200 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9201 | struct nfs4_reclaim_complete_data { |
| 9202 | struct nfs_client *clp; |
| 9203 | struct nfs41_reclaim_complete_args arg; |
| 9204 | struct nfs41_reclaim_complete_res res; |
| 9205 | }; |
| 9206 | |
| 9207 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 9208 | { |
| 9209 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9210 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9211 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9212 | &calldata->arg.seq_args, |
| 9213 | &calldata->res.seq_res, |
| 9214 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9215 | } |
| 9216 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9217 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 9218 | { |
| 9219 | switch(task->tk_status) { |
| 9220 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 9221 | wake_up_all(&clp->cl_lock_waitq); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9222 | fallthrough; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9223 | case -NFS4ERR_COMPLETE_ALREADY: |
| 9224 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 9225 | break; |
| 9226 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9227 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9228 | fallthrough; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 9229 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9230 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9231 | case -NFS4ERR_BADSESSION: |
| 9232 | case -NFS4ERR_DEADSESSION: |
| 9233 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 9234 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9235 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 9236 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9237 | } |
| 9238 | return 0; |
| 9239 | } |
| 9240 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9241 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 9242 | { |
| 9243 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9244 | struct nfs_client *clp = calldata->clp; |
| 9245 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 9246 | |
| 9247 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 9248 | if (!nfs41_sequence_done(task, res)) |
| 9249 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9250 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 9251 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 9252 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 9253 | rpc_restart_call_prepare(task); |
| 9254 | return; |
| 9255 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9256 | dprintk("<-- %s\n", __func__); |
| 9257 | } |
| 9258 | |
| 9259 | static void nfs4_free_reclaim_complete_data(void *data) |
| 9260 | { |
| 9261 | struct nfs4_reclaim_complete_data *calldata = data; |
| 9262 | |
| 9263 | kfree(calldata); |
| 9264 | } |
| 9265 | |
| 9266 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 9267 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 9268 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 9269 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 9270 | }; |
| 9271 | |
| 9272 | /* |
| 9273 | * Issue a global reclaim complete. |
| 9274 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9275 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9276 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9277 | { |
| 9278 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9279 | struct rpc_message msg = { |
| 9280 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 9281 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9282 | }; |
| 9283 | struct rpc_task_setup task_setup_data = { |
| 9284 | .rpc_client = clp->cl_rpcclient, |
| 9285 | .rpc_message = &msg, |
| 9286 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9287 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9288 | }; |
| 9289 | int status = -ENOMEM; |
| 9290 | |
| 9291 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 9292 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9293 | if (calldata == NULL) |
| 9294 | goto out; |
| 9295 | calldata->clp = clp; |
| 9296 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9297 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9298 | 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] | 9299 | msg.rpc_argp = &calldata->arg; |
| 9300 | msg.rpc_resp = &calldata->res; |
| 9301 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 9302 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9303 | out: |
| 9304 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9305 | return status; |
| 9306 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9307 | |
| 9308 | static void |
| 9309 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 9310 | { |
| 9311 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 9312 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9313 | |
| 9314 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9315 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9316 | &lgp->res.seq_res, task); |
| 9317 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9318 | } |
| 9319 | |
| 9320 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 9321 | { |
| 9322 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9323 | |
| 9324 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9325 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9326 | dprintk("<-- %s\n", __func__); |
| 9327 | } |
| 9328 | |
| 9329 | static int |
| 9330 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 9331 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 9332 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9333 | struct inode *inode = lgp->args.inode; |
| 9334 | struct nfs_server *server = NFS_SERVER(inode); |
| 9335 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9336 | int nfs4err = task->tk_status; |
| 9337 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9338 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9339 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9340 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9341 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9342 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 9343 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9344 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9345 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9346 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9347 | |
| 9348 | /* |
| 9349 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 9350 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 9351 | * retry go inband. |
| 9352 | */ |
| 9353 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9354 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 9355 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9356 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9357 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 9358 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 9359 | */ |
| 9360 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9361 | status = -EOVERFLOW; |
| 9362 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9363 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9364 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9365 | * (or clients) writing to the same RAID stripe except when |
| 9366 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9367 | * |
| 9368 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9369 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9370 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9371 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9372 | if (lgp->args.minlength == 0) { |
| 9373 | status = -EOVERFLOW; |
| 9374 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9375 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9376 | status = -EBUSY; |
| 9377 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9378 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9379 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9380 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9381 | case -NFS4ERR_DELEG_REVOKED: |
| 9382 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9383 | case -NFS4ERR_EXPIRED: |
| 9384 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9385 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9386 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9387 | lo = NFS_I(inode)->layout; |
| 9388 | /* If the open stateid was bad, then recover it. */ |
| 9389 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9390 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9391 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9392 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9393 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9394 | break; |
| 9395 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9396 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9397 | /* |
| 9398 | * Mark the bad layout state as invalid, then retry |
| 9399 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9400 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9401 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9402 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9403 | pnfs_free_lseg_list(&head); |
| 9404 | status = -EAGAIN; |
| 9405 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9406 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9407 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9408 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9409 | if (!status) { |
| 9410 | if (exception->retry) |
| 9411 | status = -EAGAIN; |
| 9412 | else |
| 9413 | status = err; |
| 9414 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9415 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9416 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9417 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9418 | } |
| 9419 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9420 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9421 | { |
| 9422 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9423 | return nfs_page_array_len(0, max_resp_sz); |
| 9424 | } |
| 9425 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9426 | static void nfs4_layoutget_release(void *calldata) |
| 9427 | { |
| 9428 | struct nfs4_layoutget *lgp = calldata; |
| 9429 | |
| 9430 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9431 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9432 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9433 | dprintk("<-- %s\n", __func__); |
| 9434 | } |
| 9435 | |
| 9436 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9437 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9438 | .rpc_call_done = nfs4_layoutget_done, |
| 9439 | .rpc_release = nfs4_layoutget_release, |
| 9440 | }; |
| 9441 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9442 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9443 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9444 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9445 | struct inode *inode = lgp->args.inode; |
| 9446 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9447 | struct rpc_task *task; |
| 9448 | struct rpc_message msg = { |
| 9449 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9450 | .rpc_argp = &lgp->args, |
| 9451 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9452 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9453 | }; |
| 9454 | struct rpc_task_setup task_setup_data = { |
| 9455 | .rpc_client = server->client, |
| 9456 | .rpc_message = &msg, |
| 9457 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9458 | .callback_data = lgp, |
Trond Myklebust | 63ec2b6 | 2020-02-07 19:40:14 -0500 | [diff] [blame] | 9459 | .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9460 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9461 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9462 | struct nfs4_exception exception = { |
| 9463 | .inode = inode, |
| 9464 | .timeout = *timeout, |
| 9465 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9466 | int status = 0; |
| 9467 | |
| 9468 | dprintk("--> %s\n", __func__); |
| 9469 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 9470 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 9471 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 9472 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9473 | 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] | 9474 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9475 | task = rpc_run_task(&task_setup_data); |
Xiyu Yang | 6e47666 | 2020-04-25 21:04:40 +0800 | [diff] [blame] | 9476 | |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9477 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9478 | if (status != 0) |
| 9479 | goto out; |
| 9480 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9481 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9482 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9483 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9484 | } else if (lgp->res.layoutp->len == 0) { |
| 9485 | status = -EAGAIN; |
| 9486 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9487 | } else |
| 9488 | lseg = pnfs_layout_process(lgp); |
| 9489 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9490 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9491 | &lgp->args.range, |
| 9492 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9493 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9494 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9495 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9496 | rpc_put_task(task); |
| 9497 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9498 | if (status) |
| 9499 | return ERR_PTR(status); |
| 9500 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9501 | } |
| 9502 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9503 | static void |
| 9504 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9505 | { |
| 9506 | struct nfs4_layoutreturn *lrp = calldata; |
| 9507 | |
| 9508 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9509 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9510 | &lrp->args.seq_args, |
| 9511 | &lrp->res.seq_res, |
| 9512 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9513 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9514 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9515 | } |
| 9516 | |
| 9517 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9518 | { |
| 9519 | struct nfs4_layoutreturn *lrp = calldata; |
| 9520 | struct nfs_server *server; |
| 9521 | |
| 9522 | dprintk("--> %s\n", __func__); |
| 9523 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9524 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9525 | return; |
| 9526 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9527 | /* |
| 9528 | * Was there an RPC level error? Assume the call succeeded, |
| 9529 | * and that we need to release the layout |
| 9530 | */ |
| 9531 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9532 | lrp->res.lrs_present = 0; |
| 9533 | return; |
| 9534 | } |
| 9535 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9536 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9537 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9538 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9539 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9540 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9541 | lrp->args.inode)) |
| 9542 | goto out_restart; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9543 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9544 | default: |
| 9545 | task->tk_status = 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 9546 | fallthrough; |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9547 | case 0: |
| 9548 | break; |
| 9549 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9550 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9551 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9552 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9553 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9554 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9555 | return; |
| 9556 | out_restart: |
| 9557 | task->tk_status = 0; |
| 9558 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9559 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9560 | } |
| 9561 | |
| 9562 | static void nfs4_layoutreturn_release(void *calldata) |
| 9563 | { |
| 9564 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9565 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9566 | |
| 9567 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9568 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9569 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9570 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9571 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9572 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9573 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9574 | nfs_iput_and_deactive(lrp->inode); |
Trond Myklebust | 44ea8df | 2020-04-02 15:37:02 -0400 | [diff] [blame] | 9575 | put_cred(lrp->cred); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9576 | kfree(calldata); |
| 9577 | dprintk("<-- %s\n", __func__); |
| 9578 | } |
| 9579 | |
| 9580 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9581 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9582 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9583 | .rpc_release = nfs4_layoutreturn_release, |
| 9584 | }; |
| 9585 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9586 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9587 | { |
| 9588 | struct rpc_task *task; |
| 9589 | struct rpc_message msg = { |
| 9590 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9591 | .rpc_argp = &lrp->args, |
| 9592 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9593 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9594 | }; |
| 9595 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9596 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9597 | .rpc_message = &msg, |
| 9598 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9599 | .callback_data = lrp, |
| 9600 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9601 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9602 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9603 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9604 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9605 | &task_setup_data.rpc_client, &msg); |
| 9606 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9607 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9608 | if (!sync) { |
| 9609 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 9610 | if (!lrp->inode) { |
| 9611 | nfs4_layoutreturn_release(lrp); |
| 9612 | return -EAGAIN; |
| 9613 | } |
| 9614 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9615 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9616 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9617 | task = rpc_run_task(&task_setup_data); |
| 9618 | if (IS_ERR(task)) |
| 9619 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9620 | if (sync) |
| 9621 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9622 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9623 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9624 | rpc_put_task(task); |
| 9625 | return status; |
| 9626 | } |
| 9627 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9628 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9629 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9630 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9631 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9632 | { |
| 9633 | struct nfs4_getdeviceinfo_args args = { |
| 9634 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9635 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9636 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9637 | }; |
| 9638 | struct nfs4_getdeviceinfo_res res = { |
| 9639 | .pdev = pdev, |
| 9640 | }; |
| 9641 | struct rpc_message msg = { |
| 9642 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9643 | .rpc_argp = &args, |
| 9644 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9645 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9646 | }; |
| 9647 | int status; |
| 9648 | |
| 9649 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9650 | 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] | 9651 | if (res.notification & ~args.notify_types) |
| 9652 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9653 | if (res.notification != args.notify_types) |
| 9654 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9655 | |
Trond Myklebust | cac1d3a | 2020-12-16 16:31:26 -0500 | [diff] [blame] | 9656 | trace_nfs4_getdeviceinfo(server, &pdev->dev_id, status); |
| 9657 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9658 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9659 | |
| 9660 | return status; |
| 9661 | } |
| 9662 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9663 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9664 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9665 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9666 | { |
| 9667 | struct nfs4_exception exception = { }; |
| 9668 | int err; |
| 9669 | |
| 9670 | do { |
| 9671 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9672 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9673 | &exception); |
| 9674 | } while (exception.retry); |
| 9675 | return err; |
| 9676 | } |
| 9677 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9678 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9679 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9680 | { |
| 9681 | struct nfs4_layoutcommit_data *data = calldata; |
| 9682 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9683 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9684 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9685 | &data->args.seq_args, |
| 9686 | &data->res.seq_res, |
| 9687 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9688 | } |
| 9689 | |
| 9690 | static void |
| 9691 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9692 | { |
| 9693 | struct nfs4_layoutcommit_data *data = calldata; |
| 9694 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9695 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9696 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9697 | return; |
| 9698 | |
| 9699 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9700 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9701 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9702 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9703 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9704 | task->tk_status = 0; |
Gustavo A. R. Silva | ffb8171 | 2020-11-20 12:26:46 -0600 | [diff] [blame^] | 9705 | break; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9706 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9707 | break; |
| 9708 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9709 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9710 | rpc_restart_call_prepare(task); |
| 9711 | return; |
| 9712 | } |
| 9713 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9714 | } |
| 9715 | |
| 9716 | static void nfs4_layoutcommit_release(void *calldata) |
| 9717 | { |
| 9718 | struct nfs4_layoutcommit_data *data = calldata; |
| 9719 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9720 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9721 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9722 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9723 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9724 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9725 | kfree(data); |
| 9726 | } |
| 9727 | |
| 9728 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9729 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9730 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9731 | .rpc_release = nfs4_layoutcommit_release, |
| 9732 | }; |
| 9733 | |
| 9734 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9735 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9736 | { |
| 9737 | struct rpc_message msg = { |
| 9738 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9739 | .rpc_argp = &data->args, |
| 9740 | .rpc_resp = &data->res, |
| 9741 | .rpc_cred = data->cred, |
| 9742 | }; |
| 9743 | struct rpc_task_setup task_setup_data = { |
| 9744 | .task = &data->task, |
| 9745 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9746 | .rpc_message = &msg, |
| 9747 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9748 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9749 | }; |
| 9750 | struct rpc_task *task; |
| 9751 | int status = 0; |
| 9752 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9753 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9754 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9755 | data->args.lastbytewritten, |
| 9756 | data->args.inode->i_ino); |
| 9757 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9758 | if (!sync) { |
| 9759 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9760 | if (data->inode == NULL) { |
| 9761 | nfs4_layoutcommit_release(data); |
| 9762 | return -EAGAIN; |
| 9763 | } |
| 9764 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9765 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9766 | 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] | 9767 | task = rpc_run_task(&task_setup_data); |
| 9768 | if (IS_ERR(task)) |
| 9769 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9770 | if (sync) |
| 9771 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9772 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9773 | dprintk("%s: status %d\n", __func__, status); |
| 9774 | rpc_put_task(task); |
| 9775 | return status; |
| 9776 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9777 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9778 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9779 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9780 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9781 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9782 | static int |
| 9783 | _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] | 9784 | struct nfs_fsinfo *info, |
| 9785 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9786 | { |
| 9787 | struct nfs41_secinfo_no_name_args args = { |
| 9788 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9789 | }; |
| 9790 | struct nfs4_secinfo_res res = { |
| 9791 | .flavors = flavors, |
| 9792 | }; |
| 9793 | struct rpc_message msg = { |
| 9794 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9795 | .rpc_argp = &args, |
| 9796 | .rpc_resp = &res, |
| 9797 | }; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9798 | struct nfs4_call_sync_data data = { |
| 9799 | .seq_server = server, |
| 9800 | .seq_args = &args.seq_args, |
| 9801 | .seq_res = &res.seq_res, |
| 9802 | }; |
| 9803 | struct rpc_task_setup task_setup = { |
| 9804 | .rpc_client = server->client, |
| 9805 | .rpc_message = &msg, |
| 9806 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9807 | .callback_data = &data, |
| 9808 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9809 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9810 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9811 | int status; |
| 9812 | |
| 9813 | if (use_integrity) { |
Colin Ian King | 48bb6ec | 2020-06-10 00:22:57 +0100 | [diff] [blame] | 9814 | task_setup.rpc_client = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9815 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9816 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9817 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9818 | } |
| 9819 | |
| 9820 | dprintk("--> %s\n", __func__); |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9821 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9822 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9823 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9824 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9825 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9826 | |
| 9827 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9828 | } |
| 9829 | |
| 9830 | static int |
| 9831 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9832 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9833 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9834 | struct nfs4_exception exception = { |
| 9835 | .interruptible = true, |
| 9836 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9837 | int err; |
| 9838 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9839 | /* first try using integrity protection */ |
| 9840 | err = -NFS4ERR_WRONGSEC; |
| 9841 | |
| 9842 | /* try to use integrity protection with machine cred */ |
| 9843 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9844 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9845 | flavors, true); |
| 9846 | |
| 9847 | /* |
| 9848 | * if unable to use integrity protection, or SECINFO with |
| 9849 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9850 | * disallowed by spec, but exists in deployed servers) use |
| 9851 | * the current filesystem's rpc_client and the user cred. |
| 9852 | */ |
| 9853 | if (err == -NFS4ERR_WRONGSEC) |
| 9854 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9855 | flavors, false); |
| 9856 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9857 | switch (err) { |
| 9858 | case 0: |
| 9859 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9860 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9861 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9862 | default: |
| 9863 | err = nfs4_handle_exception(server, err, &exception); |
| 9864 | } |
| 9865 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9866 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9867 | return err; |
| 9868 | } |
| 9869 | |
| 9870 | static int |
| 9871 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9872 | struct nfs_fsinfo *info) |
| 9873 | { |
| 9874 | int err; |
| 9875 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9876 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9877 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9878 | struct nfs4_secinfo4 *secinfo; |
| 9879 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9880 | |
| 9881 | page = alloc_page(GFP_KERNEL); |
| 9882 | if (!page) { |
| 9883 | err = -ENOMEM; |
| 9884 | goto out; |
| 9885 | } |
| 9886 | |
| 9887 | flavors = page_address(page); |
| 9888 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9889 | |
| 9890 | /* |
| 9891 | * Fall back on "guess and check" method if |
| 9892 | * the server doesn't support SECINFO_NO_NAME |
| 9893 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9894 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9895 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9896 | goto out_freepage; |
| 9897 | } |
| 9898 | if (err) |
| 9899 | goto out_freepage; |
| 9900 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9901 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9902 | secinfo = &flavors->flavors[i]; |
| 9903 | |
| 9904 | switch (secinfo->flavor) { |
| 9905 | case RPC_AUTH_NULL: |
| 9906 | case RPC_AUTH_UNIX: |
| 9907 | case RPC_AUTH_GSS: |
| 9908 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9909 | &secinfo->flavor_info); |
| 9910 | break; |
| 9911 | default: |
| 9912 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9913 | break; |
| 9914 | } |
| 9915 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9916 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9917 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9918 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9919 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9920 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9921 | info, flavor); |
| 9922 | if (!err) |
| 9923 | break; |
| 9924 | } |
| 9925 | } |
| 9926 | |
| 9927 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9928 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9929 | |
| 9930 | out_freepage: |
| 9931 | put_page(page); |
| 9932 | if (err == -EACCES) |
| 9933 | return -EPERM; |
| 9934 | out: |
| 9935 | return err; |
| 9936 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9937 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9938 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9939 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9940 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9941 | { |
| 9942 | int status; |
| 9943 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9944 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9945 | }; |
| 9946 | struct nfs41_test_stateid_res res; |
| 9947 | struct rpc_message msg = { |
| 9948 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9949 | .rpc_argp = &args, |
| 9950 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9951 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9952 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9953 | struct rpc_clnt *rpc_client = server->client; |
| 9954 | |
| 9955 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9956 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9957 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9958 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9959 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9960 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9961 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9962 | if (status != NFS_OK) { |
| 9963 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9964 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9965 | } |
| 9966 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9967 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9968 | } |
| 9969 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9970 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9971 | int err, struct nfs4_exception *exception) |
| 9972 | { |
| 9973 | exception->retry = 0; |
| 9974 | switch(err) { |
| 9975 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9976 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9977 | nfs4_handle_exception(server, err, exception); |
| 9978 | break; |
| 9979 | case -NFS4ERR_BADSESSION: |
| 9980 | case -NFS4ERR_BADSLOT: |
| 9981 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9982 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9983 | case -NFS4ERR_DEADSESSION: |
| 9984 | nfs4_do_handle_exception(server, err, exception); |
| 9985 | } |
| 9986 | } |
| 9987 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9988 | /** |
| 9989 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9990 | * |
| 9991 | * @server: server / transport on which to perform the operation |
| 9992 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9993 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9994 | * |
| 9995 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9996 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9997 | * failed or the state ID is not currently valid. |
| 9998 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9999 | static int nfs41_test_stateid(struct nfs_server *server, |
| 10000 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10001 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10002 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 10003 | struct nfs4_exception exception = { |
| 10004 | .interruptible = true, |
| 10005 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10006 | int err; |
| 10007 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10008 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 10009 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 10010 | } while (exception.retry); |
| 10011 | return err; |
| 10012 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10013 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10014 | struct nfs_free_stateid_data { |
| 10015 | struct nfs_server *server; |
| 10016 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10017 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10018 | }; |
| 10019 | |
| 10020 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 10021 | { |
| 10022 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 10023 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10024 | &data->args.seq_args, |
| 10025 | &data->res.seq_res, |
| 10026 | task); |
| 10027 | } |
| 10028 | |
| 10029 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 10030 | { |
| 10031 | struct nfs_free_stateid_data *data = calldata; |
| 10032 | |
| 10033 | nfs41_sequence_done(task, &data->res.seq_res); |
| 10034 | |
| 10035 | switch (task->tk_status) { |
| 10036 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 10037 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10038 | rpc_restart_call_prepare(task); |
| 10039 | } |
| 10040 | } |
| 10041 | |
| 10042 | static void nfs41_free_stateid_release(void *calldata) |
| 10043 | { |
| 10044 | kfree(calldata); |
| 10045 | } |
| 10046 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10047 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10048 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 10049 | .rpc_call_done = nfs41_free_stateid_done, |
| 10050 | .rpc_release = nfs41_free_stateid_release, |
| 10051 | }; |
| 10052 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10053 | /** |
| 10054 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 10055 | * |
| 10056 | * @server: server / transport on which to perform the operation |
| 10057 | * @stateid: state ID to release |
| 10058 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 10059 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10060 | * |
| 10061 | * Note: this function is always asynchronous. |
| 10062 | */ |
| 10063 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10064 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10065 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10066 | bool privileged) |
| 10067 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10068 | struct rpc_message msg = { |
| 10069 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 10070 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10071 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10072 | struct rpc_task_setup task_setup = { |
| 10073 | .rpc_client = server->client, |
| 10074 | .rpc_message = &msg, |
| 10075 | .callback_ops = &nfs41_free_stateid_ops, |
| 10076 | .flags = RPC_TASK_ASYNC, |
| 10077 | }; |
| 10078 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10079 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10080 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 10081 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 10082 | &task_setup.rpc_client, &msg); |
| 10083 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 10084 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10085 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 10086 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 10087 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10088 | data->server = server; |
| 10089 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 10090 | |
| 10091 | task_setup.callback_data = data; |
| 10092 | |
| 10093 | msg.rpc_argp = &data->args; |
| 10094 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 10095 | 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] | 10096 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10097 | if (IS_ERR(task)) |
| 10098 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 10099 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10100 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 10101 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10102 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 10103 | static void |
| 10104 | 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] | 10105 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 10106 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10107 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 10108 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10109 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10110 | } |
| 10111 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10112 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 10113 | const nfs4_stateid *s2) |
| 10114 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 10115 | if (s1->type != s2->type) |
| 10116 | return false; |
| 10117 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10118 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10119 | return false; |
| 10120 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 10121 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10122 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10123 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 10124 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10125 | } |
| 10126 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 10127 | #endif /* CONFIG_NFS_V4_1 */ |
| 10128 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10129 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 10130 | const nfs4_stateid *s2) |
| 10131 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10132 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10133 | } |
| 10134 | |
| 10135 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10136 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10137 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10138 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10139 | .recover_open = nfs4_open_reclaim, |
| 10140 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10141 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10142 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10143 | }; |
| 10144 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10145 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10146 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10147 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 10148 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 10149 | .recover_open = nfs4_open_reclaim, |
| 10150 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10151 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 10152 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 10153 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10154 | }; |
| 10155 | #endif /* CONFIG_NFS_V4_1 */ |
| 10156 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10157 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 10158 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 10159 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 10160 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10161 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10162 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10163 | }; |
| 10164 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10165 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10166 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10167 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 10168 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 10169 | .recover_open = nfs41_open_expired, |
| 10170 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 10171 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 10172 | }; |
| 10173 | #endif /* CONFIG_NFS_V4_1 */ |
| 10174 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10175 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10176 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10177 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10178 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10179 | }; |
| 10180 | |
| 10181 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 10182 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10183 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 10184 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 10185 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 10186 | }; |
| 10187 | #endif |
| 10188 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10189 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10190 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10191 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10192 | }; |
| 10193 | |
| 10194 | #if defined(CONFIG_NFS_V4_1) |
| 10195 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 10196 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 10197 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10198 | }; |
| 10199 | #endif /* CONFIG_NFS_V4_1 */ |
| 10200 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10201 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 10202 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10203 | .init_caps = NFS_CAP_READDIRPLUS |
| 10204 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10205 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10206 | .init_client = nfs40_init_client, |
| 10207 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10208 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10209 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10210 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10211 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10212 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10213 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10214 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 10215 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 10216 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10217 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10218 | }; |
| 10219 | |
| 10220 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10221 | static struct nfs_seqid * |
| 10222 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 10223 | { |
| 10224 | return NULL; |
| 10225 | } |
| 10226 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10227 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 10228 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 10229 | .init_caps = NFS_CAP_READDIRPLUS |
| 10230 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 10231 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 10232 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10233 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 10234 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10235 | .init_client = nfs41_init_client, |
| 10236 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 10237 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 10238 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 10239 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10240 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10241 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10242 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10243 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 10244 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10245 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10246 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 10247 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10248 | }; |
| 10249 | #endif |
| 10250 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10251 | #if defined(CONFIG_NFS_V4_2) |
| 10252 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 10253 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10254 | .init_caps = NFS_CAP_READDIRPLUS |
| 10255 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10256 | | NFS_CAP_POSIX_LOCK |
| 10257 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 10258 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 10259 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 10260 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 10261 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 10262 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 10263 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 10264 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 10265 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 10266 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 10267 | | NFS_CAP_CLONE |
Anna Schumaker | c567552 | 2014-05-28 13:41:22 -0400 | [diff] [blame] | 10268 | | NFS_CAP_LAYOUTERROR |
| 10269 | | NFS_CAP_READ_PLUS, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 10270 | .init_client = nfs41_init_client, |
| 10271 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10272 | .match_stateid = nfs41_match_stateid, |
| 10273 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 10274 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 10275 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 10276 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 10277 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 10278 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10279 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 10280 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 10281 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 10282 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10283 | }; |
| 10284 | #endif |
| 10285 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10286 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 10287 | [0] = &nfs_v4_0_minor_ops, |
| 10288 | #if defined(CONFIG_NFS_V4_1) |
| 10289 | [1] = &nfs_v4_1_minor_ops, |
| 10290 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 10291 | #if defined(CONFIG_NFS_V4_2) |
| 10292 | [2] = &nfs_v4_2_minor_ops, |
| 10293 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 10294 | }; |
| 10295 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 10296 | 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] | 10297 | { |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10298 | ssize_t error, error2, error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10299 | |
| 10300 | error = generic_listxattr(dentry, list, size); |
| 10301 | if (error < 0) |
| 10302 | return error; |
| 10303 | if (list) { |
| 10304 | list += error; |
| 10305 | size -= error; |
| 10306 | } |
| 10307 | |
| 10308 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 10309 | if (error2 < 0) |
| 10310 | return error2; |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10311 | |
| 10312 | if (list) { |
| 10313 | list += error2; |
| 10314 | size -= error2; |
| 10315 | } |
| 10316 | |
| 10317 | error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); |
| 10318 | if (error3 < 0) |
| 10319 | return error3; |
| 10320 | |
| 10321 | return error + error2 + error3; |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10322 | } |
| 10323 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 10324 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10325 | .create = nfs_create, |
| 10326 | .lookup = nfs_lookup, |
| 10327 | .atomic_open = nfs_atomic_open, |
| 10328 | .link = nfs_link, |
| 10329 | .unlink = nfs_unlink, |
| 10330 | .symlink = nfs_symlink, |
| 10331 | .mkdir = nfs_mkdir, |
| 10332 | .rmdir = nfs_rmdir, |
| 10333 | .mknod = nfs_mknod, |
| 10334 | .rename = nfs_rename, |
| 10335 | .permission = nfs_permission, |
| 10336 | .getattr = nfs_getattr, |
| 10337 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10338 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 10339 | }; |
| 10340 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 10341 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10342 | .permission = nfs_permission, |
| 10343 | .getattr = nfs_getattr, |
| 10344 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 10345 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10346 | }; |
| 10347 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 10348 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10349 | .version = 4, /* protocol version */ |
| 10350 | .dentry_ops = &nfs4_dentry_operations, |
| 10351 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 10352 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 10353 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10354 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 10355 | .submount = nfs4_submount, |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 10356 | .try_get_tree = nfs4_try_get_tree, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10357 | .getattr = nfs4_proc_getattr, |
| 10358 | .setattr = nfs4_proc_setattr, |
| 10359 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 10360 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10361 | .access = nfs4_proc_access, |
| 10362 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10363 | .create = nfs4_proc_create, |
| 10364 | .remove = nfs4_proc_remove, |
| 10365 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 10366 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10367 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10368 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 10369 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 10370 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10371 | .link = nfs4_proc_link, |
| 10372 | .symlink = nfs4_proc_symlink, |
| 10373 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10374 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10375 | .readdir = nfs4_proc_readdir, |
| 10376 | .mknod = nfs4_proc_mknod, |
| 10377 | .statfs = nfs4_proc_statfs, |
| 10378 | .fsinfo = nfs4_proc_fsinfo, |
| 10379 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10380 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10381 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10382 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10383 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10384 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10385 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10386 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10387 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10388 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10389 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10390 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10391 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10392 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10393 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10394 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10395 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10396 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10397 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10398 | .create_server = nfs4_create_server, |
| 10399 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10400 | }; |
| 10401 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10402 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10403 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10404 | .list = nfs4_xattr_list_nfs4_acl, |
| 10405 | .get = nfs4_xattr_get_nfs4_acl, |
| 10406 | .set = nfs4_xattr_set_nfs4_acl, |
| 10407 | }; |
| 10408 | |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10409 | #ifdef CONFIG_NFS_V4_2 |
| 10410 | static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { |
| 10411 | .prefix = XATTR_USER_PREFIX, |
| 10412 | .get = nfs4_xattr_get_nfs4_user, |
| 10413 | .set = nfs4_xattr_set_nfs4_user, |
| 10414 | }; |
| 10415 | #endif |
| 10416 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10417 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10418 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10419 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10420 | &nfs4_xattr_nfs4_label_handler, |
| 10421 | #endif |
Frank van der Linden | 012a211 | 2020-06-23 22:39:03 +0000 | [diff] [blame] | 10422 | #ifdef CONFIG_NFS_V4_2 |
| 10423 | &nfs4_xattr_nfs4_user_handler, |
| 10424 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10425 | NULL |
| 10426 | }; |
| 10427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10428 | /* |
| 10429 | * Local variables: |
| 10430 | * c-basic-offset: 8 |
| 10431 | * End: |
| 10432 | */ |