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" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 74 | #define NFS4_BITMASK_SZ 3 |
| 75 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 76 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 78 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 79 | /* file attributes which can be mapped to nfs attributes */ |
| 80 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 81 | | ATTR_UID \ |
| 82 | | ATTR_GID \ |
| 83 | | ATTR_SIZE \ |
| 84 | | ATTR_ATIME \ |
| 85 | | ATTR_MTIME \ |
| 86 | | ATTR_CTIME \ |
| 87 | | ATTR_ATIME_SET \ |
| 88 | | ATTR_MTIME_SET) |
| 89 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 90 | struct nfs4_opendata; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 91 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | 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] | 93 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 94 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label, struct inode *inode); |
| 95 | 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] | 96 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 97 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 98 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 99 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 100 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 101 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 102 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 103 | struct nfs4_slot *slot, |
| 104 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 105 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 106 | const struct cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 107 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 108 | const struct cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 109 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 110 | |
| 111 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 112 | static inline struct nfs4_label * |
| 113 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 114 | struct iattr *sattr, struct nfs4_label *label) |
| 115 | { |
| 116 | int err; |
| 117 | |
| 118 | if (label == NULL) |
| 119 | return NULL; |
| 120 | |
| 121 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 122 | return NULL; |
| 123 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 124 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 125 | &dentry->d_name, (void **)&label->label, &label->len); |
| 126 | if (err == 0) |
| 127 | return label; |
| 128 | |
| 129 | return NULL; |
| 130 | } |
| 131 | static inline void |
| 132 | nfs4_label_release_security(struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | security_release_secctx(label->label, label->len); |
| 136 | } |
| 137 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 138 | { |
| 139 | if (label) |
| 140 | return server->attr_bitmask; |
| 141 | |
| 142 | return server->attr_bitmask_nl; |
| 143 | } |
| 144 | #else |
| 145 | static inline struct nfs4_label * |
| 146 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 147 | struct iattr *sattr, struct nfs4_label *l) |
| 148 | { return NULL; } |
| 149 | static inline void |
| 150 | nfs4_label_release_security(struct nfs4_label *label) |
| 151 | { return; } |
| 152 | static inline u32 * |
| 153 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 154 | { return server->attr_bitmask; } |
| 155 | #endif |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 158 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 160 | if (err >= -1000) |
| 161 | return err; |
| 162 | switch (err) { |
| 163 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 164 | case -NFS4ERR_LAYOUTTRYLATER: |
| 165 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 166 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 167 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 168 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 169 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 170 | case -NFS4ERR_BADOWNER: |
| 171 | case -NFS4ERR_BADNAME: |
| 172 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 173 | case -NFS4ERR_SHARE_DENIED: |
| 174 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 175 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 176 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 177 | case -NFS4ERR_FILE_OPEN: |
| 178 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 181 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 182 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 184 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | * This is our standard bitmap for GETATTR requests. |
| 189 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 190 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | FATTR4_WORD0_TYPE |
| 192 | | FATTR4_WORD0_CHANGE |
| 193 | | FATTR4_WORD0_SIZE |
| 194 | | FATTR4_WORD0_FSID |
| 195 | | FATTR4_WORD0_FILEID, |
| 196 | FATTR4_WORD1_MODE |
| 197 | | FATTR4_WORD1_NUMLINKS |
| 198 | | FATTR4_WORD1_OWNER |
| 199 | | FATTR4_WORD1_OWNER_GROUP |
| 200 | | FATTR4_WORD1_RAWDEV |
| 201 | | FATTR4_WORD1_SPACE_USED |
| 202 | | FATTR4_WORD1_TIME_ACCESS |
| 203 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 204 | | FATTR4_WORD1_TIME_MODIFY |
| 205 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 206 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 207 | FATTR4_WORD2_SECURITY_LABEL |
| 208 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 211 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 212 | FATTR4_WORD0_TYPE |
| 213 | | FATTR4_WORD0_CHANGE |
| 214 | | FATTR4_WORD0_SIZE |
| 215 | | FATTR4_WORD0_FSID |
| 216 | | FATTR4_WORD0_FILEID, |
| 217 | FATTR4_WORD1_MODE |
| 218 | | FATTR4_WORD1_NUMLINKS |
| 219 | | FATTR4_WORD1_OWNER |
| 220 | | FATTR4_WORD1_OWNER_GROUP |
| 221 | | FATTR4_WORD1_RAWDEV |
| 222 | | FATTR4_WORD1_SPACE_USED |
| 223 | | FATTR4_WORD1_TIME_ACCESS |
| 224 | | FATTR4_WORD1_TIME_METADATA |
| 225 | | FATTR4_WORD1_TIME_MODIFY, |
| 226 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 227 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 228 | | FATTR4_WORD2_SECURITY_LABEL |
| 229 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 230 | }; |
| 231 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 232 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 233 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 234 | | FATTR4_WORD0_FILEID, |
| 235 | }; |
| 236 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 237 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | FATTR4_WORD0_FILES_AVAIL |
| 239 | | FATTR4_WORD0_FILES_FREE |
| 240 | | FATTR4_WORD0_FILES_TOTAL, |
| 241 | FATTR4_WORD1_SPACE_AVAIL |
| 242 | | FATTR4_WORD1_SPACE_FREE |
| 243 | | FATTR4_WORD1_SPACE_TOTAL |
| 244 | }; |
| 245 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 246 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | FATTR4_WORD0_MAXLINK |
| 248 | | FATTR4_WORD0_MAXNAME, |
| 249 | 0 |
| 250 | }; |
| 251 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 252 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | | FATTR4_WORD0_MAXREAD |
| 254 | | FATTR4_WORD0_MAXWRITE |
| 255 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 256 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 257 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 258 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 259 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 262 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 263 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 264 | | FATTR4_WORD0_SIZE |
| 265 | | FATTR4_WORD0_FSID |
| 266 | | FATTR4_WORD0_FILEID |
| 267 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 268 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 269 | | FATTR4_WORD1_OWNER_GROUP |
| 270 | | FATTR4_WORD1_RAWDEV |
| 271 | | FATTR4_WORD1_SPACE_USED |
| 272 | | FATTR4_WORD1_TIME_ACCESS |
| 273 | | FATTR4_WORD1_TIME_METADATA |
| 274 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 275 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 276 | }; |
| 277 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 278 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
| 279 | struct inode *inode) |
| 280 | { |
| 281 | unsigned long cache_validity; |
| 282 | |
| 283 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 284 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 285 | return; |
| 286 | |
| 287 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 288 | if (!(cache_validity & NFS_INO_REVAL_FORCED)) |
| 289 | cache_validity &= ~(NFS_INO_INVALID_CHANGE |
| 290 | | NFS_INO_INVALID_SIZE); |
| 291 | |
| 292 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 293 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 294 | |
| 295 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 296 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
| 297 | } |
| 298 | |
| 299 | static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, |
| 300 | const __u32 *src, struct inode *inode) |
| 301 | { |
| 302 | nfs4_bitmap_copy_adjust(dst, src, inode); |
| 303 | } |
| 304 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 305 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | struct nfs4_readdir_arg *readdir) |
| 307 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 308 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 309 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 312 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | readdir->cookie = 0; |
| 318 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 319 | if (cookie == 2) |
| 320 | return; |
| 321 | |
| 322 | /* |
| 323 | * NFSv4 servers do not return entries for '.' and '..' |
| 324 | * Therefore, we fake these entries here. We let '.' |
| 325 | * have cookie 0 and '..' have cookie 1. Note that |
| 326 | * when talking to the server, we always send cookie 0 |
| 327 | * instead of 1 or 2. |
| 328 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 329 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | if (cookie == 0) { |
| 332 | *p++ = xdr_one; /* next */ |
| 333 | *p++ = xdr_zero; /* cookie, first word */ |
| 334 | *p++ = xdr_one; /* cookie, second word */ |
| 335 | *p++ = xdr_one; /* entry len */ |
| 336 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 337 | p++; |
| 338 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 339 | *p++ = htonl(attrs); /* bitmap */ |
| 340 | *p++ = htonl(12); /* attribute buffer length */ |
| 341 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 342 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | *p++ = xdr_one; /* next */ |
| 346 | *p++ = xdr_zero; /* cookie, first word */ |
| 347 | *p++ = xdr_two; /* cookie, second word */ |
| 348 | *p++ = xdr_two; /* entry len */ |
| 349 | memcpy(p, "..\0\0", 4); /* entry */ |
| 350 | p++; |
| 351 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 352 | *p++ = htonl(attrs); /* bitmap */ |
| 353 | *p++ = htonl(12); /* attribute buffer length */ |
| 354 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 355 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | readdir->pgbase = (char *)p - (char *)start; |
| 358 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 359 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 362 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 363 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 364 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 365 | { |
| 366 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 367 | |
| 368 | ops->test_and_free_expired(server, stateid, cred); |
| 369 | } |
| 370 | |
| 371 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 372 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 373 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 374 | { |
| 375 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 376 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 377 | } |
| 378 | |
| 379 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 380 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 381 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 382 | { |
| 383 | nfs4_stateid tmp; |
| 384 | |
| 385 | nfs4_stateid_copy(&tmp, stateid); |
| 386 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 387 | } |
| 388 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 389 | static long nfs4_update_delay(long *timeout) |
| 390 | { |
| 391 | long ret; |
| 392 | if (!timeout) |
| 393 | return NFS4_POLL_RETRY_MAX; |
| 394 | if (*timeout <= 0) |
| 395 | *timeout = NFS4_POLL_RETRY_MIN; |
| 396 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 397 | *timeout = NFS4_POLL_RETRY_MAX; |
| 398 | ret = *timeout; |
| 399 | *timeout <<= 1; |
| 400 | return ret; |
| 401 | } |
| 402 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 403 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 405 | might_sleep(); |
| 406 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 407 | freezable_schedule_timeout_killable_unsafe( |
| 408 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 409 | if (!__fatal_signal_pending(current)) |
| 410 | return 0; |
| 411 | return -EINTR; |
| 412 | } |
| 413 | |
| 414 | static int nfs4_delay_interruptible(long *timeout) |
| 415 | { |
| 416 | might_sleep(); |
| 417 | |
| 418 | freezable_schedule_timeout_interruptible(nfs4_update_delay(timeout)); |
| 419 | if (!signal_pending(current)) |
| 420 | return 0; |
| 421 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 422 | } |
| 423 | |
| 424 | static int nfs4_delay(long *timeout, bool interruptible) |
| 425 | { |
| 426 | if (interruptible) |
| 427 | return nfs4_delay_interruptible(timeout); |
| 428 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 429 | } |
| 430 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 431 | static const nfs4_stateid * |
| 432 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 433 | { |
| 434 | if (!stateid) |
| 435 | return NULL; |
| 436 | switch (stateid->type) { |
| 437 | case NFS4_OPEN_STATEID_TYPE: |
| 438 | case NFS4_LOCK_STATEID_TYPE: |
| 439 | case NFS4_DELEGATION_STATEID_TYPE: |
| 440 | return stateid; |
| 441 | default: |
| 442 | break; |
| 443 | } |
| 444 | return NULL; |
| 445 | } |
| 446 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 447 | /* This is the error handling routine for processes that are allowed |
| 448 | * to sleep. |
| 449 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 450 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 451 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 452 | { |
| 453 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 454 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 455 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 456 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 457 | int ret = errorcode; |
| 458 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 459 | exception->delay = 0; |
| 460 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 461 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 462 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 463 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 464 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 465 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 466 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 467 | switch(errorcode) { |
| 468 | case 0: |
| 469 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 470 | case -NFS4ERR_BADHANDLE: |
| 471 | case -ESTALE: |
| 472 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 473 | pnfs_destroy_layout(NFS_I(inode)); |
| 474 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 475 | case -NFS4ERR_DELEG_REVOKED: |
| 476 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 477 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 478 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 479 | if (inode != NULL && stateid != NULL) { |
| 480 | nfs_inode_find_state_and_recover(inode, |
| 481 | stateid); |
| 482 | goto wait_on_recovery; |
| 483 | } |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 484 | /* Fall through */ |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 485 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 486 | if (inode) { |
| 487 | int err; |
| 488 | |
| 489 | err = nfs_async_inode_return_delegation(inode, |
| 490 | stateid); |
| 491 | if (err == 0) |
| 492 | goto wait_on_recovery; |
| 493 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 494 | exception->retry = 1; |
| 495 | break; |
| 496 | } |
| 497 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 498 | if (state == NULL) |
| 499 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 500 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 501 | if (ret < 0) |
| 502 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 503 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 504 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 505 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 506 | nfs4_schedule_lease_recovery(clp); |
| 507 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 508 | case -NFS4ERR_MOVED: |
| 509 | ret = nfs4_schedule_migration_recovery(server); |
| 510 | if (ret < 0) |
| 511 | break; |
| 512 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 513 | case -NFS4ERR_LEASE_MOVED: |
| 514 | nfs4_schedule_lease_moved_recovery(clp); |
| 515 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 516 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 517 | case -NFS4ERR_BADSESSION: |
| 518 | case -NFS4ERR_BADSLOT: |
| 519 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 520 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 521 | case -NFS4ERR_DEADSESSION: |
| 522 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 523 | case -NFS4ERR_SEQ_MISORDERED: |
| 524 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 525 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 526 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 527 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 528 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 529 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 530 | if (exception->timeout > HZ) { |
| 531 | /* We have retried a decent amount, time to |
| 532 | * fail |
| 533 | */ |
| 534 | ret = -EBUSY; |
| 535 | break; |
| 536 | } |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 537 | /* Fall through */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 538 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 539 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 540 | /* Fall through */ |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 541 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 542 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 543 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 544 | exception->delay = 1; |
| 545 | return 0; |
| 546 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 547 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 548 | case -NFS4ERR_OLD_STATEID: |
| 549 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 550 | break; |
| 551 | case -NFS4ERR_BADOWNER: |
| 552 | /* The following works around a Linux server bug! */ |
| 553 | case -NFS4ERR_BADNAME: |
| 554 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 555 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 556 | exception->retry = 1; |
| 557 | printk(KERN_WARNING "NFS: v4 server %s " |
| 558 | "does not accept raw " |
| 559 | "uid/gids. " |
| 560 | "Reenabling the idmapper.\n", |
| 561 | server->nfs_client->cl_hostname); |
| 562 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 563 | } |
| 564 | /* We failed to handle the error */ |
| 565 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 566 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 567 | exception->recovering = 1; |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | /* This is the error handling routine for processes that are allowed |
| 572 | * to sleep. |
| 573 | */ |
| 574 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 575 | { |
| 576 | struct nfs_client *clp = server->nfs_client; |
| 577 | int ret; |
| 578 | |
| 579 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 580 | if (exception->delay) { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 581 | ret = nfs4_delay(&exception->timeout, |
| 582 | exception->interruptible); |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 583 | goto out_retry; |
| 584 | } |
| 585 | if (exception->recovering) { |
| 586 | ret = nfs4_wait_clnt_recover(clp); |
| 587 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 588 | return -EIO; |
| 589 | goto out_retry; |
| 590 | } |
| 591 | return ret; |
| 592 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 593 | if (ret == 0) |
| 594 | exception->retry = 1; |
| 595 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 596 | } |
| 597 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 598 | static int |
| 599 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 600 | int errorcode, struct nfs4_exception *exception) |
| 601 | { |
| 602 | struct nfs_client *clp = server->nfs_client; |
| 603 | int ret; |
| 604 | |
| 605 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 606 | if (exception->delay) { |
| 607 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 608 | goto out_retry; |
| 609 | } |
| 610 | if (exception->recovering) { |
| 611 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 612 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 613 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 614 | goto out_retry; |
| 615 | } |
| 616 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 617 | ret = -EIO; |
| 618 | return ret; |
| 619 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 620 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 621 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 622 | /* |
| 623 | * For NFS4ERR_MOVED, the client transport will need to |
| 624 | * be recomputed after migration recovery has completed. |
| 625 | */ |
| 626 | if (errorcode == -NFS4ERR_MOVED) |
| 627 | rpc_task_release_transport(task); |
| 628 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 629 | return ret; |
| 630 | } |
| 631 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 632 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 633 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 634 | struct nfs4_state *state, long *timeout) |
| 635 | { |
| 636 | struct nfs4_exception exception = { |
| 637 | .state = state, |
| 638 | }; |
| 639 | |
| 640 | if (task->tk_status >= 0) |
| 641 | return 0; |
| 642 | if (timeout) |
| 643 | exception.timeout = *timeout; |
| 644 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 645 | task->tk_status, |
| 646 | &exception); |
| 647 | if (exception.delay && timeout) |
| 648 | *timeout = exception.timeout; |
| 649 | if (exception.retry) |
| 650 | return -EAGAIN; |
| 651 | return 0; |
| 652 | } |
| 653 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 654 | /* |
| 655 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 656 | * or 'false' otherwise. |
| 657 | */ |
| 658 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 659 | { |
| 660 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 661 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 662 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 663 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 664 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | spin_lock(&clp->cl_lock); |
| 667 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 668 | clp->cl_last_renewal = timestamp; |
| 669 | spin_unlock(&clp->cl_lock); |
| 670 | } |
| 671 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 672 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 673 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 674 | struct nfs_client *clp = server->nfs_client; |
| 675 | |
| 676 | if (!nfs4_has_session(clp)) |
| 677 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 678 | } |
| 679 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 680 | struct nfs4_call_sync_data { |
| 681 | const struct nfs_server *seq_server; |
| 682 | struct nfs4_sequence_args *seq_args; |
| 683 | struct nfs4_sequence_res *seq_res; |
| 684 | }; |
| 685 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 686 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 687 | struct nfs4_sequence_res *res, int cache_reply, |
| 688 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 689 | { |
| 690 | args->sa_slot = NULL; |
| 691 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 692 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 693 | |
| 694 | res->sr_slot = NULL; |
| 695 | } |
| 696 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 697 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 698 | { |
| 699 | struct nfs4_slot *slot = res->sr_slot; |
| 700 | struct nfs4_slot_table *tbl; |
| 701 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 702 | tbl = slot->table; |
| 703 | spin_lock(&tbl->slot_tbl_lock); |
| 704 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 705 | nfs4_free_slot(tbl, slot); |
| 706 | spin_unlock(&tbl->slot_tbl_lock); |
| 707 | |
| 708 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | static int nfs40_sequence_done(struct rpc_task *task, |
| 712 | struct nfs4_sequence_res *res) |
| 713 | { |
| 714 | if (res->sr_slot != NULL) |
| 715 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 716 | return 1; |
| 717 | } |
| 718 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 719 | #if defined(CONFIG_NFS_V4_1) |
| 720 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 721 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 722 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 723 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 724 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 725 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 726 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 727 | if (!slot) |
| 728 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 729 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 730 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 731 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 732 | /* Bump the slot sequence number */ |
| 733 | if (slot->seq_done) |
| 734 | slot->seq_nr++; |
| 735 | slot->seq_done = 0; |
| 736 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 737 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 738 | /* Be nice to the server: try to ensure that the last transmitted |
| 739 | * value for highest_user_slotid <= target_highest_slotid |
| 740 | */ |
| 741 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 742 | send_new_highest_used_slotid = true; |
| 743 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 744 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 745 | send_new_highest_used_slotid = false; |
| 746 | goto out_unlock; |
| 747 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 748 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 749 | |
| 750 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 751 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 752 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 753 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 754 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 755 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 756 | if (waitqueue_active(&tbl->slot_waitq)) |
| 757 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 758 | } |
| 759 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 760 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 761 | { |
| 762 | nfs41_release_slot(res->sr_slot); |
| 763 | res->sr_slot = NULL; |
| 764 | } |
| 765 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 766 | static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
| 767 | u32 seqnr) |
| 768 | { |
| 769 | if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
| 770 | slot->seq_nr_highest_sent = seqnr; |
| 771 | } |
| 772 | static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, |
| 773 | u32 seqnr) |
| 774 | { |
| 775 | slot->seq_nr_highest_sent = seqnr; |
| 776 | slot->seq_nr_last_acked = seqnr; |
| 777 | } |
| 778 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 779 | static int nfs41_sequence_process(struct rpc_task *task, |
| 780 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 781 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 782 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 783 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 784 | struct nfs_client *clp; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 785 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 786 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 787 | if (slot == NULL) |
| 788 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 789 | /* don't increment the sequence number if the task wasn't sent */ |
Trond Myklebust | c71c46f | 2019-03-01 11:40:05 -0500 | [diff] [blame] | 790 | if (!RPC_WAS_SENT(task) || slot->seq_done) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 791 | goto out; |
| 792 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 793 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 794 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 795 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 796 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 797 | switch (res->sr_status) { |
| 798 | case 0: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 799 | /* Mark this sequence number as having been acked */ |
| 800 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 801 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 802 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 803 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 804 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 805 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 806 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 807 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 808 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 809 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 810 | case 1: |
| 811 | /* |
| 812 | * sr_status remains 1 if an RPC level error occurred. |
| 813 | * The server may or may not have processed the sequence |
| 814 | * operation.. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 815 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 816 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
| 817 | slot->seq_done = 1; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 818 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 819 | case -NFS4ERR_DELAY: |
| 820 | /* The server detected a resend of the RPC call and |
| 821 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 822 | * of RFC5661. |
| 823 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 824 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 825 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 826 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 827 | slot->seq_nr); |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 828 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 829 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 830 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 831 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 832 | /* |
| 833 | * The server thinks we tried to replay a request. |
| 834 | * Retry the call after bumping the sequence ID. |
| 835 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 836 | nfs4_slot_sequence_acked(slot, slot->seq_nr); |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 837 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 838 | case -NFS4ERR_BADSLOT: |
| 839 | /* |
| 840 | * The slot id we used was probably retired. Try again |
| 841 | * using a different slot id. |
| 842 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 843 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 844 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 845 | goto retry_nowait; |
| 846 | case -NFS4ERR_SEQ_MISORDERED: |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 847 | nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 848 | /* |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 849 | * Were one or more calls using this slot interrupted? |
| 850 | * If the server never received the request, then our |
| 851 | * transmitted slot sequence number may be too high. |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 852 | */ |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 853 | if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
| 854 | slot->seq_nr--; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 855 | goto retry_nowait; |
| 856 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 857 | /* |
| 858 | * RFC5661: |
| 859 | * A retry might be sent while the original request is |
| 860 | * still in progress on the replier. The replier SHOULD |
| 861 | * deal with the issue by returning NFS4ERR_DELAY as the |
| 862 | * reply to SEQUENCE or CB_SEQUENCE operation, but |
| 863 | * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
| 864 | * |
| 865 | * Restart the search after a delay. |
| 866 | */ |
| 867 | slot->seq_nr = slot->seq_nr_highest_sent; |
| 868 | goto out_retry; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 869 | default: |
| 870 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 871 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 872 | } |
| 873 | out: |
| 874 | /* The session may be reset by one of the error handlers. */ |
| 875 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 876 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 877 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 878 | session_recover: |
| 879 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 880 | goto retry_nowait; |
| 881 | retry_new_seq: |
| 882 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 883 | retry_nowait: |
| 884 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 885 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 886 | task->tk_status = 0; |
| 887 | ret = 0; |
| 888 | } |
| 889 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 890 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 891 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 892 | goto out; |
| 893 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 894 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 895 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 896 | |
| 897 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 898 | { |
| 899 | if (!nfs41_sequence_process(task, res)) |
| 900 | return 0; |
| 901 | if (res->sr_slot != NULL) |
| 902 | nfs41_sequence_free_slot(res); |
| 903 | return 1; |
| 904 | |
| 905 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 906 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 907 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 908 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 909 | { |
| 910 | if (res->sr_slot == NULL) |
| 911 | return 1; |
| 912 | if (res->sr_slot->table->session != NULL) |
| 913 | return nfs41_sequence_process(task, res); |
| 914 | return nfs40_sequence_done(task, res); |
| 915 | } |
| 916 | |
| 917 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 918 | { |
| 919 | if (res->sr_slot != NULL) { |
| 920 | if (res->sr_slot->table->session != NULL) |
| 921 | nfs41_sequence_free_slot(res); |
| 922 | else |
| 923 | nfs40_sequence_free_slot(res); |
| 924 | } |
| 925 | } |
| 926 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 927 | 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] | 928 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 929 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 930 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 931 | if (!res->sr_slot->table->session) |
| 932 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 933 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 934 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 935 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 936 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 937 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 938 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 939 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 940 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 941 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 942 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 943 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 944 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 945 | } |
| 946 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 947 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 948 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 949 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 950 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 951 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 954 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 955 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 956 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 957 | }; |
| 958 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 959 | #else /* !CONFIG_NFS_V4_1 */ |
| 960 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 961 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 962 | { |
| 963 | return nfs40_sequence_done(task, res); |
| 964 | } |
| 965 | |
| 966 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 967 | { |
| 968 | if (res->sr_slot != NULL) |
| 969 | nfs40_sequence_free_slot(res); |
| 970 | } |
| 971 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 972 | int nfs4_sequence_done(struct rpc_task *task, |
| 973 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 974 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 975 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 976 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 977 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 978 | |
| 979 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 980 | |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 981 | static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) |
| 982 | { |
| 983 | res->sr_timestamp = jiffies; |
| 984 | res->sr_status_flags = 0; |
| 985 | res->sr_status = 1; |
| 986 | } |
| 987 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 988 | static |
| 989 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 990 | struct nfs4_sequence_res *res, |
| 991 | struct nfs4_slot *slot) |
| 992 | { |
| 993 | if (!slot) |
| 994 | return; |
| 995 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 996 | args->sa_slot = slot; |
| 997 | |
| 998 | res->sr_slot = slot; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1002 | struct nfs4_sequence_args *args, |
| 1003 | struct nfs4_sequence_res *res, |
| 1004 | struct rpc_task *task) |
| 1005 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1006 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1007 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1008 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1009 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1010 | /* slot already allocated? */ |
| 1011 | if (res->sr_slot != NULL) |
| 1012 | goto out_start; |
| 1013 | |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1014 | if (session) |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1015 | tbl = &session->fc_slot_table; |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 1016 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1017 | spin_lock(&tbl->slot_tbl_lock); |
| 1018 | /* The state manager will wait until the slot table is empty */ |
| 1019 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 1020 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 1021 | |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1022 | slot = nfs4_alloc_slot(tbl); |
| 1023 | if (IS_ERR(slot)) { |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1024 | if (slot == ERR_PTR(-ENOMEM)) |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1025 | goto out_sleep_timeout; |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1026 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1027 | } |
Trond Myklebust | 3453d57 | 2018-06-20 17:53:34 -0400 | [diff] [blame] | 1028 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1029 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1030 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1031 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1032 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1033 | out_start: |
Trond Myklebust | c1dffe0 | 2019-03-01 12:13:34 -0500 | [diff] [blame] | 1034 | nfs41_sequence_res_init(res); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1035 | rpc_call_start(task); |
| 1036 | return 0; |
Trond Myklebust | 6b2e685 | 2019-04-07 13:58:49 -0400 | [diff] [blame] | 1037 | out_sleep_timeout: |
| 1038 | /* Try again in 1/4 second */ |
| 1039 | if (args->sa_privileged) |
| 1040 | rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
| 1041 | jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
| 1042 | else |
| 1043 | rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
| 1044 | NULL, jiffies + (HZ >> 2)); |
| 1045 | spin_unlock(&tbl->slot_tbl_lock); |
| 1046 | return -EAGAIN; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1047 | out_sleep: |
| 1048 | if (args->sa_privileged) |
| 1049 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
Trond Myklebust | 8357a9b | 2019-04-07 13:58:48 -0400 | [diff] [blame] | 1050 | RPC_PRIORITY_PRIVILEGED); |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1051 | else |
| 1052 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1053 | spin_unlock(&tbl->slot_tbl_lock); |
| 1054 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1055 | } |
| 1056 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1057 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1058 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1059 | { |
| 1060 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1061 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1062 | data->seq_args, data->seq_res, task); |
| 1063 | } |
| 1064 | |
| 1065 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1066 | { |
| 1067 | struct nfs4_call_sync_data *data = calldata; |
| 1068 | nfs4_sequence_done(task, data->seq_res); |
| 1069 | } |
| 1070 | |
| 1071 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1072 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1073 | .rpc_call_done = nfs40_call_sync_done, |
| 1074 | }; |
| 1075 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1076 | static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
| 1077 | { |
| 1078 | int ret; |
| 1079 | struct rpc_task *task; |
| 1080 | |
| 1081 | task = rpc_run_task(task_setup); |
| 1082 | if (IS_ERR(task)) |
| 1083 | return PTR_ERR(task); |
| 1084 | |
| 1085 | ret = task->tk_status; |
| 1086 | rpc_put_task(task); |
| 1087 | return ret; |
| 1088 | } |
| 1089 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1090 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1091 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1092 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1093 | struct nfs4_sequence_args *args, |
| 1094 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1095 | { |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1096 | struct nfs_client *clp = server->nfs_client; |
| 1097 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1098 | .seq_server = server, |
| 1099 | .seq_args = args, |
| 1100 | .seq_res = res, |
| 1101 | }; |
| 1102 | struct rpc_task_setup task_setup = { |
| 1103 | .rpc_client = clnt, |
| 1104 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1105 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1106 | .callback_data = &data |
| 1107 | }; |
| 1108 | |
Anna Schumaker | 48c0585 | 2019-08-14 15:27:00 -0400 | [diff] [blame] | 1109 | return nfs4_call_sync_custom(&task_setup); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1110 | } |
| 1111 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1112 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1113 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1114 | struct rpc_message *msg, |
| 1115 | struct nfs4_sequence_args *args, |
| 1116 | struct nfs4_sequence_res *res, |
| 1117 | int cache_reply) |
| 1118 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1119 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1120 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1123 | static void |
| 1124 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1125 | { |
| 1126 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1127 | inc_nlink(inode); |
| 1128 | } |
| 1129 | |
| 1130 | static void |
| 1131 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1132 | { |
| 1133 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1134 | drop_nlink(inode); |
| 1135 | } |
| 1136 | |
| 1137 | static void |
| 1138 | update_changeattr_locked(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1139 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | { |
| 1141 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1142 | |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1143 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1144 | | NFS_INO_INVALID_MTIME |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1145 | | NFS_INO_INVALID_DATA |
| 1146 | | cache_validity; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1147 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(dir)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1148 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1149 | nfsi->attrtimeo_timestamp = jiffies; |
| 1150 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | nfs_force_lookup_revalidate(dir); |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1152 | if (cinfo->before != inode_peek_iversion_raw(dir)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1153 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1154 | NFS_INO_INVALID_ACL; |
| 1155 | } |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1156 | inode_set_iversion_raw(dir, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1157 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1158 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1159 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1160 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | static void |
| 1164 | update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1165 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1166 | { |
| 1167 | spin_lock(&dir->i_lock); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1168 | update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | spin_unlock(&dir->i_lock); |
| 1170 | } |
| 1171 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1172 | struct nfs4_open_createattrs { |
| 1173 | struct nfs4_label *label; |
| 1174 | struct iattr *sattr; |
| 1175 | const __u32 verf[2]; |
| 1176 | }; |
| 1177 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1178 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1179 | int err, struct nfs4_exception *exception) |
| 1180 | { |
| 1181 | if (err != -EINVAL) |
| 1182 | return false; |
| 1183 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1184 | return false; |
| 1185 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1186 | exception->retry = 1; |
| 1187 | return true; |
| 1188 | } |
| 1189 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 1190 | static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
| 1191 | { |
| 1192 | return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
| 1193 | } |
| 1194 | |
| 1195 | static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
| 1196 | { |
| 1197 | fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
| 1198 | |
| 1199 | return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
| 1200 | } |
| 1201 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1202 | static u32 |
| 1203 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1204 | fmode_t fmode, int openflags) |
| 1205 | { |
| 1206 | u32 res = 0; |
| 1207 | |
| 1208 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1209 | case FMODE_READ: |
| 1210 | res = NFS4_SHARE_ACCESS_READ; |
| 1211 | break; |
| 1212 | case FMODE_WRITE: |
| 1213 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1214 | break; |
| 1215 | case FMODE_READ|FMODE_WRITE: |
| 1216 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1217 | } |
| 1218 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1219 | goto out; |
| 1220 | /* Want no delegation if we're using O_DIRECT */ |
| 1221 | if (openflags & O_DIRECT) |
| 1222 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1223 | out: |
| 1224 | return res; |
| 1225 | } |
| 1226 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1227 | static enum open_claim_type4 |
| 1228 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1229 | enum open_claim_type4 claim) |
| 1230 | { |
| 1231 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1232 | return claim; |
| 1233 | switch (claim) { |
| 1234 | default: |
| 1235 | return claim; |
| 1236 | case NFS4_OPEN_CLAIM_FH: |
| 1237 | return NFS4_OPEN_CLAIM_NULL; |
| 1238 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1239 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1240 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1241 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1242 | } |
| 1243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
| 1245 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1246 | { |
| 1247 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1248 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1249 | p->o_res.seqid = p->o_arg.seqid; |
| 1250 | p->c_res.seqid = p->c_arg.seqid; |
| 1251 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1252 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1253 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1254 | 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] | 1255 | } |
| 1256 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1257 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1258 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1259 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1260 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1261 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1262 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1263 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1264 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1265 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1266 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1267 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1268 | struct nfs4_opendata *p; |
| 1269 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1270 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1271 | if (p == NULL) |
| 1272 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1273 | |
| 1274 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1275 | if (IS_ERR(p->f_label)) |
| 1276 | goto err_free_p; |
| 1277 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1278 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1279 | if (IS_ERR(p->a_label)) |
| 1280 | goto err_free_f; |
| 1281 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1282 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1283 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1284 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1285 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1286 | nfs_sb_active(dentry->d_sb); |
| 1287 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1288 | p->dir = parent; |
| 1289 | p->owner = sp; |
| 1290 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1291 | p->o_arg.open_flags = flags; |
| 1292 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1293 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1294 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1295 | fmode, flags); |
Benjamin Coddington | 9091051 | 2019-06-07 06:37:30 -0400 | [diff] [blame] | 1296 | if (flags & O_CREAT) { |
| 1297 | p->o_arg.umask = current_umask(); |
| 1298 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
| 1299 | if (c->sattr != NULL && c->sattr->ia_valid != 0) { |
| 1300 | p->o_arg.u.attrs = &p->attrs; |
| 1301 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
| 1302 | |
| 1303 | memcpy(p->o_arg.u.verifier.data, c->verf, |
| 1304 | sizeof(p->o_arg.u.verifier.data)); |
| 1305 | } |
| 1306 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1307 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1308 | * will return permission denied for all bits until close */ |
| 1309 | if (!(flags & O_EXCL)) { |
| 1310 | /* ask server to check for all possible rights as results |
| 1311 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1312 | switch (p->o_arg.claim) { |
| 1313 | default: |
| 1314 | break; |
| 1315 | case NFS4_OPEN_CLAIM_NULL: |
| 1316 | case NFS4_OPEN_CLAIM_FH: |
| 1317 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1318 | NFS4_ACCESS_MODIFY | |
| 1319 | NFS4_ACCESS_EXTEND | |
| 1320 | NFS4_ACCESS_EXECUTE; |
| 1321 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1322 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1323 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1324 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1325 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1326 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1327 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1328 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1329 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1330 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1331 | case NFS4_OPEN_CLAIM_NULL: |
| 1332 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1333 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1334 | p->o_arg.fh = NFS_FH(dir); |
| 1335 | break; |
| 1336 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1337 | case NFS4_OPEN_CLAIM_FH: |
| 1338 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1339 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1340 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1341 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1342 | p->c_arg.fh = &p->o_res.fh; |
| 1343 | p->c_arg.stateid = &p->o_res.stateid; |
| 1344 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1345 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1346 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1347 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1348 | |
| 1349 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1350 | nfs4_label_free(p->a_label); |
| 1351 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1352 | nfs4_label_free(p->f_label); |
| 1353 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1354 | kfree(p); |
| 1355 | err: |
| 1356 | dput(parent); |
| 1357 | return NULL; |
| 1358 | } |
| 1359 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1360 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1361 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1362 | struct nfs4_opendata *p = container_of(kref, |
| 1363 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1364 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1365 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1366 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1367 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1368 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1369 | if (p->state != NULL) |
| 1370 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1371 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1372 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1373 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1374 | nfs4_label_free(p->f_label); |
| 1375 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1376 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1377 | dput(p->dentry); |
| 1378 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1379 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1380 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1381 | kfree(p); |
| 1382 | } |
| 1383 | |
| 1384 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1385 | { |
| 1386 | if (p != NULL) |
| 1387 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1390 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1391 | fmode_t fmode) |
| 1392 | { |
| 1393 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1394 | case FMODE_READ|FMODE_WRITE: |
| 1395 | return state->n_rdwr != 0; |
| 1396 | case FMODE_WRITE: |
| 1397 | return state->n_wronly != 0; |
| 1398 | case FMODE_READ: |
| 1399 | return state->n_rdonly != 0; |
| 1400 | } |
| 1401 | WARN_ON_ONCE(1); |
| 1402 | return false; |
| 1403 | } |
| 1404 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1405 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, |
| 1406 | int open_mode, enum open_claim_type4 claim) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1407 | { |
| 1408 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1409 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1410 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1411 | goto out; |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1412 | switch (claim) { |
| 1413 | case NFS4_OPEN_CLAIM_NULL: |
| 1414 | case NFS4_OPEN_CLAIM_FH: |
| 1415 | goto out; |
| 1416 | default: |
| 1417 | break; |
| 1418 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1419 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1420 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1421 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1422 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1423 | break; |
| 1424 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1425 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1426 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1427 | break; |
| 1428 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1429 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1430 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1431 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1432 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1433 | return ret; |
| 1434 | } |
| 1435 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1436 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1437 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1438 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1439 | if (delegation == NULL) |
| 1440 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1441 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1442 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1443 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1444 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1445 | switch (claim) { |
| 1446 | case NFS4_OPEN_CLAIM_NULL: |
| 1447 | case NFS4_OPEN_CLAIM_FH: |
| 1448 | break; |
| 1449 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1450 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1451 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 1452 | /* Fall through */ |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1453 | default: |
| 1454 | return 0; |
| 1455 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1456 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1457 | return 1; |
| 1458 | } |
| 1459 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1460 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1461 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1462 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1463 | case FMODE_WRITE: |
| 1464 | state->n_wronly++; |
| 1465 | break; |
| 1466 | case FMODE_READ: |
| 1467 | state->n_rdonly++; |
| 1468 | break; |
| 1469 | case FMODE_READ|FMODE_WRITE: |
| 1470 | state->n_rdwr++; |
| 1471 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1472 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1473 | } |
| 1474 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1475 | #ifdef CONFIG_NFS_V4_1 |
| 1476 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1477 | { |
| 1478 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1479 | return true; |
| 1480 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1481 | return true; |
| 1482 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1483 | return true; |
| 1484 | return false; |
| 1485 | } |
| 1486 | #endif /* CONFIG_NFS_V4_1 */ |
| 1487 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1488 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1489 | { |
| 1490 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1491 | wake_up_all(&state->waitq); |
| 1492 | } |
| 1493 | |
| 1494 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
| 1495 | const nfs4_stateid *stateid) |
| 1496 | { |
| 1497 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
| 1498 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
| 1499 | |
| 1500 | if (stateid_seqid == state_seqid + 1U || |
| 1501 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
| 1502 | nfs_state_log_update_open_stateid(state); |
| 1503 | else |
| 1504 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 1505 | } |
| 1506 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1507 | 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] | 1508 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1509 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1510 | bool need_recover = false; |
| 1511 | |
| 1512 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1513 | need_recover = true; |
| 1514 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1515 | need_recover = true; |
| 1516 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1517 | need_recover = true; |
| 1518 | if (need_recover) |
| 1519 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1520 | } |
| 1521 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1522 | /* |
| 1523 | * Check for whether or not the caller may update the open stateid |
| 1524 | * to the value passed in by stateid. |
| 1525 | * |
| 1526 | * Note: This function relies heavily on the server implementing |
| 1527 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1528 | * correctly. |
| 1529 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1530 | * are then incremented on every state transition. |
| 1531 | */ |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1532 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1533 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1534 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1535 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
| 1536 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1537 | if (stateid->seqid == cpu_to_be32(1)) |
| 1538 | nfs_state_log_update_open_stateid(state); |
| 1539 | else |
| 1540 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1541 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1542 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1543 | |
| 1544 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1545 | nfs_state_log_out_of_order_open_stateid(state, stateid); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1546 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1547 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1548 | return false; |
| 1549 | } |
| 1550 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1551 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1552 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1553 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1554 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1555 | if (state->n_wronly) |
| 1556 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1557 | if (state->n_rdonly) |
| 1558 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1559 | if (state->n_rdwr) |
| 1560 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1561 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1564 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1565 | nfs4_stateid *stateid, fmode_t fmode) |
| 1566 | { |
| 1567 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1568 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1569 | case FMODE_WRITE: |
| 1570 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1571 | break; |
| 1572 | case FMODE_READ: |
| 1573 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1574 | break; |
| 1575 | case 0: |
| 1576 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1577 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1578 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1579 | } |
| 1580 | if (stateid == NULL) |
| 1581 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1582 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1583 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1584 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1585 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1586 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1587 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1588 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1589 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1590 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1591 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1592 | out: |
| 1593 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1594 | } |
| 1595 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1596 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1597 | nfs4_stateid *arg_stateid, |
| 1598 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1599 | { |
| 1600 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1601 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1602 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1603 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1604 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1605 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1606 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1607 | } |
| 1608 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1609 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1610 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e9acf21 | 2019-01-22 14:01:16 -0500 | [diff] [blame] | 1611 | __must_hold(&state->owner->so_lock) |
| 1612 | __must_hold(&state->seqlock) |
| 1613 | __must_hold(RCU) |
| 1614 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1615 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1616 | DEFINE_WAIT(wait); |
| 1617 | int status = 0; |
| 1618 | for (;;) { |
| 1619 | |
| 1620 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1621 | return; |
| 1622 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1623 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1624 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1625 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1626 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1627 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1628 | break; |
| 1629 | |
| 1630 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1631 | /* |
| 1632 | * Ensure we process the state changes in the same order |
| 1633 | * in which the server processed them by delaying the |
| 1634 | * update of the stateid until we are in sequence. |
| 1635 | */ |
| 1636 | write_sequnlock(&state->seqlock); |
| 1637 | spin_unlock(&state->owner->so_lock); |
| 1638 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1639 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1640 | if (!signal_pending(current)) { |
| 1641 | if (schedule_timeout(5*HZ) == 0) |
| 1642 | status = -EAGAIN; |
| 1643 | else |
| 1644 | status = 0; |
| 1645 | } else |
| 1646 | status = -EINTR; |
| 1647 | finish_wait(&state->waitq, &wait); |
| 1648 | rcu_read_lock(); |
| 1649 | spin_lock(&state->owner->so_lock); |
| 1650 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1651 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1652 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1653 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1654 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1655 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1656 | nfs_test_and_clear_all_open_stateid(state); |
| 1657 | } |
| 1658 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1659 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1660 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1661 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1662 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1663 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1666 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1667 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1668 | fmode_t fmode, |
| 1669 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1671 | /* |
| 1672 | * Protect the call to nfs4_state_set_mode_locked and |
| 1673 | * serialise the stateid update |
| 1674 | */ |
| 1675 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1676 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1677 | switch (fmode) { |
| 1678 | case FMODE_READ: |
| 1679 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1680 | break; |
| 1681 | case FMODE_WRITE: |
| 1682 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1683 | break; |
| 1684 | case FMODE_READ|FMODE_WRITE: |
| 1685 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1686 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1687 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1688 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1689 | } |
| 1690 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 1691 | static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
| 1692 | { |
| 1693 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1694 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1695 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1696 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1697 | } |
| 1698 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1699 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1700 | const nfs4_stateid *deleg_stateid, |
| 1701 | fmode_t fmode) |
| 1702 | { |
| 1703 | /* |
| 1704 | * Protect the call to nfs4_state_set_mode_locked and |
| 1705 | * serialise the stateid update |
| 1706 | */ |
| 1707 | write_seqlock(&state->seqlock); |
| 1708 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1709 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1710 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 1713 | static void nfs_state_clear_delegation(struct nfs4_state *state) |
| 1714 | { |
| 1715 | write_seqlock(&state->seqlock); |
| 1716 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1717 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1718 | write_sequnlock(&state->seqlock); |
| 1719 | } |
| 1720 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1721 | static int update_open_stateid(struct nfs4_state *state, |
| 1722 | const nfs4_stateid *open_stateid, |
| 1723 | const nfs4_stateid *delegation, |
| 1724 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1725 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1726 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1727 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1728 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1729 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1730 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1731 | int ret = 0; |
| 1732 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1733 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1734 | |
| 1735 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1736 | spin_lock(&state->owner->so_lock); |
| 1737 | if (open_stateid != NULL) { |
| 1738 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1739 | ret = 1; |
| 1740 | } |
| 1741 | |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1742 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1743 | if (deleg_cur == NULL) |
| 1744 | goto no_delegation; |
| 1745 | |
| 1746 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1747 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1748 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1749 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1750 | goto no_delegation_unlock; |
| 1751 | |
| 1752 | if (delegation == NULL) |
| 1753 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1754 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1755 | goto no_delegation_unlock; |
| 1756 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1757 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1758 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1759 | ret = 1; |
| 1760 | no_delegation_unlock: |
| 1761 | spin_unlock(&deleg_cur->lock); |
| 1762 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1763 | if (ret) |
| 1764 | update_open_stateflags(state, fmode); |
| 1765 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1766 | rcu_read_unlock(); |
| 1767 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1768 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1769 | nfs4_schedule_state_manager(clp); |
| 1770 | if (freeme.type != 0) |
| 1771 | nfs4_test_and_free_stateid(server, &freeme, |
| 1772 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1773 | |
| 1774 | return ret; |
| 1775 | } |
| 1776 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1777 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1778 | const nfs4_stateid *stateid) |
| 1779 | { |
| 1780 | struct nfs4_state *state = lsp->ls_state; |
| 1781 | bool ret = false; |
| 1782 | |
| 1783 | spin_lock(&state->state_lock); |
| 1784 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1785 | goto out_noupdate; |
| 1786 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1787 | goto out_noupdate; |
| 1788 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1789 | ret = true; |
| 1790 | out_noupdate: |
| 1791 | spin_unlock(&state->state_lock); |
| 1792 | return ret; |
| 1793 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1794 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1795 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1796 | { |
| 1797 | struct nfs_delegation *delegation; |
| 1798 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1799 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1800 | rcu_read_lock(); |
| 1801 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1802 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1803 | rcu_read_unlock(); |
| 1804 | return; |
| 1805 | } |
| 1806 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1807 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1810 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1811 | { |
| 1812 | struct nfs4_state *state = opendata->state; |
| 1813 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1814 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1815 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1816 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1817 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1818 | nfs4_stateid stateid; |
| 1819 | int ret = -EAGAIN; |
| 1820 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1821 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1822 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 1823 | if (can_open_cached(state, fmode, open_mode, claim)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1824 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1825 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1826 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1827 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1828 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1829 | rcu_read_lock(); |
| 1830 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1831 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1832 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1833 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1834 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1835 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1836 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1837 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1838 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1839 | if (!opendata->is_recover) { |
| 1840 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1841 | if (ret != 0) |
| 1842 | goto out; |
| 1843 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1844 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1845 | |
| 1846 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1847 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1848 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1849 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1850 | out: |
| 1851 | return ERR_PTR(ret); |
| 1852 | out_return_state: |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1853 | refcount_inc(&state->count); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1854 | return state; |
| 1855 | } |
| 1856 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1857 | static void |
| 1858 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1859 | { |
| 1860 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1861 | struct nfs_delegation *delegation; |
| 1862 | int delegation_flags = 0; |
| 1863 | |
| 1864 | rcu_read_lock(); |
| 1865 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1866 | if (delegation) |
| 1867 | delegation_flags = delegation->flags; |
| 1868 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1869 | switch (data->o_arg.claim) { |
| 1870 | default: |
| 1871 | break; |
| 1872 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1873 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1874 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1875 | "returning a delegation for " |
| 1876 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1877 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1878 | return; |
| 1879 | } |
| 1880 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1881 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1882 | data->owner->so_cred, |
| 1883 | data->o_res.delegation_type, |
| 1884 | &data->o_res.delegation, |
| 1885 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1886 | else |
| 1887 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1888 | data->owner->so_cred, |
| 1889 | data->o_res.delegation_type, |
| 1890 | &data->o_res.delegation, |
| 1891 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1892 | |
| 1893 | if (data->o_res.do_recall) |
| 1894 | nfs_async_inode_return_delegation(state->inode, |
| 1895 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | /* |
| 1899 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1900 | * and update the nfs4_state. |
| 1901 | */ |
| 1902 | static struct nfs4_state * |
| 1903 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1904 | { |
| 1905 | struct inode *inode = data->state->inode; |
| 1906 | struct nfs4_state *state = data->state; |
| 1907 | int ret; |
| 1908 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1909 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1910 | if (data->rpc_status) |
| 1911 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1912 | /* cached opens have already been processed */ |
| 1913 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1914 | } |
| 1915 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1916 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1917 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1918 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1919 | |
| 1920 | if (data->o_res.delegation_type != 0) |
| 1921 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1922 | update: |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1923 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1924 | NULL, data->o_arg.fmode)) |
| 1925 | return ERR_PTR(-EAGAIN); |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1926 | refcount_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1927 | |
| 1928 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1929 | } |
| 1930 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1931 | static struct inode * |
| 1932 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1933 | { |
| 1934 | struct inode *inode; |
| 1935 | |
| 1936 | switch (data->o_arg.claim) { |
| 1937 | case NFS4_OPEN_CLAIM_NULL: |
| 1938 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1939 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1940 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1941 | return ERR_PTR(-EAGAIN); |
| 1942 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1943 | &data->f_attr, data->f_label); |
| 1944 | break; |
| 1945 | default: |
| 1946 | inode = d_inode(data->dentry); |
| 1947 | ihold(inode); |
| 1948 | nfs_refresh_inode(inode, &data->f_attr); |
| 1949 | } |
| 1950 | return inode; |
| 1951 | } |
| 1952 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1953 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1954 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1955 | { |
| 1956 | struct nfs4_state *state; |
| 1957 | struct inode *inode; |
| 1958 | |
| 1959 | inode = nfs4_opendata_get_inode(data); |
| 1960 | if (IS_ERR(inode)) |
| 1961 | return ERR_CAST(inode); |
| 1962 | if (data->state != NULL && data->state->inode == inode) { |
| 1963 | state = data->state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 1964 | refcount_inc(&state->count); |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1965 | } else |
| 1966 | state = nfs4_get_open_state(inode, data->owner); |
| 1967 | iput(inode); |
| 1968 | if (state == NULL) |
| 1969 | state = ERR_PTR(-ENOMEM); |
| 1970 | return state; |
| 1971 | } |
| 1972 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1973 | static struct nfs4_state * |
| 1974 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1975 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1976 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1977 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1978 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1979 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1980 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1981 | goto out; |
| 1982 | } |
| 1983 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1984 | state = nfs4_opendata_find_nfs4_state(data); |
| 1985 | if (IS_ERR(state)) |
| 1986 | goto out; |
| 1987 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1988 | if (data->o_res.delegation_type != 0) |
| 1989 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | e3c8dc7 | 2019-07-29 18:25:00 +0100 | [diff] [blame] | 1990 | if (!update_open_stateid(state, &data->o_res.stateid, |
| 1991 | NULL, data->o_arg.fmode)) { |
| 1992 | nfs4_put_open_state(state); |
| 1993 | state = ERR_PTR(-EAGAIN); |
| 1994 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1995 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1996 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1997 | return state; |
| 1998 | } |
| 1999 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2000 | static struct nfs4_state * |
| 2001 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 2002 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2003 | struct nfs4_state *ret; |
| 2004 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2005 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2006 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 2007 | else |
| 2008 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 2009 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 2010 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2011 | } |
| 2012 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2013 | static struct nfs_open_context * |
| 2014 | 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] | 2015 | { |
| 2016 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 2017 | struct nfs_open_context *ctx; |
| 2018 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2019 | rcu_read_lock(); |
| 2020 | list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2021 | if (ctx->state != state) |
| 2022 | continue; |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2023 | if ((ctx->mode & mode) != mode) |
| 2024 | continue; |
| 2025 | if (!get_nfs_open_context(ctx)) |
| 2026 | continue; |
| 2027 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2028 | return ctx; |
| 2029 | } |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2030 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2031 | return ERR_PTR(-ENOENT); |
| 2032 | } |
| 2033 | |
Trond Myklebust | 0de4397 | 2018-09-02 15:57:01 -0400 | [diff] [blame] | 2034 | static struct nfs_open_context * |
| 2035 | nfs4_state_find_open_context(struct nfs4_state *state) |
| 2036 | { |
| 2037 | struct nfs_open_context *ctx; |
| 2038 | |
| 2039 | ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
| 2040 | if (!IS_ERR(ctx)) |
| 2041 | return ctx; |
| 2042 | ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
| 2043 | if (!IS_ERR(ctx)) |
| 2044 | return ctx; |
| 2045 | return nfs4_state_find_open_context_mode(state, FMODE_READ); |
| 2046 | } |
| 2047 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2048 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 2049 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2050 | { |
| 2051 | struct nfs4_opendata *opendata; |
| 2052 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2053 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2054 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2055 | if (opendata == NULL) |
| 2056 | return ERR_PTR(-ENOMEM); |
| 2057 | opendata->state = state; |
Trond Myklebust | ace9fad | 2018-09-02 19:19:07 -0400 | [diff] [blame] | 2058 | refcount_inc(&state->count); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2059 | return opendata; |
| 2060 | } |
| 2061 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2062 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 2063 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2064 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2065 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2066 | int ret; |
| 2067 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2068 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 2069 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2070 | opendata->o_arg.open_flags = 0; |
| 2071 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 2072 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 2073 | NFS_SB(opendata->dentry->d_sb), |
| 2074 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2075 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 2076 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 2077 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2078 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2079 | if (ret != 0) |
| 2080 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2081 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2082 | if (IS_ERR(newstate)) |
| 2083 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2084 | if (newstate != opendata->state) |
| 2085 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2086 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2087 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 2091 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2092 | int ret; |
| 2093 | |
| 2094 | /* memory barrier prior to reading state->n_* */ |
| 2095 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2096 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2097 | if (ret != 0) |
| 2098 | return ret; |
| 2099 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2100 | if (ret != 0) |
| 2101 | return ret; |
| 2102 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2103 | if (ret != 0) |
| 2104 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2105 | /* |
| 2106 | * We may have performed cached opens for all three recoveries. |
| 2107 | * Check if we need to update the current stateid. |
| 2108 | */ |
| 2109 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2110 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2111 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2112 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2113 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2114 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2115 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2116 | return 0; |
| 2117 | } |
| 2118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | /* |
| 2120 | * OPEN_RECLAIM: |
| 2121 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2123 | 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] | 2124 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2125 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2126 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2127 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | int status; |
| 2129 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2130 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2131 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2132 | if (IS_ERR(opendata)) |
| 2133 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2134 | rcu_read_lock(); |
| 2135 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2136 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2137 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2138 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2139 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2140 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2141 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | return status; |
| 2143 | } |
| 2144 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2145 | 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] | 2146 | { |
| 2147 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2148 | struct nfs4_exception exception = { }; |
| 2149 | int err; |
| 2150 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2151 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2152 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2153 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2154 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2155 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2156 | break; |
| 2157 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | } while (exception.retry); |
| 2159 | return err; |
| 2160 | } |
| 2161 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2162 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2163 | { |
| 2164 | struct nfs_open_context *ctx; |
| 2165 | int ret; |
| 2166 | |
| 2167 | ctx = nfs4_state_find_open_context(state); |
| 2168 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2169 | return -EAGAIN; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2170 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2171 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2172 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2173 | put_nfs_open_context(ctx); |
| 2174 | return ret; |
| 2175 | } |
| 2176 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2177 | 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] | 2178 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2179 | switch (err) { |
| 2180 | default: |
| 2181 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2182 | "%d.\n", __func__, err); |
| 2183 | case 0: |
| 2184 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2185 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2186 | case -ESTALE: |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2187 | case -ETIMEDOUT: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2188 | break; |
| 2189 | case -NFS4ERR_BADSESSION: |
| 2190 | case -NFS4ERR_BADSLOT: |
| 2191 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2192 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2193 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2194 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 2195 | return -EAGAIN; |
| 2196 | case -NFS4ERR_STALE_CLIENTID: |
| 2197 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2198 | /* Don't recall a delegation if it was lost */ |
| 2199 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2200 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2201 | case -NFS4ERR_MOVED: |
| 2202 | nfs4_schedule_migration_recovery(server); |
| 2203 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2204 | case -NFS4ERR_LEASE_MOVED: |
| 2205 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2206 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2207 | case -NFS4ERR_DELEG_REVOKED: |
| 2208 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2209 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2210 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2211 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2212 | nfs_inode_find_state_and_recover(state->inode, |
| 2213 | stateid); |
| 2214 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2215 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2216 | case -NFS4ERR_DELAY: |
| 2217 | case -NFS4ERR_GRACE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2218 | ssleep(1); |
| 2219 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2220 | case -ENOMEM: |
| 2221 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2222 | if (fl) { |
| 2223 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2224 | if (lsp) |
| 2225 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2226 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2227 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | return err; |
| 2230 | } |
| 2231 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2232 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2233 | struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2234 | { |
| 2235 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2236 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2237 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2238 | |
| 2239 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2240 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2241 | if (IS_ERR(opendata)) |
| 2242 | return PTR_ERR(opendata); |
| 2243 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2244 | if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2245 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2246 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2247 | goto out; |
| 2248 | } |
| 2249 | if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2250 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2251 | if (err) |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2252 | goto out; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2253 | } |
Trond Myklebust | 5eb8d18 | 2019-07-19 14:08:37 -0400 | [diff] [blame] | 2254 | if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { |
| 2255 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2256 | if (err) |
| 2257 | goto out; |
| 2258 | } |
| 2259 | nfs_state_clear_delegation(state); |
| 2260 | out: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2261 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2262 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2263 | } |
| 2264 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2265 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2266 | { |
| 2267 | struct nfs4_opendata *data = calldata; |
| 2268 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2269 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2270 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2271 | } |
| 2272 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2273 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2274 | { |
| 2275 | struct nfs4_opendata *data = calldata; |
| 2276 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2277 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2278 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2279 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2280 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2281 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2282 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2283 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2284 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2285 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | static void nfs4_open_confirm_release(void *calldata) |
| 2289 | { |
| 2290 | struct nfs4_opendata *data = calldata; |
| 2291 | struct nfs4_state *state = NULL; |
| 2292 | |
| 2293 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2294 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2295 | goto out_free; |
| 2296 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2297 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2298 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2299 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2300 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2301 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2302 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2303 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2307 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2308 | .rpc_call_done = nfs4_open_confirm_done, |
| 2309 | .rpc_release = nfs4_open_confirm_release, |
| 2310 | }; |
| 2311 | |
| 2312 | /* |
| 2313 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2314 | */ |
| 2315 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2316 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2317 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2318 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2319 | struct rpc_message msg = { |
| 2320 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2321 | .rpc_argp = &data->c_arg, |
| 2322 | .rpc_resp = &data->c_res, |
| 2323 | .rpc_cred = data->owner->so_cred, |
| 2324 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2325 | struct rpc_task_setup task_setup_data = { |
| 2326 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2327 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2328 | .callback_ops = &nfs4_open_confirm_ops, |
| 2329 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2330 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2331 | .flags = RPC_TASK_ASYNC, |
| 2332 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | int status; |
| 2334 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2335 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2336 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2337 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2338 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2339 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2340 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2341 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2342 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2343 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2344 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2345 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2346 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2347 | smp_wmb(); |
| 2348 | } else |
| 2349 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2350 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | return status; |
| 2352 | } |
| 2353 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2354 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2356 | struct nfs4_opendata *data = calldata; |
| 2357 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2358 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2359 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2360 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2361 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2362 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2363 | /* |
| 2364 | * Check if we still need to send an OPEN call, or if we can use |
| 2365 | * a delegation instead. |
| 2366 | */ |
| 2367 | if (data->state != NULL) { |
| 2368 | struct nfs_delegation *delegation; |
| 2369 | |
Trond Myklebust | be189f7 | 2018-09-27 17:12:33 -0400 | [diff] [blame] | 2370 | if (can_open_cached(data->state, data->o_arg.fmode, |
| 2371 | data->o_arg.open_flags, claim)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2372 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2373 | rcu_read_lock(); |
| 2374 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2375 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2376 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2377 | rcu_read_unlock(); |
| 2378 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2379 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2380 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2381 | switch (claim) { |
| 2382 | default: |
| 2383 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2384 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2385 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2386 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2387 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 2388 | /* Fall through */ |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2389 | case NFS4_OPEN_CLAIM_FH: |
| 2390 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2391 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2392 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2393 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2394 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2395 | &data->o_res.seq_res, |
| 2396 | task) != 0) |
| 2397 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2398 | |
| 2399 | /* Set the create mode (note dependency on the session type) */ |
| 2400 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2401 | if (data->o_arg.open_flags & O_EXCL) { |
| 2402 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2403 | if (nfs4_has_persistent_session(clp)) |
| 2404 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2405 | else if (clp->cl_mvops->minor_version > 0) |
| 2406 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2407 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2408 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2409 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2410 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2411 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2412 | out_no_action: |
| 2413 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2414 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2415 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2416 | } |
| 2417 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2418 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2419 | { |
| 2420 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2422 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2423 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2424 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2425 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2426 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2427 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2428 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2429 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2430 | case S_IFREG: |
| 2431 | break; |
| 2432 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2433 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2434 | break; |
| 2435 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2436 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2437 | break; |
| 2438 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2439 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2440 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2441 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2442 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2443 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2444 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2445 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2446 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2447 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2448 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2449 | static void nfs4_open_release(void *calldata) |
| 2450 | { |
| 2451 | struct nfs4_opendata *data = calldata; |
| 2452 | struct nfs4_state *state = NULL; |
| 2453 | |
| 2454 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2455 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2456 | goto out_free; |
| 2457 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2458 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2459 | goto out_free; |
| 2460 | /* In case we need an open_confirm, no cleanup! */ |
| 2461 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2462 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2463 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2464 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2465 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2466 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2467 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2471 | .rpc_call_prepare = nfs4_open_prepare, |
| 2472 | .rpc_call_done = nfs4_open_done, |
| 2473 | .rpc_release = nfs4_open_release, |
| 2474 | }; |
| 2475 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2476 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2477 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2478 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2479 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2480 | struct nfs_server *server = NFS_SERVER(dir); |
| 2481 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2482 | struct nfs_openres *o_res = &data->o_res; |
| 2483 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2484 | struct rpc_message msg = { |
| 2485 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2486 | .rpc_argp = o_arg, |
| 2487 | .rpc_resp = o_res, |
| 2488 | .rpc_cred = data->owner->so_cred, |
| 2489 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2490 | struct rpc_task_setup task_setup_data = { |
| 2491 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2492 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2493 | .callback_ops = &nfs4_open_ops, |
| 2494 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2495 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2496 | .flags = RPC_TASK_ASYNC, |
| 2497 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2498 | int status; |
| 2499 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2500 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2501 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2502 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2503 | data->cancelled = false; |
| 2504 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2505 | if (!ctx) { |
| 2506 | 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] | 2507 | data->is_recover = true; |
Trond Myklebust | 67e7b52 | 2019-08-07 07:31:27 -0400 | [diff] [blame] | 2508 | task_setup_data.flags |= RPC_TASK_TIMEOUT; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2509 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2510 | 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] | 2511 | pnfs_lgopen_prepare(data, ctx); |
| 2512 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2513 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2514 | if (IS_ERR(task)) |
| 2515 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2516 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2517 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2518 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2519 | smp_wmb(); |
| 2520 | } else |
| 2521 | status = data->rpc_status; |
| 2522 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2523 | |
| 2524 | return status; |
| 2525 | } |
| 2526 | |
| 2527 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2528 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2529 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2530 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2531 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2532 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2533 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2534 | if (status != 0 || !data->rpc_done) |
| 2535 | return status; |
| 2536 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2537 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2538 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2539 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2540 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2541 | |
| 2542 | return status; |
| 2543 | } |
| 2544 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2545 | /* |
| 2546 | * Additional permission checks in order to distinguish between an |
| 2547 | * open for read, and an open for execute. This works around the |
| 2548 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2549 | * the same. |
| 2550 | * Note that in the non-execute case, we want to turn off permission |
| 2551 | * checking if we just created a new file (POSIX open() semantics). |
| 2552 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2553 | static int nfs4_opendata_access(const struct cred *cred, |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2554 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2555 | struct nfs4_state *state, fmode_t fmode, |
| 2556 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2557 | { |
| 2558 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2559 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2560 | |
| 2561 | /* access call failed or for some reason the server doesn't |
| 2562 | * support any access modes -- defer access call until later */ |
| 2563 | if (opendata->o_res.access_supported == 0) |
| 2564 | return 0; |
| 2565 | |
| 2566 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2567 | /* |
| 2568 | * Use openflags to check for exec, because fmode won't |
| 2569 | * always have FMODE_EXEC set when file open for exec. |
| 2570 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2571 | if (openflags & __FMODE_EXEC) { |
| 2572 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2573 | if (S_ISDIR(state->inode->i_mode)) |
| 2574 | mask = NFS4_ACCESS_LOOKUP; |
| 2575 | else |
| 2576 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2577 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2578 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2579 | |
| 2580 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2581 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2582 | nfs_access_add_cache(state->inode, &cache); |
| 2583 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2584 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2585 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2586 | return 0; |
| 2587 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2588 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2589 | } |
| 2590 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2591 | /* |
| 2592 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2593 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2594 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2595 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2596 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2597 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2598 | struct nfs_server *server = NFS_SERVER(dir); |
| 2599 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2600 | struct nfs_openres *o_res = &data->o_res; |
| 2601 | int status; |
| 2602 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2603 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2604 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2605 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2606 | if (status != 0) { |
| 2607 | if (status == -NFS4ERR_BADNAME && |
| 2608 | !(o_arg->open_flags & O_CREAT)) |
| 2609 | return -ENOENT; |
| 2610 | return status; |
| 2611 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2612 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2613 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2614 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2615 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2616 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2617 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2618 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2619 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2620 | if (data->file_created || |
| 2621 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2622 | update_changeattr(dir, &o_res->cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 2623 | o_res->f_attr->time_start, 0); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2624 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2625 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2626 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2628 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2630 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2632 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2633 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2634 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2635 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2636 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2637 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | } |
| 2639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | /* |
| 2641 | * OPEN_EXPIRED: |
| 2642 | * reclaim state on the server after a network partition. |
| 2643 | * Assumes caller holds the appropriate lock |
| 2644 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2645 | 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] | 2646 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2647 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2648 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2650 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2651 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2652 | if (IS_ERR(opendata)) |
| 2653 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2654 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2655 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2656 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2657 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2658 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2661 | 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] | 2662 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2663 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2664 | struct nfs4_exception exception = { }; |
| 2665 | int err; |
| 2666 | |
| 2667 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2668 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2669 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2670 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2671 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2672 | switch (err) { |
| 2673 | default: |
| 2674 | goto out; |
| 2675 | case -NFS4ERR_GRACE: |
| 2676 | case -NFS4ERR_DELAY: |
| 2677 | nfs4_handle_exception(server, err, &exception); |
| 2678 | err = 0; |
| 2679 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2680 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2681 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2682 | return err; |
| 2683 | } |
| 2684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2686 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2688 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2690 | ctx = nfs4_state_find_open_context(state); |
| 2691 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2692 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2693 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2694 | put_nfs_open_context(ctx); |
| 2695 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2698 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2699 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2700 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2701 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2702 | nfs_state_clear_delegation(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2706 | { |
| 2707 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2708 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2712 | { |
| 2713 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2714 | nfs40_clear_delegation_stateid(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2715 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2716 | return nfs4_open_expired(sp, state); |
| 2717 | } |
| 2718 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2719 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2720 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2721 | const struct cred *cred) |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2722 | { |
| 2723 | return -NFS4ERR_BAD_STATEID; |
| 2724 | } |
| 2725 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2726 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2727 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2728 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2729 | const struct cred *cred) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2730 | { |
| 2731 | int status; |
| 2732 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2733 | switch (stateid->type) { |
| 2734 | default: |
| 2735 | break; |
| 2736 | case NFS4_INVALID_STATEID_TYPE: |
| 2737 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2738 | return -NFS4ERR_BAD_STATEID; |
| 2739 | case NFS4_REVOKED_STATEID_TYPE: |
| 2740 | goto out_free; |
| 2741 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2742 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2743 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2744 | switch (status) { |
| 2745 | case -NFS4ERR_EXPIRED: |
| 2746 | case -NFS4ERR_ADMIN_REVOKED: |
| 2747 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2748 | break; |
| 2749 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2750 | return status; |
| 2751 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2752 | out_free: |
| 2753 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2754 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2755 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2756 | } |
| 2757 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2758 | static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2759 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2760 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2761 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2762 | struct nfs_delegation *delegation; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2763 | const struct cred *cred = NULL; |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2764 | int status, ret = NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2765 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2766 | /* Get the delegation credential for use by test/free_stateid */ |
| 2767 | rcu_read_lock(); |
| 2768 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2769 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2770 | rcu_read_unlock(); |
Trond Myklebust | 9f0c512 | 2018-09-05 14:07:15 -0400 | [diff] [blame] | 2771 | nfs_state_clear_delegation(state); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2772 | return NFS_OK; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2776 | |
Trond Myklebust | 994b15b | 2018-09-05 14:07:14 -0400 | [diff] [blame] | 2777 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2778 | &delegation->flags)) { |
| 2779 | rcu_read_unlock(); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2780 | return NFS_OK; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2781 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2782 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2783 | if (delegation->cred) |
| 2784 | cred = get_cred(delegation->cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2785 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2786 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2787 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2788 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2789 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2790 | else |
| 2791 | ret = status; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2792 | |
Trond Myklebust | 8c39a39 | 2019-07-19 13:48:44 -0400 | [diff] [blame] | 2793 | put_cred(cred); |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2794 | return ret; |
| 2795 | } |
| 2796 | |
| 2797 | static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
| 2798 | { |
| 2799 | nfs4_stateid tmp; |
| 2800 | |
| 2801 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
| 2802 | nfs4_copy_delegation_stateid(state->inode, state->state, |
| 2803 | &tmp, NULL) && |
| 2804 | nfs4_stateid_match_other(&state->stateid, &tmp)) |
| 2805 | nfs_state_set_delegation(state, &tmp, state->state); |
| 2806 | else |
| 2807 | nfs_state_clear_delegation(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2811 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2812 | * |
| 2813 | * @state: NFSv4 state for an inode |
| 2814 | * |
| 2815 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2816 | * Otherwise a negative NFS4ERR value is returned. |
| 2817 | */ |
| 2818 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2819 | { |
| 2820 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2821 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2822 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2823 | |
| 2824 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2825 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2826 | |
| 2827 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2828 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2829 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2830 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2831 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2832 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2833 | spin_unlock(&state->state_lock); |
| 2834 | |
| 2835 | nfs4_put_lock_state(prev); |
| 2836 | prev = lsp; |
| 2837 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2838 | status = nfs41_test_and_free_expired_stateid(server, |
| 2839 | &lsp->ls_stateid, |
| 2840 | cred); |
| 2841 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2842 | if (status == -NFS4ERR_EXPIRED || |
| 2843 | status == -NFS4ERR_BAD_STATEID) { |
| 2844 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2845 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2846 | if (!recover_lost_locks) |
| 2847 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2848 | } else if (status != NFS_OK) { |
| 2849 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2850 | nfs4_put_lock_state(prev); |
| 2851 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2852 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2853 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2854 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2855 | } |
| 2856 | spin_unlock(&state->state_lock); |
| 2857 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2858 | out: |
| 2859 | return ret; |
| 2860 | } |
| 2861 | |
| 2862 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2863 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2864 | * |
| 2865 | * @state: NFSv4 state for an inode |
| 2866 | * |
| 2867 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2868 | * Otherwise a negative NFS4ERR value is returned. |
| 2869 | */ |
| 2870 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2871 | { |
| 2872 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2873 | nfs4_stateid *stateid = &state->open_stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2874 | const struct cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2875 | int status; |
| 2876 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2877 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2878 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2879 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2880 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2881 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2882 | nfs_state_clear_open_state_flags(state); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2883 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2884 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2885 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2886 | if (nfs_open_stateid_recover_openmode(state)) |
| 2887 | return -NFS4ERR_OPENMODE; |
| 2888 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2892 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2893 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2894 | |
Trond Myklebust | 27a30cf | 2019-07-22 18:32:59 +0100 | [diff] [blame] | 2895 | status = nfs41_check_delegation_stateid(state); |
| 2896 | if (status != NFS_OK) |
| 2897 | return status; |
| 2898 | nfs41_delegation_recover_stateid(state); |
| 2899 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2900 | status = nfs41_check_expired_locks(state); |
| 2901 | if (status != NFS_OK) |
| 2902 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2903 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2904 | if (status != NFS_OK) |
| 2905 | status = nfs4_open_expired(sp, state); |
| 2906 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2907 | } |
| 2908 | #endif |
| 2909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2911 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2912 | * fields corresponding to attributes that were used to store the verifier. |
| 2913 | * Make sure we clobber those fields in the later setattr call |
| 2914 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2915 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2916 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2917 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2918 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2919 | __u32 attrset[3]; |
| 2920 | unsigned ret; |
| 2921 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2922 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2923 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2924 | attrset[i] = opendata->o_res.attrset[i]; |
| 2925 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2926 | attrset[i] &= ~bitmask[i]; |
| 2927 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2928 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2929 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2930 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2931 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2932 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2933 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2934 | ret |= ATTR_ATIME_SET; |
| 2935 | else |
| 2936 | ret |= ATTR_ATIME; |
| 2937 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2938 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2939 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2940 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2941 | ret |= ATTR_MTIME_SET; |
| 2942 | else |
| 2943 | ret |= ATTR_MTIME; |
| 2944 | } |
| 2945 | |
| 2946 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2947 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2948 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2949 | } |
| 2950 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2951 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 2952 | int flags, struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2953 | { |
| 2954 | struct nfs4_state_owner *sp = opendata->owner; |
| 2955 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2956 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2957 | struct nfs4_state *state; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 2958 | fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2959 | unsigned int seq; |
| 2960 | int ret; |
| 2961 | |
| 2962 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2963 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2964 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2965 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2966 | goto out; |
| 2967 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2968 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2969 | ret = PTR_ERR(state); |
| 2970 | if (IS_ERR(state)) |
| 2971 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2972 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2973 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2974 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2975 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2976 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2977 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2978 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2979 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2980 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2981 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2982 | alias = d_exact_alias(dentry, state->inode); |
| 2983 | if (!alias) |
| 2984 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2985 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2986 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2987 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2988 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2989 | } |
| 2990 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2991 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2992 | } |
| 2993 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 2994 | /* Parse layoutget results before we check for access */ |
| 2995 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 2996 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 2997 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
| 2998 | acc_mode, flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2999 | if (ret != 0) |
| 3000 | goto out; |
| 3001 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3002 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 3003 | nfs_inode_attach_open_context(ctx); |
| 3004 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 3005 | nfs4_schedule_stateid_recovery(server, state); |
| 3006 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 3007 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3008 | out: |
Olga Kornievskaia | 0cb98ab | 2019-03-19 12:12:13 -0400 | [diff] [blame] | 3009 | if (!opendata->cancelled) |
| 3010 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 3011 | return ret; |
| 3012 | } |
| 3013 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 3014 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 3015 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3017 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3018 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3019 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3020 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3021 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | { |
| 3023 | struct nfs4_state_owner *sp; |
| 3024 | struct nfs4_state *state = NULL; |
| 3025 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3026 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3027 | struct dentry *dentry = ctx->dentry; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3028 | const struct cred *cred = ctx->cred; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3029 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3030 | fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3031 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3032 | struct iattr *sattr = c->sattr; |
| 3033 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3034 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3035 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | |
| 3037 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 3039 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 3040 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 3042 | goto out_err; |
| 3043 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 3044 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3045 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3046 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3047 | if (d_really_is_positive(dentry)) |
| 3048 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 3049 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3050 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3051 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3052 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 3053 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3054 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 3055 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3057 | if (label) { |
| 3058 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 3059 | if (IS_ERR(olabel)) { |
| 3060 | status = PTR_ERR(olabel); |
| 3061 | goto err_opendata_put; |
| 3062 | } |
| 3063 | } |
| 3064 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3065 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 3066 | if (!opendata->f_attr.mdsthreshold) { |
| 3067 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 3068 | if (!opendata->f_attr.mdsthreshold) |
| 3069 | goto err_free_label; |
| 3070 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 3071 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3072 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3073 | if (d_really_is_positive(dentry)) |
| 3074 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3075 | |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3076 | status = _nfs4_open_and_get_state(opendata, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3077 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3078 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3079 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3080 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 3081 | 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] | 3082 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3083 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3084 | /* |
| 3085 | * send create attributes which was not set by open |
| 3086 | * with an extra setattr. |
| 3087 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3088 | if (attrs || label) { |
| 3089 | unsigned ia_old = sattr->ia_valid; |
| 3090 | |
| 3091 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3092 | nfs_fattr_init(opendata->o_res.f_attr); |
| 3093 | status = nfs4_do_setattr(state->inode, cred, |
| 3094 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3095 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 3096 | if (status == 0) { |
| 3097 | nfs_setattr_update_inode(state->inode, sattr, |
| 3098 | opendata->o_res.f_attr); |
| 3099 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 3100 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 3101 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3102 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 3103 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3104 | if (opened && opendata->file_created) |
Al Viro | 73a09dd | 2018-06-08 13:22:02 -0400 | [diff] [blame] | 3105 | *opened = 1; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3106 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3107 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3108 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3109 | opendata->f_attr.mdsthreshold = NULL; |
| 3110 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3111 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3112 | nfs4_label_free(olabel); |
| 3113 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3114 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3117 | err_free_label: |
| 3118 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3119 | err_opendata_put: |
| 3120 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3121 | err_put_state_owner: |
| 3122 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | return status; |
| 3125 | } |
| 3126 | |
| 3127 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3128 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3129 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3130 | int flags, |
| 3131 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3132 | struct nfs4_label *label, |
| 3133 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3135 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3136 | struct nfs4_exception exception = { |
| 3137 | .interruptible = true, |
| 3138 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3140 | struct nfs4_open_createattrs c = { |
| 3141 | .label = label, |
| 3142 | .sattr = sattr, |
| 3143 | .verf = { |
| 3144 | [0] = (__u32)jiffies, |
| 3145 | [1] = (__u32)current->pid, |
| 3146 | }, |
| 3147 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | int status; |
| 3149 | |
| 3150 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3151 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3152 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3153 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | if (status == 0) |
| 3155 | break; |
| 3156 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3157 | * book-keeping w.r.t. state-changing operations |
| 3158 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3159 | * It is actually a sign of a bug on the client or on the server. |
| 3160 | * |
| 3161 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3162 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | * have unhashed the old state_owner for us, and that we can |
| 3164 | * therefore safely retry using a new one. We should still warn |
| 3165 | * the user though... |
| 3166 | */ |
| 3167 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3168 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3169 | " returned a bad sequence-id error!\n", |
| 3170 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | exception.retry = 1; |
| 3172 | continue; |
| 3173 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3174 | /* |
| 3175 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3176 | * state before it received the OPEN_CONFIRM. |
| 3177 | * Recover by retrying the request as per the discussion |
| 3178 | * on Page 181 of RFC3530. |
| 3179 | */ |
| 3180 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3181 | exception.retry = 1; |
| 3182 | continue; |
| 3183 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3184 | if (status == -EAGAIN) { |
| 3185 | /* We must have found a delegation */ |
| 3186 | exception.retry = 1; |
| 3187 | continue; |
| 3188 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3189 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3190 | continue; |
| 3191 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | status, &exception)); |
| 3193 | } while (exception.retry); |
| 3194 | return res; |
| 3195 | } |
| 3196 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3197 | static int _nfs4_do_setattr(struct inode *inode, |
| 3198 | struct nfs_setattrargs *arg, |
| 3199 | struct nfs_setattrres *res, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3200 | const struct cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3201 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3202 | { |
| 3203 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3204 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3205 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3206 | .rpc_argp = arg, |
| 3207 | .rpc_resp = res, |
| 3208 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3209 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3210 | const struct cred *delegation_cred = NULL; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3211 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3212 | bool truncate; |
| 3213 | int status; |
| 3214 | |
| 3215 | nfs_fattr_init(res->fattr); |
| 3216 | |
| 3217 | /* Servers should only apply open mode checks for file size changes */ |
| 3218 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3219 | if (!truncate) |
| 3220 | goto zero_stateid; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3221 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3222 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3223 | /* Use that stateid */ |
Trond Myklebust | 09a54f0 | 2019-08-03 10:28:18 -0400 | [diff] [blame] | 3224 | } else if (ctx != NULL && ctx->state) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3225 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3226 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3227 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3228 | l_ctx = nfs_get_lock_context(ctx); |
| 3229 | if (IS_ERR(l_ctx)) |
| 3230 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3231 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3232 | &arg->stateid, &delegation_cred); |
| 3233 | nfs_put_lock_context(l_ctx); |
| 3234 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3235 | return -EBADF; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3236 | } else { |
| 3237 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3238 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3239 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3240 | if (delegation_cred) |
| 3241 | msg.rpc_cred = delegation_cred; |
| 3242 | |
| 3243 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3244 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3245 | put_cred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3246 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3247 | renew_lease(server, timestamp); |
| 3248 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3249 | return status; |
| 3250 | } |
| 3251 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 3252 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3253 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3254 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3255 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3257 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3258 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3259 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3260 | struct nfs_setattrargs arg = { |
| 3261 | .fh = NFS_FH(inode), |
| 3262 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3264 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3265 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3266 | }; |
| 3267 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3269 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3271 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3272 | struct nfs4_exception exception = { |
| 3273 | .state = state, |
| 3274 | .inode = inode, |
| 3275 | .stateid = &arg.stateid, |
| 3276 | }; |
| 3277 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3280 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3281 | nfs4_bitmask(server, olabel), |
| 3282 | inode); |
| 3283 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3284 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3285 | switch (err) { |
| 3286 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3287 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3288 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3289 | "applying open mode checks to " |
| 3290 | "a SETATTR that is not " |
| 3291 | "changing file size.\n", |
| 3292 | server->nfs_client->cl_hostname); |
| 3293 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3294 | if (state && !(state->state & FMODE_WRITE)) { |
| 3295 | err = -EBADF; |
| 3296 | if (sattr->ia_valid & ATTR_OPEN) |
| 3297 | err = -EACCES; |
| 3298 | goto out; |
| 3299 | } |
| 3300 | } |
| 3301 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3303 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | return err; |
| 3305 | } |
| 3306 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3307 | static bool |
| 3308 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3309 | { |
| 3310 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3311 | return false; |
| 3312 | |
| 3313 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3314 | } |
| 3315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | struct nfs4_closedata { |
| 3317 | struct inode *inode; |
| 3318 | struct nfs4_state *state; |
| 3319 | struct nfs_closeargs arg; |
| 3320 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3321 | struct { |
| 3322 | struct nfs4_layoutreturn_args arg; |
| 3323 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3324 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3325 | u32 roc_barrier; |
| 3326 | bool roc; |
| 3327 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3328 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3329 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | }; |
| 3331 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3332 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3333 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3334 | struct nfs4_closedata *calldata = data; |
| 3335 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3336 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3337 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3338 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3339 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3340 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3341 | nfs4_put_open_state(calldata->state); |
| 3342 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3343 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3344 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3345 | kfree(calldata); |
| 3346 | } |
| 3347 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3348 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3350 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3353 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3354 | struct nfs4_exception exception = { |
| 3355 | .state = state, |
| 3356 | .inode = calldata->inode, |
| 3357 | .stateid = &calldata->arg.stateid, |
| 3358 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3360 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3361 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3362 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3363 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3364 | |
| 3365 | /* Handle Layoutreturn errors */ |
| 3366 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3367 | switch (calldata->res.lr_ret) { |
| 3368 | default: |
| 3369 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3370 | break; |
| 3371 | case 0: |
| 3372 | calldata->arg.lr_args = NULL; |
| 3373 | calldata->res.lr_res = NULL; |
| 3374 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3375 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | c16467d | 2018-07-29 22:39:15 -0400 | [diff] [blame] | 3376 | if (nfs4_layoutreturn_refresh_stateid(&calldata->arg.lr_args->stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 3377 | &calldata->arg.lr_args->range, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3378 | calldata->inode)) |
| 3379 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3380 | /* Fallthrough */ |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3381 | case -NFS4ERR_ADMIN_REVOKED: |
| 3382 | case -NFS4ERR_DELEG_REVOKED: |
| 3383 | case -NFS4ERR_EXPIRED: |
| 3384 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3385 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3386 | case -NFS4ERR_WRONG_CRED: |
| 3387 | calldata->arg.lr_args = NULL; |
| 3388 | calldata->res.lr_res = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3389 | goto lr_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3390 | } |
| 3391 | } |
| 3392 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3393 | /* 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] | 3394 | * the state_owner. we keep this around to process errors |
| 3395 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | switch (task->tk_status) { |
| 3397 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3398 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3399 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3400 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3401 | case -NFS4ERR_ACCESS: |
| 3402 | if (calldata->arg.bitmask != NULL) { |
| 3403 | calldata->arg.bitmask = NULL; |
| 3404 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3405 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3406 | |
| 3407 | } |
| 3408 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3409 | case -NFS4ERR_OLD_STATEID: |
| 3410 | /* Did we race with OPEN? */ |
| 3411 | if (nfs4_refresh_open_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3412 | state)) |
| 3413 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3414 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3415 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3417 | case -NFS4ERR_EXPIRED: |
| 3418 | nfs4_free_revoked_stateid(server, |
| 3419 | &calldata->arg.stateid, |
| 3420 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3421 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3422 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3423 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3425 | task->tk_status = nfs4_async_handle_exception(task, |
| 3426 | server, task->tk_status, &exception); |
| 3427 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3428 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3430 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3431 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3432 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3433 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3434 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3435 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3436 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3437 | return; |
| 3438 | lr_restart: |
| 3439 | calldata->res.lr_ret = 0; |
| 3440 | out_restart: |
| 3441 | task->tk_status = 0; |
| 3442 | rpc_restart_call_prepare(task); |
| 3443 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | } |
| 3445 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3446 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3448 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3449 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3450 | struct inode *inode = calldata->inode; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3451 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3452 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3453 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3454 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3455 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3456 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3457 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3458 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3459 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3460 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3461 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3462 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3463 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3464 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3465 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3466 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3467 | if (state->n_rdonly == 0) |
| 3468 | call_close |= is_rdonly; |
| 3469 | else if (is_rdonly) |
| 3470 | calldata->arg.fmode |= FMODE_READ; |
| 3471 | if (state->n_wronly == 0) |
| 3472 | call_close |= is_wronly; |
| 3473 | else if (is_wronly) |
| 3474 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3475 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3476 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3477 | } else if (is_rdwr) |
| 3478 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3479 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3480 | if (!nfs4_valid_open_stateid(state) || |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3481 | !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3482 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3483 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3484 | |
| 3485 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3486 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3487 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3488 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3489 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3490 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3491 | nfs_release_seqid(calldata->arg.seqid); |
| 3492 | goto out_wait; |
| 3493 | } |
| 3494 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3495 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3496 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3497 | calldata->arg.lr_args = NULL; |
| 3498 | calldata->res.lr_res = NULL; |
| 3499 | } |
| 3500 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3501 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3502 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3503 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3504 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3505 | /* Close-to-open cache consistency revalidation */ |
| 3506 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3507 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3508 | else |
| 3509 | calldata->arg.bitmask = NULL; |
| 3510 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3511 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3512 | calldata->arg.share_access = |
| 3513 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3514 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3515 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3516 | if (calldata->res.fattr == NULL) |
| 3517 | calldata->arg.bitmask = NULL; |
| 3518 | else if (calldata->arg.bitmask == NULL) |
| 3519 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3520 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3521 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3522 | &calldata->arg.seq_args, |
| 3523 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3524 | task) != 0) |
| 3525 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3526 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3527 | return; |
| 3528 | out_no_action: |
| 3529 | task->tk_action = NULL; |
| 3530 | out_wait: |
| 3531 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3534 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3535 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3536 | .rpc_call_done = nfs4_close_done, |
| 3537 | .rpc_release = nfs4_free_closedata, |
| 3538 | }; |
| 3539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | /* |
| 3541 | * It is possible for data to be read/written from a mem-mapped file |
| 3542 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3543 | * This means that we can't safely call nfsv4 close on a file until |
| 3544 | * the inode is cleared. This in turn means that we are not good |
| 3545 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3546 | * share state even when we are done with one of the three share |
| 3547 | * stateid's in the inode. |
| 3548 | * |
| 3549 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3550 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3551 | 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] | 3552 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3553 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3554 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3556 | struct nfs4_state_owner *sp = state->owner; |
| 3557 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3558 | struct rpc_message msg = { |
| 3559 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3560 | .rpc_cred = state->owner->so_cred, |
| 3561 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3562 | struct rpc_task_setup task_setup_data = { |
| 3563 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3564 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3565 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3566 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3567 | .flags = RPC_TASK_ASYNC, |
| 3568 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3569 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3571 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3572 | &task_setup_data.rpc_client, &msg); |
| 3573 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3574 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3576 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3577 | 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] | 3578 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3580 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3581 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3582 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3584 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3585 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3586 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3587 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3588 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3589 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3590 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3591 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3592 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3593 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3594 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3595 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3596 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3597 | if (calldata->lr.roc) { |
| 3598 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3599 | calldata->res.lr_res = &calldata->lr.res; |
| 3600 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3601 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3602 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3603 | msg.rpc_argp = &calldata->arg; |
| 3604 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3605 | task_setup_data.callback_data = calldata; |
| 3606 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3607 | if (IS_ERR(task)) |
| 3608 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3609 | status = 0; |
| 3610 | if (wait) |
| 3611 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3612 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3613 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3614 | out_free_calldata: |
| 3615 | kfree(calldata); |
| 3616 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3617 | nfs4_put_open_state(state); |
| 3618 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3619 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | } |
| 3621 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3622 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3623 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3624 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3627 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3628 | |
| 3629 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3631 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3632 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3633 | |
| 3634 | nfs4_label_release_security(label); |
| 3635 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3636 | if (IS_ERR(state)) |
| 3637 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3638 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3641 | 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] | 3642 | { |
| 3643 | if (ctx->state == NULL) |
| 3644 | return; |
| 3645 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3646 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3647 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3648 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3651 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3652 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3653 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3656 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3657 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3658 | struct nfs4_server_caps_arg args = { |
| 3659 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3660 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3661 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | struct nfs4_server_caps_res res = {}; |
| 3663 | struct rpc_message msg = { |
| 3664 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3665 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | .rpc_resp = &res, |
| 3667 | }; |
| 3668 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3669 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3671 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3672 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3673 | FATTR4_WORD0_LINK_SUPPORT | |
| 3674 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3675 | FATTR4_WORD0_ACLSUPPORT; |
| 3676 | if (minorversion) |
| 3677 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3678 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3679 | 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] | 3680 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3681 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3682 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3683 | case 0: |
| 3684 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3685 | res.attr_bitmask[2] = 0; |
| 3686 | break; |
| 3687 | case 1: |
| 3688 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3689 | break; |
| 3690 | case 2: |
| 3691 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3692 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3694 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3695 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3696 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3697 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3698 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3699 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3700 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3701 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | server->caps |= NFS_CAP_ACLS; |
| 3703 | if (res.has_links != 0) |
| 3704 | server->caps |= NFS_CAP_HARDLINKS; |
| 3705 | if (res.has_symlinks != 0) |
| 3706 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3707 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3708 | server->caps |= NFS_CAP_FILEID; |
| 3709 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3710 | server->caps |= NFS_CAP_MODE; |
| 3711 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3712 | server->caps |= NFS_CAP_NLINK; |
| 3713 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3714 | server->caps |= NFS_CAP_OWNER; |
| 3715 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3716 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3717 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3718 | server->caps |= NFS_CAP_ATIME; |
| 3719 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3720 | server->caps |= NFS_CAP_CTIME; |
| 3721 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3722 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3723 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3724 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3725 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3726 | #endif |
| 3727 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3728 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3729 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3730 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3731 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3732 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3733 | 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] | 3734 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3735 | |
| 3736 | /* Avoid a regression due to buggy server */ |
| 3737 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3738 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3739 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3740 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3743 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | return status; |
| 3747 | } |
| 3748 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3749 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3751 | struct nfs4_exception exception = { |
| 3752 | .interruptible = true, |
| 3753 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | int err; |
| 3755 | do { |
| 3756 | err = nfs4_handle_exception(server, |
| 3757 | _nfs4_server_capabilities(server, fhandle), |
| 3758 | &exception); |
| 3759 | } while (exception.retry); |
| 3760 | return err; |
| 3761 | } |
| 3762 | |
| 3763 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3764 | struct nfs_fsinfo *info) |
| 3765 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3766 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3768 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | }; |
| 3770 | struct nfs4_lookup_res res = { |
| 3771 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3772 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | .fh = fhandle, |
| 3774 | }; |
| 3775 | struct rpc_message msg = { |
| 3776 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3777 | .rpc_argp = &args, |
| 3778 | .rpc_resp = &res, |
| 3779 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3780 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3781 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3782 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3783 | /* |
| 3784 | * Process the label in the upcoming getfattr |
| 3785 | */ |
| 3786 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3787 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3788 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3789 | 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] | 3790 | } |
| 3791 | |
| 3792 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3793 | struct nfs_fsinfo *info) |
| 3794 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3795 | struct nfs4_exception exception = { |
| 3796 | .interruptible = true, |
| 3797 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | int err; |
| 3799 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3800 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3801 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3802 | switch (err) { |
| 3803 | case 0: |
| 3804 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3805 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3806 | default: |
| 3807 | err = nfs4_handle_exception(server, err, &exception); |
| 3808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3810 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | return err; |
| 3812 | } |
| 3813 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3814 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3815 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3816 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3817 | struct rpc_auth_create_args auth_args = { |
| 3818 | .pseudoflavor = flavor, |
| 3819 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3820 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3821 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3822 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3823 | if (IS_ERR(auth)) |
| 3824 | return -EACCES; |
| 3825 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3828 | /* |
| 3829 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3830 | * |
| 3831 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3832 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3833 | * |
| 3834 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3835 | * negative errno value. |
| 3836 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3837 | 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] | 3838 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3840 | /* Per 3530bis 15.33.5 */ |
| 3841 | static const rpc_authflavor_t flav_array[] = { |
| 3842 | RPC_AUTH_GSS_KRB5P, |
| 3843 | RPC_AUTH_GSS_KRB5I, |
| 3844 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3845 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3846 | RPC_AUTH_NULL, |
| 3847 | }; |
| 3848 | int status = -EPERM; |
| 3849 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3851 | if (server->auth_info.flavor_len > 0) { |
| 3852 | /* try each flavor specified by user */ |
| 3853 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3854 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3855 | server->auth_info.flavors[i]); |
| 3856 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3857 | continue; |
| 3858 | break; |
| 3859 | } |
| 3860 | } else { |
| 3861 | /* no flavors specified by user, try default list */ |
| 3862 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3863 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3864 | flav_array[i]); |
| 3865 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3866 | continue; |
| 3867 | break; |
| 3868 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3869 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3870 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3871 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 3872 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3873 | * to access the mount. It could also mean that we tried to mount |
| 3874 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3875 | * existing mount programs don't handle -EACCES very well so it should |
| 3876 | * be mapped to -EPERM instead. |
| 3877 | */ |
| 3878 | if (status == -EACCES) |
| 3879 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3880 | return status; |
| 3881 | } |
| 3882 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3883 | /** |
| 3884 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3885 | * @server: initialized nfs_server handle |
| 3886 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3887 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3888 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3889 | * |
| 3890 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3891 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3892 | 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] | 3893 | struct nfs_fsinfo *info, |
| 3894 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3895 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3896 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3897 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3898 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3899 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3900 | |
| 3901 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3902 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3903 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | if (status == 0) |
| 3906 | status = nfs4_server_capabilities(server, fhandle); |
| 3907 | if (status == 0) |
| 3908 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3909 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3910 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | } |
| 3912 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3913 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3914 | struct nfs_fsinfo *info) |
| 3915 | { |
| 3916 | int error; |
| 3917 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3918 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3919 | |
| 3920 | error = nfs4_server_capabilities(server, mntfh); |
| 3921 | if (error < 0) { |
| 3922 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3923 | return error; |
| 3924 | } |
| 3925 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3926 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3927 | if (IS_ERR(label)) |
| 3928 | return PTR_ERR(label); |
| 3929 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3930 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3931 | if (error < 0) { |
| 3932 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3933 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3937 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3938 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3939 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3940 | err_free_label: |
| 3941 | nfs4_label_free(label); |
| 3942 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3943 | return error; |
| 3944 | } |
| 3945 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3946 | /* |
| 3947 | * Get locations and (maybe) other attributes of a referral. |
| 3948 | * Note that we'll actually follow the referral later when |
| 3949 | * we detect fsid mismatch in inode revalidation |
| 3950 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3951 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3952 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3953 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3954 | { |
| 3955 | int status = -ENOMEM; |
| 3956 | struct page *page = NULL; |
| 3957 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3958 | |
| 3959 | page = alloc_page(GFP_KERNEL); |
| 3960 | if (page == NULL) |
| 3961 | goto out; |
| 3962 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3963 | if (locations == NULL) |
| 3964 | goto out; |
| 3965 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3966 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3967 | if (status != 0) |
| 3968 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3969 | |
| 3970 | /* |
| 3971 | * If the fsid didn't change, this is a migration event, not a |
| 3972 | * referral. Cause us to drop into the exception handler, which |
| 3973 | * will kick off migration recovery. |
| 3974 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3975 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3976 | dprintk("%s: server did not return a different fsid for" |
| 3977 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3978 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3979 | goto out; |
| 3980 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3981 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3982 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3983 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3984 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3985 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3986 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3987 | out: |
| 3988 | if (page) |
| 3989 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3990 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3991 | return status; |
| 3992 | } |
| 3993 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3994 | 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] | 3995 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3996 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3998 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | struct nfs4_getattr_arg args = { |
| 4000 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4001 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | }; |
| 4003 | struct nfs4_getattr_res res = { |
| 4004 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4005 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | .server = server, |
| 4007 | }; |
| 4008 | struct rpc_message msg = { |
| 4009 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4010 | .rpc_argp = &args, |
| 4011 | .rpc_resp = &res, |
| 4012 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4013 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4014 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4015 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4016 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4017 | 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] | 4018 | } |
| 4019 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4020 | 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] | 4021 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4022 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4024 | struct nfs4_exception exception = { |
| 4025 | .interruptible = true, |
| 4026 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | int err; |
| 4028 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4029 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4030 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4031 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | &exception); |
| 4033 | } while (exception.retry); |
| 4034 | return err; |
| 4035 | } |
| 4036 | |
| 4037 | /* |
| 4038 | * The file is not closed if it is opened due to the a request to change |
| 4039 | * the size of the file. The open call will not be needed once the |
| 4040 | * VFS layer lookup-intents are implemented. |
| 4041 | * |
| 4042 | * Close is called when the inode is destroyed. |
| 4043 | * If we haven't opened the file for O_WRONLY, we |
| 4044 | * need to in the size_change case to obtain a stateid. |
| 4045 | * |
| 4046 | * Got race? |
| 4047 | * Because OPEN is always done by name in nfsv4, it is |
| 4048 | * possible that we opened a different file by the same |
| 4049 | * name. We can recognize this race condition, but we |
| 4050 | * can't do anything about it besides returning an error. |
| 4051 | * |
| 4052 | * This will be fixed with VFS changes (lookup-intent). |
| 4053 | */ |
| 4054 | static int |
| 4055 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4056 | struct iattr *sattr) |
| 4057 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4058 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4059 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4060 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4061 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | int status; |
| 4063 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4064 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4065 | sattr->ia_valid & ATTR_SIZE && |
| 4066 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4067 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4068 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4069 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4071 | /* Deal with open(O_TRUNC) */ |
| 4072 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4073 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4074 | |
| 4075 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4076 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4077 | return 0; |
| 4078 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4079 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4080 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4081 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4082 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4083 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4084 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4085 | } |
| 4086 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4087 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4088 | if (IS_ERR(label)) |
| 4089 | return PTR_ERR(label); |
| 4090 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4091 | /* Return any delegations if we're going to change ACLs */ |
| 4092 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4093 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4094 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4095 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4096 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4097 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4098 | nfs_setsecurity(inode, fattr, label); |
| 4099 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4100 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | return status; |
| 4102 | } |
| 4103 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4104 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 4105 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4106 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4107 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4108 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4109 | int status; |
| 4110 | struct nfs4_lookup_arg args = { |
| 4111 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4112 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4113 | .name = name, |
| 4114 | }; |
| 4115 | struct nfs4_lookup_res res = { |
| 4116 | .server = server, |
| 4117 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4118 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4119 | .fh = fhandle, |
| 4120 | }; |
| 4121 | struct rpc_message msg = { |
| 4122 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4123 | .rpc_argp = &args, |
| 4124 | .rpc_resp = &res, |
| 4125 | }; |
| 4126 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4127 | args.bitmask = nfs4_bitmask(server, label); |
| 4128 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4129 | nfs_fattr_init(fattr); |
| 4130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4132 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | dprintk("NFS reply lookup: %d\n", status); |
| 4134 | return status; |
| 4135 | } |
| 4136 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4137 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4138 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4139 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4140 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4141 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4142 | fattr->nlink = 2; |
| 4143 | } |
| 4144 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4145 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4146 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4147 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4148 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4149 | struct nfs4_exception exception = { |
| 4150 | .interruptible = true, |
| 4151 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4152 | struct rpc_clnt *client = *clnt; |
| 4153 | int err; |
| 4154 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4155 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4156 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4157 | switch (err) { |
| 4158 | case -NFS4ERR_BADNAME: |
| 4159 | err = -ENOENT; |
| 4160 | goto out; |
| 4161 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4162 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4163 | if (err == -NFS4ERR_MOVED) |
| 4164 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4165 | goto out; |
| 4166 | case -NFS4ERR_WRONGSEC: |
| 4167 | err = -EPERM; |
| 4168 | if (client != *clnt) |
| 4169 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4170 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4171 | if (IS_ERR(client)) |
| 4172 | return PTR_ERR(client); |
| 4173 | |
| 4174 | exception.retry = 1; |
| 4175 | break; |
| 4176 | default: |
| 4177 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4178 | } |
| 4179 | } while (exception.retry); |
| 4180 | |
| 4181 | out: |
| 4182 | if (err == 0) |
| 4183 | *clnt = client; |
| 4184 | else if (client != *clnt) |
| 4185 | rpc_shutdown_client(client); |
| 4186 | |
| 4187 | return err; |
| 4188 | } |
| 4189 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4190 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4191 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4192 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4194 | int status; |
| 4195 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4196 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4197 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4198 | if (client != NFS_CLIENT(dir)) { |
| 4199 | rpc_shutdown_client(client); |
| 4200 | nfs_fixup_secinfo_attributes(fattr); |
| 4201 | } |
| 4202 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | } |
| 4204 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4205 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4206 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4207 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4208 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4209 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4210 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4211 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4212 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4213 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4214 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4215 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4216 | } |
| 4217 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4218 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4219 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4220 | struct nfs4_label *label) |
| 4221 | { |
| 4222 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4223 | struct nfs_server *server = NFS_SERVER(inode); |
| 4224 | int status; |
| 4225 | struct nfs4_lookupp_arg args = { |
| 4226 | .bitmask = server->attr_bitmask, |
| 4227 | .fh = NFS_FH(inode), |
| 4228 | }; |
| 4229 | struct nfs4_lookupp_res res = { |
| 4230 | .server = server, |
| 4231 | .fattr = fattr, |
| 4232 | .label = label, |
| 4233 | .fh = fhandle, |
| 4234 | }; |
| 4235 | struct rpc_message msg = { |
| 4236 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4237 | .rpc_argp = &args, |
| 4238 | .rpc_resp = &res, |
| 4239 | }; |
| 4240 | |
| 4241 | args.bitmask = nfs4_bitmask(server, label); |
| 4242 | |
| 4243 | nfs_fattr_init(fattr); |
| 4244 | |
| 4245 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4246 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4247 | &res.seq_res, 0); |
| 4248 | dprintk("NFS reply lookupp: %d\n", status); |
| 4249 | return status; |
| 4250 | } |
| 4251 | |
| 4252 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4253 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4254 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4255 | struct nfs4_exception exception = { |
| 4256 | .interruptible = true, |
| 4257 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4258 | int err; |
| 4259 | do { |
| 4260 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4261 | trace_nfs4_lookupp(inode, err); |
| 4262 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4263 | &exception); |
| 4264 | } while (exception.retry); |
| 4265 | return err; |
| 4266 | } |
| 4267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4269 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4270 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | struct nfs4_accessargs args = { |
| 4272 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4273 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4275 | struct nfs4_accessres res = { |
| 4276 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4277 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | struct rpc_message msg = { |
| 4279 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4280 | .rpc_argp = &args, |
| 4281 | .rpc_resp = &res, |
| 4282 | .rpc_cred = entry->cred, |
| 4283 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4284 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4286 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4287 | res.fattr = nfs_alloc_fattr(); |
| 4288 | if (res.fattr == NULL) |
| 4289 | return -ENOMEM; |
| 4290 | args.bitmask = server->cache_consistency_bitmask; |
| 4291 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4292 | 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] | 4293 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4294 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4295 | if (res.fattr) |
| 4296 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4298 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | return status; |
| 4300 | } |
| 4301 | |
| 4302 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4303 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4304 | struct nfs4_exception exception = { |
| 4305 | .interruptible = true, |
| 4306 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | int err; |
| 4308 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4309 | err = _nfs4_proc_access(inode, entry); |
| 4310 | trace_nfs4_access(inode, err); |
| 4311 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | &exception); |
| 4313 | } while (exception.retry); |
| 4314 | return err; |
| 4315 | } |
| 4316 | |
| 4317 | /* |
| 4318 | * TODO: For the time being, we don't try to get any attributes |
| 4319 | * along with any of the zero-copy operations READ, READDIR, |
| 4320 | * READLINK, WRITE. |
| 4321 | * |
| 4322 | * In the case of the first three, we want to put the GETATTR |
| 4323 | * after the read-type operation -- this is because it is hard |
| 4324 | * to predict the length of a GETATTR response in v4, and thus |
| 4325 | * align the READ data correctly. This means that the GETATTR |
| 4326 | * may end up partially falling into the page cache, and we should |
| 4327 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4328 | * To do this efficiently, we need to know the total length |
| 4329 | * of data received, which doesn't seem to be available outside |
| 4330 | * of the RPC layer. |
| 4331 | * |
| 4332 | * In the case of WRITE, we also want to put the GETATTR after |
| 4333 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4334 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | * |
| 4336 | * Both of these changes to the XDR layer would in fact be quite |
| 4337 | * minor, but I decided to leave them for a subsequent patch. |
| 4338 | */ |
| 4339 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4340 | unsigned int pgbase, unsigned int pglen) |
| 4341 | { |
| 4342 | struct nfs4_readlink args = { |
| 4343 | .fh = NFS_FH(inode), |
| 4344 | .pgbase = pgbase, |
| 4345 | .pglen = pglen, |
| 4346 | .pages = &page, |
| 4347 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4348 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | struct rpc_message msg = { |
| 4350 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4351 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4352 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | }; |
| 4354 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4355 | 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] | 4356 | } |
| 4357 | |
| 4358 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4359 | unsigned int pgbase, unsigned int pglen) |
| 4360 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4361 | struct nfs4_exception exception = { |
| 4362 | .interruptible = true, |
| 4363 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | int err; |
| 4365 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4366 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4367 | trace_nfs4_readlink(inode, err); |
| 4368 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | &exception); |
| 4370 | } while (exception.retry); |
| 4371 | return err; |
| 4372 | } |
| 4373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4375 | * 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] | 4376 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | static int |
| 4378 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4379 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4381 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4382 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4383 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | int status = 0; |
| 4386 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4387 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4388 | if (IS_ERR(ctx)) |
| 4389 | return PTR_ERR(ctx); |
| 4390 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4391 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4392 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4393 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4394 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4395 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | if (IS_ERR(state)) { |
| 4397 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4398 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4401 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4402 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | return status; |
| 4404 | } |
| 4405 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4406 | static int |
| 4407 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4409 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4410 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4412 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4414 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4415 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4416 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4418 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4419 | .rpc_argp = &args, |
| 4420 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4422 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4423 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4424 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4425 | 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] | 4426 | if (status == 0) { |
| 4427 | spin_lock(&dir->i_lock); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4428 | update_changeattr_locked(dir, &res.cinfo, timestamp, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4429 | /* Removing a directory decrements nlink in the parent */ |
| 4430 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4431 | nfs4_dec_nlink_locked(dir); |
| 4432 | spin_unlock(&dir->i_lock); |
| 4433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | return status; |
| 4435 | } |
| 4436 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4437 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4438 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4439 | struct nfs4_exception exception = { |
| 4440 | .interruptible = true, |
| 4441 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4442 | struct inode *inode = d_inode(dentry); |
| 4443 | int err; |
| 4444 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4445 | if (inode) { |
| 4446 | if (inode->i_nlink == 1) |
| 4447 | nfs4_inode_return_delegation(inode); |
| 4448 | else |
| 4449 | nfs4_inode_make_writeable(inode); |
| 4450 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4451 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4452 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4453 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4454 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4455 | &exception); |
| 4456 | } while (exception.retry); |
| 4457 | return err; |
| 4458 | } |
| 4459 | |
| 4460 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4462 | struct nfs4_exception exception = { |
| 4463 | .interruptible = true, |
| 4464 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4468 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4469 | trace_nfs4_remove(dir, name, err); |
| 4470 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | &exception); |
| 4472 | } while (exception.retry); |
| 4473 | return err; |
| 4474 | } |
| 4475 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4476 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4477 | struct dentry *dentry, |
| 4478 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4480 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4481 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4483 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4485 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4486 | |
| 4487 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4488 | |
| 4489 | if (inode) |
| 4490 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | } |
| 4492 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4493 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4494 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4495 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4496 | &data->args.seq_args, |
| 4497 | &data->res.seq_res, |
| 4498 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | } |
| 4500 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4501 | 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] | 4502 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4503 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4504 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4505 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4506 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4507 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4508 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4509 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4510 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4511 | if (task->tk_status == 0) |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4512 | update_changeattr(dir, &res->cinfo, |
| 4513 | res->dir_attr->time_start, 0); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4514 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | } |
| 4516 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4517 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4518 | struct dentry *old_dentry, |
| 4519 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4520 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4521 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4522 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4523 | struct inode *old_inode = d_inode(old_dentry); |
| 4524 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4525 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4526 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4527 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4528 | if (new_inode) |
| 4529 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4530 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4531 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4532 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4533 | } |
| 4534 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4535 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4536 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4537 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4538 | &data->args.seq_args, |
| 4539 | &data->res.seq_res, |
| 4540 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4544 | struct inode *new_dir) |
| 4545 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4546 | struct nfs_renamedata *data = task->tk_calldata; |
| 4547 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4548 | |
| 4549 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4550 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4551 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4552 | return 0; |
| 4553 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4554 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4555 | if (new_dir != old_dir) { |
| 4556 | /* Note: If we moved a directory, nlink will change */ |
| 4557 | update_changeattr(old_dir, &res->old_cinfo, |
| 4558 | res->old_fattr->time_start, |
| 4559 | NFS_INO_INVALID_OTHER); |
| 4560 | update_changeattr(new_dir, &res->new_cinfo, |
| 4561 | res->new_fattr->time_start, |
| 4562 | NFS_INO_INVALID_OTHER); |
| 4563 | } else |
| 4564 | update_changeattr(old_dir, &res->old_cinfo, |
| 4565 | res->old_fattr->time_start, |
| 4566 | 0); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4567 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4568 | return 1; |
| 4569 | } |
| 4570 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4571 | 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] | 4572 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4573 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4574 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | struct nfs4_link_arg arg = { |
| 4576 | .fh = NFS_FH(inode), |
| 4577 | .dir_fh = NFS_FH(dir), |
| 4578 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4579 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4581 | struct nfs4_link_res res = { |
| 4582 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4583 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4584 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | struct rpc_message msg = { |
| 4586 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4587 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4588 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4590 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4592 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4593 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4594 | goto out; |
| 4595 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4596 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4597 | if (IS_ERR(res.label)) { |
| 4598 | status = PTR_ERR(res.label); |
| 4599 | goto out; |
| 4600 | } |
| 4601 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4602 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4603 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4604 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4605 | 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] | 4606 | if (!status) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4607 | update_changeattr(dir, &res.cinfo, res.fattr->time_start, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4608 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4609 | if (!status) |
| 4610 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4611 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4612 | |
| 4613 | |
| 4614 | nfs4_label_free(res.label); |
| 4615 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4616 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4617 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | return status; |
| 4619 | } |
| 4620 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4621 | 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] | 4622 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4623 | struct nfs4_exception exception = { |
| 4624 | .interruptible = true, |
| 4625 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | int err; |
| 4627 | do { |
| 4628 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4629 | _nfs4_proc_link(inode, dir, name), |
| 4630 | &exception); |
| 4631 | } while (exception.retry); |
| 4632 | return err; |
| 4633 | } |
| 4634 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4635 | struct nfs4_createdata { |
| 4636 | struct rpc_message msg; |
| 4637 | struct nfs4_create_arg arg; |
| 4638 | struct nfs4_create_res res; |
| 4639 | struct nfs_fh fh; |
| 4640 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4641 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4642 | }; |
| 4643 | |
| 4644 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4645 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4646 | { |
| 4647 | struct nfs4_createdata *data; |
| 4648 | |
| 4649 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4650 | if (data != NULL) { |
| 4651 | struct nfs_server *server = NFS_SERVER(dir); |
| 4652 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4653 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4654 | if (IS_ERR(data->label)) |
| 4655 | goto out_free; |
| 4656 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4657 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4658 | data->msg.rpc_argp = &data->arg; |
| 4659 | data->msg.rpc_resp = &data->res; |
| 4660 | data->arg.dir_fh = NFS_FH(dir); |
| 4661 | data->arg.server = server; |
| 4662 | data->arg.name = name; |
| 4663 | data->arg.attrs = sattr; |
| 4664 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4665 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4666 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4667 | data->res.server = server; |
| 4668 | data->res.fh = &data->fh; |
| 4669 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4670 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4671 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4672 | } |
| 4673 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4674 | out_free: |
| 4675 | kfree(data); |
| 4676 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4680 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4681 | 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] | 4682 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4683 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4684 | spin_lock(&dir->i_lock); |
| 4685 | update_changeattr_locked(dir, &data->res.dir_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4686 | data->res.fattr->time_start, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4687 | /* Creating a directory bumps nlink in the parent */ |
| 4688 | if (data->arg.ftype == NF4DIR) |
| 4689 | nfs4_inc_nlink_locked(dir); |
| 4690 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4691 | 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] | 4692 | } |
| 4693 | return status; |
| 4694 | } |
| 4695 | |
| 4696 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4697 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4698 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4699 | kfree(data); |
| 4700 | } |
| 4701 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4702 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4703 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4704 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4706 | struct nfs4_createdata *data; |
| 4707 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4709 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4710 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4711 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4712 | status = -ENOMEM; |
| 4713 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4714 | if (data == NULL) |
| 4715 | goto out; |
| 4716 | |
| 4717 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4718 | data->arg.u.symlink.pages = &page; |
| 4719 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4720 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4722 | status = nfs4_do_create(dir, dentry, data); |
| 4723 | |
| 4724 | nfs4_free_createdata(data); |
| 4725 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | return status; |
| 4727 | } |
| 4728 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4729 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4730 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4732 | struct nfs4_exception exception = { |
| 4733 | .interruptible = true, |
| 4734 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4735 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4737 | |
| 4738 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4741 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4742 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4743 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | &exception); |
| 4745 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4746 | |
| 4747 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | return err; |
| 4749 | } |
| 4750 | |
| 4751 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4752 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4754 | struct nfs4_createdata *data; |
| 4755 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4757 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4758 | if (data == NULL) |
| 4759 | goto out; |
| 4760 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4761 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4762 | status = nfs4_do_create(dir, dentry, data); |
| 4763 | |
| 4764 | nfs4_free_createdata(data); |
| 4765 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | return status; |
| 4767 | } |
| 4768 | |
| 4769 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4770 | struct iattr *sattr) |
| 4771 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4772 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4773 | struct nfs4_exception exception = { |
| 4774 | .interruptible = true, |
| 4775 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4776 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4778 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4779 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4780 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4781 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4782 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4784 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4785 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4786 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | &exception); |
| 4788 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4789 | nfs4_label_release_security(label); |
| 4790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | return err; |
| 4792 | } |
| 4793 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4794 | static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4795 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4797 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | struct nfs4_readdir_arg args = { |
| 4799 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4800 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | .pgbase = 0, |
| 4802 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4803 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4804 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4805 | }; |
| 4806 | struct nfs4_readdir_res res; |
| 4807 | struct rpc_message msg = { |
| 4808 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4809 | .rpc_argp = &args, |
| 4810 | .rpc_resp = &res, |
| 4811 | .rpc_cred = cred, |
| 4812 | }; |
| 4813 | int status; |
| 4814 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4815 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4816 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4817 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4818 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4820 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4821 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4822 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4823 | status += args.pgbase; |
| 4824 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4825 | |
| 4826 | nfs_invalidate_atime(dir); |
| 4827 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4828 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | return status; |
| 4830 | } |
| 4831 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4832 | static int nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4833 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4835 | struct nfs4_exception exception = { |
| 4836 | .interruptible = true, |
| 4837 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | int err; |
| 4839 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4840 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4841 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4842 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4843 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | &exception); |
| 4845 | } while (exception.retry); |
| 4846 | return err; |
| 4847 | } |
| 4848 | |
| 4849 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4850 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4852 | struct nfs4_createdata *data; |
| 4853 | int mode = sattr->ia_mode; |
| 4854 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4856 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4857 | if (data == NULL) |
| 4858 | goto out; |
| 4859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4861 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4863 | data->arg.ftype = NF4BLK; |
| 4864 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4865 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | } |
| 4867 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4868 | data->arg.ftype = NF4CHR; |
| 4869 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4870 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4871 | } else if (!S_ISSOCK(mode)) { |
| 4872 | status = -EINVAL; |
| 4873 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4875 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4876 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4877 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4878 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4879 | nfs4_free_createdata(data); |
| 4880 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | return status; |
| 4882 | } |
| 4883 | |
| 4884 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4885 | struct iattr *sattr, dev_t rdev) |
| 4886 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4887 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4888 | struct nfs4_exception exception = { |
| 4889 | .interruptible = true, |
| 4890 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4891 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4893 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4894 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4895 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4896 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4897 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4899 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4900 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4901 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | &exception); |
| 4903 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4904 | |
| 4905 | nfs4_label_release_security(label); |
| 4906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | return err; |
| 4908 | } |
| 4909 | |
| 4910 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4911 | struct nfs_fsstat *fsstat) |
| 4912 | { |
| 4913 | struct nfs4_statfs_arg args = { |
| 4914 | .fh = fhandle, |
| 4915 | .bitmask = server->attr_bitmask, |
| 4916 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4917 | struct nfs4_statfs_res res = { |
| 4918 | .fsstat = fsstat, |
| 4919 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | struct rpc_message msg = { |
| 4921 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4922 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4923 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | }; |
| 4925 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4926 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4927 | 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] | 4928 | } |
| 4929 | |
| 4930 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4931 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4932 | struct nfs4_exception exception = { |
| 4933 | .interruptible = true, |
| 4934 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | int err; |
| 4936 | do { |
| 4937 | err = nfs4_handle_exception(server, |
| 4938 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4939 | &exception); |
| 4940 | } while (exception.retry); |
| 4941 | return err; |
| 4942 | } |
| 4943 | |
| 4944 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4945 | struct nfs_fsinfo *fsinfo) |
| 4946 | { |
| 4947 | struct nfs4_fsinfo_arg args = { |
| 4948 | .fh = fhandle, |
| 4949 | .bitmask = server->attr_bitmask, |
| 4950 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4951 | struct nfs4_fsinfo_res res = { |
| 4952 | .fsinfo = fsinfo, |
| 4953 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | struct rpc_message msg = { |
| 4955 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4956 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4957 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | }; |
| 4959 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4960 | 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] | 4961 | } |
| 4962 | |
| 4963 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4964 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4965 | struct nfs4_exception exception = { |
| 4966 | .interruptible = true, |
| 4967 | }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4968 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | int err; |
| 4970 | |
| 4971 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4972 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4973 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4974 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4975 | nfs4_set_lease_period(server->nfs_client, |
| 4976 | fsinfo->lease_time * HZ, |
| 4977 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4978 | break; |
| 4979 | } |
| 4980 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | } while (exception.retry); |
| 4982 | return err; |
| 4983 | } |
| 4984 | |
| 4985 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4986 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4987 | int error; |
| 4988 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4989 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4990 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4991 | if (error == 0) { |
| 4992 | /* block layout checks this! */ |
| 4993 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4994 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4995 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4996 | |
| 4997 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5001 | struct nfs_pathconf *pathconf) |
| 5002 | { |
| 5003 | struct nfs4_pathconf_arg args = { |
| 5004 | .fh = fhandle, |
| 5005 | .bitmask = server->attr_bitmask, |
| 5006 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5007 | struct nfs4_pathconf_res res = { |
| 5008 | .pathconf = pathconf, |
| 5009 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | struct rpc_message msg = { |
| 5011 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5012 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5013 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | }; |
| 5015 | |
| 5016 | /* None of the pathconf attributes are mandatory to implement */ |
| 5017 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5018 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5019 | return 0; |
| 5020 | } |
| 5021 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5022 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5023 | 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] | 5024 | } |
| 5025 | |
| 5026 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5027 | struct nfs_pathconf *pathconf) |
| 5028 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5029 | struct nfs4_exception exception = { |
| 5030 | .interruptible = true, |
| 5031 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | int err; |
| 5033 | |
| 5034 | do { |
| 5035 | err = nfs4_handle_exception(server, |
| 5036 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5037 | &exception); |
| 5038 | } while (exception.retry); |
| 5039 | return err; |
| 5040 | } |
| 5041 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5042 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5043 | const struct nfs_open_context *ctx, |
| 5044 | const struct nfs_lock_context *l_ctx, |
| 5045 | fmode_t fmode) |
| 5046 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5047 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5048 | } |
| 5049 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5050 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5051 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5052 | const struct nfs_open_context *ctx, |
| 5053 | const struct nfs_lock_context *l_ctx, |
| 5054 | fmode_t fmode) |
| 5055 | { |
| 5056 | nfs4_stateid current_stateid; |
| 5057 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5058 | /* If the current stateid represents a lost lock, then exit */ |
| 5059 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 5060 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5061 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 5062 | } |
| 5063 | |
| 5064 | static bool nfs4_error_stateid_expired(int err) |
| 5065 | { |
| 5066 | switch (err) { |
| 5067 | case -NFS4ERR_DELEG_REVOKED: |
| 5068 | case -NFS4ERR_ADMIN_REVOKED: |
| 5069 | case -NFS4ERR_BAD_STATEID: |
| 5070 | case -NFS4ERR_STALE_STATEID: |
| 5071 | case -NFS4ERR_OLD_STATEID: |
| 5072 | case -NFS4ERR_OPENMODE: |
| 5073 | case -NFS4ERR_EXPIRED: |
| 5074 | return true; |
| 5075 | } |
| 5076 | return false; |
| 5077 | } |
| 5078 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5079 | 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] | 5080 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5081 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5083 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5084 | if (task->tk_status < 0) { |
| 5085 | struct nfs4_exception exception = { |
| 5086 | .inode = hdr->inode, |
| 5087 | .state = hdr->args.context->state, |
| 5088 | .stateid = &hdr->args.stateid, |
| 5089 | }; |
| 5090 | task->tk_status = nfs4_async_handle_exception(task, |
| 5091 | server, task->tk_status, &exception); |
| 5092 | if (exception.retry) { |
| 5093 | rpc_restart_call_prepare(task); |
| 5094 | return -EAGAIN; |
| 5095 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5099 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5100 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5103 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5104 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5105 | { |
| 5106 | |
| 5107 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5108 | nfs4_stateid_is_current(&args->stateid, |
| 5109 | args->context, |
| 5110 | args->lock_context, |
| 5111 | FMODE_READ)) |
| 5112 | return false; |
| 5113 | rpc_restart_call_prepare(task); |
| 5114 | return true; |
| 5115 | } |
| 5116 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5117 | 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] | 5118 | { |
| 5119 | |
| 5120 | dprintk("--> %s\n", __func__); |
| 5121 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5122 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5123 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5124 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5125 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5126 | if (task->tk_status > 0) |
| 5127 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5128 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5129 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5130 | } |
| 5131 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5132 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5133 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5135 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5136 | if (!hdr->pgio_done_cb) |
| 5137 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5138 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5139 | 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] | 5140 | } |
| 5141 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5142 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5143 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5144 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5145 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5146 | &hdr->args.seq_args, |
| 5147 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5148 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5149 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5150 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5151 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5152 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5153 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5154 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5155 | return -EIO; |
| 5156 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5159 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5160 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5162 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5163 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5164 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5165 | if (task->tk_status < 0) { |
| 5166 | struct nfs4_exception exception = { |
| 5167 | .inode = hdr->inode, |
| 5168 | .state = hdr->args.context->state, |
| 5169 | .stateid = &hdr->args.stateid, |
| 5170 | }; |
| 5171 | task->tk_status = nfs4_async_handle_exception(task, |
| 5172 | NFS_SERVER(inode), task->tk_status, |
| 5173 | &exception); |
| 5174 | if (exception.retry) { |
| 5175 | rpc_restart_call_prepare(task); |
| 5176 | return -EAGAIN; |
| 5177 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5179 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5180 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5181 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5182 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5183 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5186 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5187 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5188 | { |
| 5189 | |
| 5190 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5191 | nfs4_stateid_is_current(&args->stateid, |
| 5192 | args->context, |
| 5193 | args->lock_context, |
| 5194 | FMODE_WRITE)) |
| 5195 | return false; |
| 5196 | rpc_restart_call_prepare(task); |
| 5197 | return true; |
| 5198 | } |
| 5199 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5200 | 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] | 5201 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5202 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5203 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5204 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5205 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5206 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5207 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5210 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5211 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5212 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5213 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5214 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5215 | return false; |
| 5216 | /* Otherwise, request attributes if and only if we don't hold |
| 5217 | * a delegation |
| 5218 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5219 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5220 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5221 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5222 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5223 | struct rpc_message *msg, |
| 5224 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5225 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5226 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5227 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5228 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5229 | hdr->args.bitmask = NULL; |
| 5230 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 5231 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5232 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5233 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5234 | if (!hdr->pgio_done_cb) |
| 5235 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5236 | hdr->res.server = server; |
| 5237 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5238 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5239 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5240 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1, 0); |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5241 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | } |
| 5243 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5244 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5245 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5246 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5247 | &data->args.seq_args, |
| 5248 | &data->res.seq_res, |
| 5249 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5250 | } |
| 5251 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5252 | 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] | 5253 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5255 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5256 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5257 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5258 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5259 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5260 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5262 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 | } |
| 5264 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5265 | 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] | 5266 | { |
| 5267 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5268 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5269 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5270 | } |
| 5271 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5272 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5273 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5274 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5275 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5276 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5277 | if (data->commit_done_cb == NULL) |
| 5278 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5279 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5280 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5281 | 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] | 5282 | 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] | 5283 | } |
| 5284 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5285 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5286 | struct nfs_commitres *res) |
| 5287 | { |
| 5288 | struct inode *dst_inode = file_inode(dst); |
| 5289 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5290 | struct rpc_message msg = { |
| 5291 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5292 | .rpc_argp = args, |
| 5293 | .rpc_resp = res, |
| 5294 | }; |
| 5295 | |
| 5296 | args->fh = NFS_FH(dst_inode); |
| 5297 | return nfs4_call_sync(server->client, server, &msg, |
| 5298 | &args->seq_args, &res->seq_res, 1); |
| 5299 | } |
| 5300 | |
| 5301 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5302 | { |
| 5303 | struct nfs_commitargs args = { |
| 5304 | .offset = offset, |
| 5305 | .count = count, |
| 5306 | }; |
| 5307 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5308 | struct nfs4_exception exception = { }; |
| 5309 | int status; |
| 5310 | |
| 5311 | do { |
| 5312 | status = _nfs4_proc_commit(dst, &args, res); |
| 5313 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5314 | } while (exception.retry); |
| 5315 | |
| 5316 | return status; |
| 5317 | } |
| 5318 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5319 | struct nfs4_renewdata { |
| 5320 | struct nfs_client *client; |
| 5321 | unsigned long timestamp; |
| 5322 | }; |
| 5323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | /* |
| 5325 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5326 | * standalone procedure for queueing an asynchronous RENEW. |
| 5327 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5328 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5329 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5330 | struct nfs4_renewdata *data = calldata; |
| 5331 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5332 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5333 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5334 | nfs4_schedule_state_renewal(clp); |
| 5335 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5336 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5337 | } |
| 5338 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5339 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5340 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5341 | struct nfs4_renewdata *data = calldata; |
| 5342 | struct nfs_client *clp = data->client; |
| 5343 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5345 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5346 | switch (task->tk_status) { |
| 5347 | case 0: |
| 5348 | break; |
| 5349 | case -NFS4ERR_LEASE_MOVED: |
| 5350 | nfs4_schedule_lease_moved_recovery(clp); |
| 5351 | break; |
| 5352 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5353 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5354 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5355 | return; |
| 5356 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5357 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5358 | return; |
| 5359 | } |
| 5360 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5362 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5363 | } |
| 5364 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5365 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5366 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5367 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5368 | }; |
| 5369 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5370 | 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] | 5371 | { |
| 5372 | struct rpc_message msg = { |
| 5373 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5374 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5375 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5376 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5377 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5379 | if (renew_flags == 0) |
| 5380 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5381 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5382 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5383 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5384 | if (data == NULL) { |
| 5385 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5386 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5387 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5388 | data->client = clp; |
| 5389 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5390 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5391 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5392 | } |
| 5393 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5394 | 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] | 5395 | { |
| 5396 | struct rpc_message msg = { |
| 5397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5398 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5399 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | }; |
| 5401 | unsigned long now = jiffies; |
| 5402 | int status; |
| 5403 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5404 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5405 | if (status < 0) |
| 5406 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5407 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | return 0; |
| 5409 | } |
| 5410 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5411 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5412 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5413 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5416 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5417 | * 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] | 5418 | * the stack. |
| 5419 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5420 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5421 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5422 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5423 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5424 | { |
| 5425 | struct page *newpage, **spages; |
| 5426 | int rc = 0; |
| 5427 | size_t len; |
| 5428 | spages = pages; |
| 5429 | |
| 5430 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5431 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5432 | newpage = alloc_page(GFP_KERNEL); |
| 5433 | |
| 5434 | if (newpage == NULL) |
| 5435 | goto unwind; |
| 5436 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5437 | buf += len; |
| 5438 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5439 | *pages++ = newpage; |
| 5440 | rc++; |
| 5441 | } while (buflen != 0); |
| 5442 | |
| 5443 | return rc; |
| 5444 | |
| 5445 | unwind: |
| 5446 | for(; rc > 0; rc--) |
| 5447 | __free_page(spages[rc-1]); |
| 5448 | return -ENOMEM; |
| 5449 | } |
| 5450 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5451 | struct nfs4_cached_acl { |
| 5452 | int cached; |
| 5453 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5454 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5455 | }; |
| 5456 | |
| 5457 | 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] | 5458 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5459 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5460 | |
| 5461 | spin_lock(&inode->i_lock); |
| 5462 | kfree(nfsi->nfs4_acl); |
| 5463 | nfsi->nfs4_acl = acl; |
| 5464 | spin_unlock(&inode->i_lock); |
| 5465 | } |
| 5466 | |
| 5467 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5468 | { |
| 5469 | nfs4_set_cached_acl(inode, NULL); |
| 5470 | } |
| 5471 | |
| 5472 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5473 | { |
| 5474 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5475 | struct nfs4_cached_acl *acl; |
| 5476 | int ret = -ENOENT; |
| 5477 | |
| 5478 | spin_lock(&inode->i_lock); |
| 5479 | acl = nfsi->nfs4_acl; |
| 5480 | if (acl == NULL) |
| 5481 | goto out; |
| 5482 | if (buf == NULL) /* user is just asking for length */ |
| 5483 | goto out_len; |
| 5484 | if (acl->cached == 0) |
| 5485 | goto out; |
| 5486 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5487 | if (acl->len > buflen) |
| 5488 | goto out; |
| 5489 | memcpy(buf, acl->data, acl->len); |
| 5490 | out_len: |
| 5491 | ret = acl->len; |
| 5492 | out: |
| 5493 | spin_unlock(&inode->i_lock); |
| 5494 | return ret; |
| 5495 | } |
| 5496 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5497 | 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] | 5498 | { |
| 5499 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5500 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5501 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5502 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5503 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5504 | if (acl == NULL) |
| 5505 | goto out; |
| 5506 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5507 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5508 | } else { |
| 5509 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5510 | if (acl == NULL) |
| 5511 | goto out; |
| 5512 | acl->cached = 0; |
| 5513 | } |
| 5514 | acl->len = acl_len; |
| 5515 | out: |
| 5516 | nfs4_set_cached_acl(inode, acl); |
| 5517 | } |
| 5518 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5519 | /* |
| 5520 | * The getxattr API returns the required buffer length when called with a |
| 5521 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5522 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5523 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5524 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5525 | * the cache. If not so, we throw away the page, and cache the required |
| 5526 | * length. The next getxattr call will then produce another round trip to |
| 5527 | * the server, this time with the input buf of the required size. |
| 5528 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5529 | 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] | 5530 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5531 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5532 | struct nfs_getaclargs args = { |
| 5533 | .fh = NFS_FH(inode), |
| 5534 | .acl_pages = pages, |
| 5535 | .acl_len = buflen, |
| 5536 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5537 | struct nfs_getaclres res = { |
| 5538 | .acl_len = buflen, |
| 5539 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5540 | struct rpc_message msg = { |
| 5541 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5542 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5543 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5544 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5545 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5546 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5547 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5548 | if (npages > ARRAY_SIZE(pages)) |
| 5549 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5550 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5551 | for (i = 0; i < npages; i++) { |
| 5552 | pages[i] = alloc_page(GFP_KERNEL); |
| 5553 | if (!pages[i]) |
| 5554 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5555 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5556 | |
| 5557 | /* for decoding across pages */ |
| 5558 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5559 | if (!res.acl_scratch) |
| 5560 | goto out_free; |
| 5561 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5562 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5563 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5564 | 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] | 5565 | __func__, buf, buflen, npages, args.acl_len); |
| 5566 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5567 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5568 | if (ret) |
| 5569 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5570 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5571 | /* Handle the case where the passed-in buffer is too short */ |
| 5572 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5573 | /* Did the user only issue a request for the acl length? */ |
| 5574 | if (buf == NULL) |
| 5575 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5576 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5577 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5578 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5579 | 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] | 5580 | if (buf) { |
| 5581 | if (res.acl_len > buflen) { |
| 5582 | ret = -ERANGE; |
| 5583 | goto out_free; |
| 5584 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5585 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5586 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5587 | out_ok: |
| 5588 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5589 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5590 | for (i = 0; i < npages; i++) |
| 5591 | if (pages[i]) |
| 5592 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5593 | if (res.acl_scratch) |
| 5594 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5595 | return ret; |
| 5596 | } |
| 5597 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5598 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5599 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5600 | struct nfs4_exception exception = { |
| 5601 | .interruptible = true, |
| 5602 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5603 | ssize_t ret; |
| 5604 | do { |
| 5605 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5606 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5607 | if (ret >= 0) |
| 5608 | break; |
| 5609 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5610 | } while (exception.retry); |
| 5611 | return ret; |
| 5612 | } |
| 5613 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5614 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5615 | { |
| 5616 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5617 | int ret; |
| 5618 | |
| 5619 | if (!nfs4_server_supports_acls(server)) |
| 5620 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5621 | ret = nfs_revalidate_inode(server, inode); |
| 5622 | if (ret < 0) |
| 5623 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5624 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5625 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5626 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5627 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5628 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5629 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5630 | return ret; |
| 5631 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5632 | } |
| 5633 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5634 | 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] | 5635 | { |
| 5636 | struct nfs_server *server = NFS_SERVER(inode); |
| 5637 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5638 | struct nfs_setaclargs arg = { |
| 5639 | .fh = NFS_FH(inode), |
| 5640 | .acl_pages = pages, |
| 5641 | .acl_len = buflen, |
| 5642 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5643 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5644 | struct rpc_message msg = { |
| 5645 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5646 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5647 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5648 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5649 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5650 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5651 | |
| 5652 | if (!nfs4_server_supports_acls(server)) |
| 5653 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5654 | if (npages > ARRAY_SIZE(pages)) |
| 5655 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5656 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5657 | if (i < 0) |
| 5658 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5659 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5660 | 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] | 5661 | |
| 5662 | /* |
| 5663 | * Free each page after tx, so the only ref left is |
| 5664 | * held by the network stack |
| 5665 | */ |
| 5666 | for (; i > 0; i--) |
| 5667 | put_page(pages[i-1]); |
| 5668 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5669 | /* |
| 5670 | * Acl update can result in inode attribute update. |
| 5671 | * so mark the attribute cache invalid. |
| 5672 | */ |
| 5673 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5674 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5675 | | NFS_INO_INVALID_CTIME |
| 5676 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5677 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5678 | nfs_access_zap_cache(inode); |
| 5679 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5680 | return ret; |
| 5681 | } |
| 5682 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5683 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5684 | { |
| 5685 | struct nfs4_exception exception = { }; |
| 5686 | int err; |
| 5687 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5688 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5689 | trace_nfs4_set_acl(inode, err); |
| 5690 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5691 | &exception); |
| 5692 | } while (exception.retry); |
| 5693 | return err; |
| 5694 | } |
| 5695 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5696 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5697 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5698 | size_t buflen) |
| 5699 | { |
| 5700 | struct nfs_server *server = NFS_SERVER(inode); |
| 5701 | struct nfs_fattr fattr; |
| 5702 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5703 | |
| 5704 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5705 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5706 | .fh = NFS_FH(inode), |
| 5707 | .bitmask = bitmask, |
| 5708 | }; |
| 5709 | struct nfs4_getattr_res res = { |
| 5710 | .fattr = &fattr, |
| 5711 | .label = &label, |
| 5712 | .server = server, |
| 5713 | }; |
| 5714 | struct rpc_message msg = { |
| 5715 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5716 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5717 | .rpc_resp = &res, |
| 5718 | }; |
| 5719 | int ret; |
| 5720 | |
| 5721 | nfs_fattr_init(&fattr); |
| 5722 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5723 | 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] | 5724 | if (ret) |
| 5725 | return ret; |
| 5726 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5727 | return -ENOENT; |
| 5728 | if (buflen < label.len) |
| 5729 | return -ERANGE; |
| 5730 | return 0; |
| 5731 | } |
| 5732 | |
| 5733 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5734 | size_t buflen) |
| 5735 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5736 | struct nfs4_exception exception = { |
| 5737 | .interruptible = true, |
| 5738 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5739 | int err; |
| 5740 | |
| 5741 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5742 | return -EOPNOTSUPP; |
| 5743 | |
| 5744 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5745 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5746 | trace_nfs4_get_security_label(inode, err); |
| 5747 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5748 | &exception); |
| 5749 | } while (exception.retry); |
| 5750 | return err; |
| 5751 | } |
| 5752 | |
| 5753 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5754 | struct nfs4_label *ilabel, |
| 5755 | struct nfs_fattr *fattr, |
| 5756 | struct nfs4_label *olabel) |
| 5757 | { |
| 5758 | |
| 5759 | struct iattr sattr = {0}; |
| 5760 | struct nfs_server *server = NFS_SERVER(inode); |
| 5761 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5762 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5763 | .fh = NFS_FH(inode), |
| 5764 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5765 | .server = server, |
| 5766 | .bitmask = bitmask, |
| 5767 | .label = ilabel, |
| 5768 | }; |
| 5769 | struct nfs_setattrres res = { |
| 5770 | .fattr = fattr, |
| 5771 | .label = olabel, |
| 5772 | .server = server, |
| 5773 | }; |
| 5774 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5775 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5776 | .rpc_argp = &arg, |
| 5777 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5778 | }; |
| 5779 | int status; |
| 5780 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5781 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5782 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5783 | 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] | 5784 | if (status) |
| 5785 | dprintk("%s failed: %d\n", __func__, status); |
| 5786 | |
| 5787 | return status; |
| 5788 | } |
| 5789 | |
| 5790 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5791 | struct nfs4_label *ilabel, |
| 5792 | struct nfs_fattr *fattr, |
| 5793 | struct nfs4_label *olabel) |
| 5794 | { |
| 5795 | struct nfs4_exception exception = { }; |
| 5796 | int err; |
| 5797 | |
| 5798 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5799 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5800 | fattr, olabel); |
| 5801 | trace_nfs4_set_security_label(inode, err); |
| 5802 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5803 | &exception); |
| 5804 | } while (exception.retry); |
| 5805 | return err; |
| 5806 | } |
| 5807 | |
| 5808 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5809 | 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] | 5810 | { |
| 5811 | struct nfs4_label ilabel, *olabel = NULL; |
| 5812 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5813 | int status; |
| 5814 | |
| 5815 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5816 | return -EOPNOTSUPP; |
| 5817 | |
| 5818 | nfs_fattr_init(&fattr); |
| 5819 | |
| 5820 | ilabel.pi = 0; |
| 5821 | ilabel.lfs = 0; |
| 5822 | ilabel.label = (char *)buf; |
| 5823 | ilabel.len = buflen; |
| 5824 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5825 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5826 | if (IS_ERR(olabel)) { |
| 5827 | status = -PTR_ERR(olabel); |
| 5828 | goto out; |
| 5829 | } |
| 5830 | |
| 5831 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5832 | if (status == 0) |
| 5833 | nfs_setsecurity(inode, &fattr, olabel); |
| 5834 | |
| 5835 | nfs4_label_free(olabel); |
| 5836 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5837 | return status; |
| 5838 | } |
| 5839 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5840 | |
| 5841 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5842 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5843 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5844 | { |
| 5845 | __be32 verf[2]; |
| 5846 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5847 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5848 | /* An impossible timestamp guarantees this value |
| 5849 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5850 | verf[0] = cpu_to_be32(U32_MAX); |
| 5851 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5852 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5853 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5854 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5855 | |
| 5856 | verf[0] = cpu_to_be32(ns >> 32); |
| 5857 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5858 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5859 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5860 | } |
| 5861 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5862 | static int |
| 5863 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5864 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5865 | size_t len; |
| 5866 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5867 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5868 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5869 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5870 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5871 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5872 | len = 14 + |
| 5873 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 5874 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5875 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5876 | 1; |
| 5877 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5878 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 5879 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5880 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5881 | return -EINVAL; |
| 5882 | |
| 5883 | /* |
| 5884 | * Since this string is allocated at mount time, and held until the |
| 5885 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5886 | * about a memory-reclaim deadlock. |
| 5887 | */ |
| 5888 | str = kmalloc(len, GFP_KERNEL); |
| 5889 | if (!str) |
| 5890 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5891 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5892 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5893 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5894 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5895 | clp->cl_rpcclient->cl_nodename, |
| 5896 | nfs4_client_id_uniquifier, |
| 5897 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5898 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5899 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5900 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5901 | clp->cl_rpcclient->cl_nodename, |
| 5902 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5903 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5904 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5905 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5906 | clp->cl_owner_id = str; |
| 5907 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5908 | } |
| 5909 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5910 | static int |
| 5911 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5912 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5913 | size_t len; |
| 5914 | char *str; |
| 5915 | |
| 5916 | len = 10 + 10 + 1 + 10 + 1 + |
| 5917 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5918 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5919 | |
| 5920 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5921 | return -EINVAL; |
| 5922 | |
| 5923 | /* |
| 5924 | * Since this string is allocated at mount time, and held until the |
| 5925 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5926 | * about a memory-reclaim deadlock. |
| 5927 | */ |
| 5928 | str = kmalloc(len, GFP_KERNEL); |
| 5929 | if (!str) |
| 5930 | return -ENOMEM; |
| 5931 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5932 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5933 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5934 | nfs4_client_id_uniquifier, |
| 5935 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5936 | clp->cl_owner_id = str; |
| 5937 | return 0; |
| 5938 | } |
| 5939 | |
| 5940 | static int |
| 5941 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5942 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5943 | size_t len; |
| 5944 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5945 | |
| 5946 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5947 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5948 | |
| 5949 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5950 | return nfs4_init_uniquifier_client_string(clp); |
| 5951 | |
| 5952 | len = 10 + 10 + 1 + 10 + 1 + |
| 5953 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5954 | |
| 5955 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5956 | return -EINVAL; |
| 5957 | |
| 5958 | /* |
| 5959 | * Since this string is allocated at mount time, and held until the |
| 5960 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5961 | * about a memory-reclaim deadlock. |
| 5962 | */ |
| 5963 | str = kmalloc(len, GFP_KERNEL); |
| 5964 | if (!str) |
| 5965 | return -ENOMEM; |
| 5966 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5967 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5968 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5969 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5970 | clp->cl_owner_id = str; |
| 5971 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5972 | } |
| 5973 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5974 | /* |
| 5975 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5976 | * services. Advertise one based on the address family of the |
| 5977 | * clientaddr. |
| 5978 | */ |
| 5979 | static unsigned int |
| 5980 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5981 | { |
| 5982 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5983 | return scnprintf(buf, len, "tcp6"); |
| 5984 | else |
| 5985 | return scnprintf(buf, len, "tcp"); |
| 5986 | } |
| 5987 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5988 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5989 | { |
| 5990 | struct nfs4_setclientid *sc = calldata; |
| 5991 | |
| 5992 | if (task->tk_status == 0) |
| 5993 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5994 | } |
| 5995 | |
| 5996 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5997 | .rpc_call_done = nfs4_setclientid_done, |
| 5998 | }; |
| 5999 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6000 | /** |
| 6001 | * nfs4_proc_setclientid - Negotiate client ID |
| 6002 | * @clp: state data structure |
| 6003 | * @program: RPC program for NFSv4 callback service |
| 6004 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6005 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6006 | * @res: where to place the result |
| 6007 | * |
| 6008 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6009 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6010 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6011 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6012 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | { |
| 6014 | nfs4_verifier sc_verifier; |
| 6015 | struct nfs4_setclientid setclientid = { |
| 6016 | .sc_verifier = &sc_verifier, |
| 6017 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6018 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | }; |
| 6020 | struct rpc_message msg = { |
| 6021 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6022 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6023 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6024 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6025 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6026 | struct rpc_task_setup task_setup_data = { |
| 6027 | .rpc_client = clp->cl_rpcclient, |
| 6028 | .rpc_message = &msg, |
| 6029 | .callback_ops = &nfs4_setclientid_ops, |
| 6030 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6031 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6032 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6033 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6034 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6035 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6036 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6037 | |
| 6038 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6039 | status = nfs4_init_uniform_client_string(clp); |
| 6040 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6041 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6042 | |
| 6043 | if (status) |
| 6044 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6045 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6046 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6047 | setclientid.sc_netid_len = |
| 6048 | nfs4_init_callback_netid(clp, |
| 6049 | setclientid.sc_netid, |
| 6050 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6051 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6052 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6053 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6054 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6055 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6056 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6057 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6058 | |
| 6059 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6060 | if (setclientid.sc_cred) { |
| 6061 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6062 | put_rpccred(setclientid.sc_cred); |
| 6063 | } |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6064 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6065 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6066 | dprintk("NFS reply setclientid: %d\n", status); |
| 6067 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6068 | } |
| 6069 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6070 | /** |
| 6071 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6072 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6073 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6074 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6075 | * |
| 6076 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6077 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6078 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6079 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6080 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6081 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6082 | struct rpc_message msg = { |
| 6083 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6084 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6085 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6086 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | int status; |
| 6088 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6089 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6090 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6091 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6092 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6093 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6094 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6095 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6096 | return status; |
| 6097 | } |
| 6098 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6099 | struct nfs4_delegreturndata { |
| 6100 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6101 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6102 | struct nfs_fh fh; |
| 6103 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6104 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6105 | struct { |
| 6106 | struct nfs4_layoutreturn_args arg; |
| 6107 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6108 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6109 | u32 roc_barrier; |
| 6110 | bool roc; |
| 6111 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6112 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6113 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6114 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6115 | }; |
| 6116 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6117 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6118 | { |
| 6119 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6120 | struct nfs4_exception exception = { |
| 6121 | .inode = data->inode, |
| 6122 | .stateid = &data->stateid, |
| 6123 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6124 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6125 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6126 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6127 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6128 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6129 | |
| 6130 | /* Handle Layoutreturn errors */ |
| 6131 | if (data->args.lr_args && task->tk_status != 0) { |
| 6132 | switch(data->res.lr_ret) { |
| 6133 | default: |
| 6134 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 6135 | break; |
| 6136 | case 0: |
| 6137 | data->args.lr_args = NULL; |
| 6138 | data->res.lr_res = NULL; |
| 6139 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 6140 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | c16467d | 2018-07-29 22:39:15 -0400 | [diff] [blame] | 6141 | if (nfs4_layoutreturn_refresh_stateid(&data->args.lr_args->stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 6142 | &data->args.lr_args->range, |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6143 | data->inode)) |
| 6144 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 6145 | /* Fallthrough */ |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6146 | case -NFS4ERR_ADMIN_REVOKED: |
| 6147 | case -NFS4ERR_DELEG_REVOKED: |
| 6148 | case -NFS4ERR_EXPIRED: |
| 6149 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6150 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 6151 | case -NFS4ERR_WRONG_CRED: |
| 6152 | data->args.lr_args = NULL; |
| 6153 | data->res.lr_res = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6154 | goto lr_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6155 | } |
| 6156 | } |
| 6157 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6158 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6159 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6160 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6161 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6162 | case -NFS4ERR_ADMIN_REVOKED: |
| 6163 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6164 | case -NFS4ERR_EXPIRED: |
| 6165 | nfs4_free_revoked_stateid(data->res.server, |
| 6166 | data->args.stateid, |
| 6167 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6168 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6169 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6170 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6171 | task->tk_status = 0; |
| 6172 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6173 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6174 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6175 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6176 | task->tk_status = 0; |
| 6177 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6178 | case -NFS4ERR_ACCESS: |
| 6179 | if (data->args.bitmask) { |
| 6180 | data->args.bitmask = NULL; |
| 6181 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6182 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6183 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6184 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6185 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6186 | task->tk_status = nfs4_async_handle_exception(task, |
| 6187 | data->res.server, task->tk_status, |
| 6188 | &exception); |
| 6189 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6190 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6191 | } |
| 6192 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6193 | return; |
| 6194 | lr_restart: |
| 6195 | data->res.lr_ret = 0; |
| 6196 | out_restart: |
| 6197 | task->tk_status = 0; |
| 6198 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | static void nfs4_delegreturn_release(void *calldata) |
| 6202 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6203 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6204 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6205 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6206 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6207 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6208 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6209 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6210 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6211 | nfs_iput_and_deactive(inode); |
| 6212 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6213 | kfree(calldata); |
| 6214 | } |
| 6215 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6216 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6217 | { |
| 6218 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6219 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6220 | |
| 6221 | d_data = (struct nfs4_delegreturndata *)data; |
| 6222 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6223 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 6224 | return; |
| 6225 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6226 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6227 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6228 | d_data->args.lr_args = NULL; |
| 6229 | d_data->res.lr_res = NULL; |
| 6230 | } |
| 6231 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6232 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6233 | &d_data->args.seq_args, |
| 6234 | &d_data->res.seq_res, |
| 6235 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6236 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6237 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6238 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6239 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6240 | .rpc_call_done = nfs4_delegreturn_done, |
| 6241 | .rpc_release = nfs4_delegreturn_release, |
| 6242 | }; |
| 6243 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6244 | 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] | 6245 | { |
| 6246 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6247 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6248 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6249 | struct rpc_message msg = { |
| 6250 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6251 | .rpc_cred = cred, |
| 6252 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6253 | struct rpc_task_setup task_setup_data = { |
| 6254 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6255 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6256 | .callback_ops = &nfs4_delegreturn_ops, |
| 6257 | .flags = RPC_TASK_ASYNC, |
| 6258 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6259 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6260 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6261 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6262 | if (data == NULL) |
| 6263 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6264 | 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] | 6265 | |
| 6266 | nfs4_state_protect(server->nfs_client, |
| 6267 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6268 | &task_setup_data.rpc_client, &msg); |
| 6269 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6270 | data->args.fhandle = &data->fh; |
| 6271 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6272 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6273 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6274 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6275 | data->res.fattr = &data->fattr; |
| 6276 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6277 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6278 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6279 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6280 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6281 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6282 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, cred); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6283 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6284 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6285 | if (data->lr.roc) { |
| 6286 | data->args.lr_args = &data->lr.arg; |
| 6287 | data->res.lr_res = &data->lr.res; |
| 6288 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6289 | } else if (data->lr.roc) { |
| 6290 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6291 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6292 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6293 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6294 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6295 | msg.rpc_argp = &data->args; |
| 6296 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6297 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6298 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6299 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6300 | if (!issync) |
| 6301 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6302 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6303 | if (status != 0) |
| 6304 | goto out; |
| 6305 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6306 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6307 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6308 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | } |
| 6310 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6311 | 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] | 6312 | { |
| 6313 | struct nfs_server *server = NFS_SERVER(inode); |
| 6314 | struct nfs4_exception exception = { }; |
| 6315 | int err; |
| 6316 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6317 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6318 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6319 | switch (err) { |
| 6320 | case -NFS4ERR_STALE_STATEID: |
| 6321 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | case 0: |
| 6323 | return 0; |
| 6324 | } |
| 6325 | err = nfs4_handle_exception(server, err, &exception); |
| 6326 | } while (exception.retry); |
| 6327 | return err; |
| 6328 | } |
| 6329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6330 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6331 | { |
| 6332 | struct inode *inode = state->inode; |
| 6333 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6334 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6335 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6337 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6338 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6339 | struct nfs_lockt_res res = { |
| 6340 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | }; |
| 6342 | struct rpc_message msg = { |
| 6343 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6344 | .rpc_argp = &arg, |
| 6345 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6346 | .rpc_cred = state->owner->so_cred, |
| 6347 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6348 | struct nfs4_lock_state *lsp; |
| 6349 | int status; |
| 6350 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6351 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6352 | status = nfs4_set_lock_state(state, request); |
| 6353 | if (status != 0) |
| 6354 | goto out; |
| 6355 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6356 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6357 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6358 | 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] | 6359 | switch (status) { |
| 6360 | case 0: |
| 6361 | request->fl_type = F_UNLCK; |
| 6362 | break; |
| 6363 | case -NFS4ERR_DENIED: |
| 6364 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6365 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6366 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6367 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6368 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6369 | return status; |
| 6370 | } |
| 6371 | |
| 6372 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6373 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6374 | struct nfs4_exception exception = { |
| 6375 | .interruptible = true, |
| 6376 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6377 | int err; |
| 6378 | |
| 6379 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6380 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6381 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6382 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6383 | &exception); |
| 6384 | } while (exception.retry); |
| 6385 | return err; |
| 6386 | } |
| 6387 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6388 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6389 | struct nfs_locku_args arg; |
| 6390 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6391 | struct nfs4_lock_state *lsp; |
| 6392 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6393 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6394 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6395 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6396 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6397 | }; |
| 6398 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6399 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6400 | struct nfs_open_context *ctx, |
| 6401 | struct nfs4_lock_state *lsp, |
| 6402 | struct nfs_seqid *seqid) |
| 6403 | { |
| 6404 | struct nfs4_unlockdata *p; |
| 6405 | struct inode *inode = lsp->ls_state->inode; |
| 6406 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6407 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6408 | if (p == NULL) |
| 6409 | return NULL; |
| 6410 | p->arg.fh = NFS_FH(inode); |
| 6411 | p->arg.fl = &p->fl; |
| 6412 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6413 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6414 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6415 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6416 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6417 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6418 | locks_init_lock(&p->fl); |
| 6419 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6420 | p->server = NFS_SERVER(inode); |
| 6421 | return p; |
| 6422 | } |
| 6423 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6424 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6425 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6426 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6427 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6428 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6429 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6430 | put_nfs_open_context(calldata->ctx); |
| 6431 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6434 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6435 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6436 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6437 | struct nfs4_exception exception = { |
| 6438 | .inode = calldata->lsp->ls_state->inode, |
| 6439 | .stateid = &calldata->arg.stateid, |
| 6440 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6441 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6442 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6443 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6444 | switch (task->tk_status) { |
| 6445 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6446 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6447 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6448 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6449 | &calldata->res.stateid)) |
| 6450 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6451 | /* Fall through */ |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6452 | case -NFS4ERR_ADMIN_REVOKED: |
| 6453 | case -NFS4ERR_EXPIRED: |
| 6454 | nfs4_free_revoked_stateid(calldata->server, |
| 6455 | &calldata->arg.stateid, |
| 6456 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6457 | /* Fall through */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6458 | case -NFS4ERR_BAD_STATEID: |
| 6459 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6460 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6461 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 6462 | &calldata->lsp->ls_stateid)) |
| 6463 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6464 | break; |
| 6465 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6466 | task->tk_status = nfs4_async_handle_exception(task, |
| 6467 | calldata->server, task->tk_status, |
| 6468 | &exception); |
| 6469 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6470 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6471 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6472 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6473 | } |
| 6474 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6475 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6476 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6477 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6478 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6479 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6480 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6481 | return; |
| 6482 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6483 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6484 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6485 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6486 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6487 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6488 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6489 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6490 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6491 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6492 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6493 | &calldata->res.seq_res, |
| 6494 | task) != 0) |
| 6495 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6496 | return; |
| 6497 | out_no_action: |
| 6498 | task->tk_action = NULL; |
| 6499 | out_wait: |
| 6500 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6501 | } |
| 6502 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6503 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6504 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6505 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6506 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6507 | }; |
| 6508 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6509 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6510 | struct nfs_open_context *ctx, |
| 6511 | struct nfs4_lock_state *lsp, |
| 6512 | struct nfs_seqid *seqid) |
| 6513 | { |
| 6514 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6515 | struct rpc_message msg = { |
| 6516 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6517 | .rpc_cred = ctx->cred, |
| 6518 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6519 | struct rpc_task_setup task_setup_data = { |
| 6520 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6521 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6522 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6523 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6524 | .flags = RPC_TASK_ASYNC, |
| 6525 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6526 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6527 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6528 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6529 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6530 | /* Ensure this is an unlock - when canceling a lock, the |
| 6531 | * canceled lock is passed in, and it won't be an unlock. |
| 6532 | */ |
| 6533 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6534 | if (fl->fl_flags & FL_CLOSE) |
| 6535 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6536 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6537 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6538 | if (data == NULL) { |
| 6539 | nfs_free_seqid(seqid); |
| 6540 | return ERR_PTR(-ENOMEM); |
| 6541 | } |
| 6542 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6543 | 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] | 6544 | msg.rpc_argp = &data->arg; |
| 6545 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6546 | task_setup_data.callback_data = data; |
| 6547 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6548 | } |
| 6549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6550 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6551 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6552 | struct inode *inode = state->inode; |
| 6553 | struct nfs4_state_owner *sp = state->owner; |
| 6554 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6555 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6556 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6557 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6558 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6559 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6560 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6561 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6562 | status = nfs4_set_lock_state(state, request); |
| 6563 | /* Unlock _before_ we do the RPC call */ |
| 6564 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6565 | /* Exclude nfs_delegation_claim_locks() */ |
| 6566 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6567 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6568 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6569 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6570 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6571 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6572 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6573 | } |
| 6574 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6575 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6576 | if (status != 0) |
| 6577 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6578 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6579 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6580 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6581 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6582 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6583 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6584 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6585 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6586 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6587 | 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] | 6588 | status = PTR_ERR(task); |
| 6589 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6590 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6591 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6592 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6593 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6594 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6595 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6596 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6597 | } |
| 6598 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6599 | struct nfs4_lockdata { |
| 6600 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6601 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6602 | struct nfs4_lock_state *lsp; |
| 6603 | struct nfs_open_context *ctx; |
| 6604 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6605 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6606 | int rpc_status; |
| 6607 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6608 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6609 | }; |
| 6610 | |
| 6611 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6612 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6613 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6614 | { |
| 6615 | struct nfs4_lockdata *p; |
| 6616 | struct inode *inode = lsp->ls_state->inode; |
| 6617 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6618 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6619 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6620 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6621 | if (p == NULL) |
| 6622 | return NULL; |
| 6623 | |
| 6624 | p->arg.fh = NFS_FH(inode); |
| 6625 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6626 | 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] | 6627 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6628 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6629 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6630 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6631 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6632 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6633 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6634 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6635 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6636 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6637 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6638 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6639 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6640 | locks_init_lock(&p->fl); |
| 6641 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6642 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6643 | out_free_seqid: |
| 6644 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6645 | out_free: |
| 6646 | kfree(p); |
| 6647 | return NULL; |
| 6648 | } |
| 6649 | |
| 6650 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6651 | { |
| 6652 | struct nfs4_lockdata *data = calldata; |
| 6653 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6654 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6655 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6656 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6657 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6658 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6659 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6660 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6661 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6662 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6663 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6664 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6665 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6666 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6667 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6668 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6669 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6670 | &data->lsp->ls_stateid); |
| 6671 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6672 | if (!nfs4_valid_open_stateid(state)) { |
| 6673 | data->rpc_status = -EBADF; |
| 6674 | task->tk_action = NULL; |
| 6675 | goto out_release_open_seqid; |
| 6676 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6677 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6678 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6679 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6680 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6681 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6682 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6683 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6684 | nfs_release_seqid(data->arg.open_seqid); |
| 6685 | out_release_lock_seqid: |
| 6686 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6687 | out_wait: |
| 6688 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6689 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6690 | } |
| 6691 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6692 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6693 | { |
| 6694 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6695 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6696 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6697 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6698 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6699 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6700 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6701 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6702 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6703 | switch (task->tk_status) { |
| 6704 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6705 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6706 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6707 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6708 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6709 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6710 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6711 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6712 | if (data->arg.new_lock_owner != 0) { |
| 6713 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6714 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6715 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6716 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6717 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6718 | break; |
| 6719 | case -NFS4ERR_BAD_STATEID: |
| 6720 | case -NFS4ERR_OLD_STATEID: |
| 6721 | case -NFS4ERR_STALE_STATEID: |
| 6722 | case -NFS4ERR_EXPIRED: |
| 6723 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6724 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6725 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6726 | goto out_restart; |
| 6727 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6728 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6729 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6730 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6731 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6732 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6733 | return; |
| 6734 | out_restart: |
| 6735 | if (!data->cancelled) |
| 6736 | rpc_restart_call_prepare(task); |
| 6737 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | static void nfs4_lock_release(void *calldata) |
| 6741 | { |
| 6742 | struct nfs4_lockdata *data = calldata; |
| 6743 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6744 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6745 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6746 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6747 | struct rpc_task *task; |
| 6748 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6749 | data->arg.lock_seqid); |
| 6750 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6751 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6752 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6753 | } else |
| 6754 | nfs_free_seqid(data->arg.lock_seqid); |
| 6755 | nfs4_put_lock_state(data->lsp); |
| 6756 | put_nfs_open_context(data->ctx); |
| 6757 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6758 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6762 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6763 | .rpc_call_done = nfs4_lock_done, |
| 6764 | .rpc_release = nfs4_lock_release, |
| 6765 | }; |
| 6766 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6767 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6768 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6769 | switch (error) { |
| 6770 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6771 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6772 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6773 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6774 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6775 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6776 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6777 | break; |
| 6778 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6779 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6780 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6781 | }; |
| 6782 | } |
| 6783 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6784 | 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] | 6785 | { |
| 6786 | struct nfs4_lockdata *data; |
| 6787 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6788 | struct rpc_message msg = { |
| 6789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6790 | .rpc_cred = state->owner->so_cred, |
| 6791 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6792 | struct rpc_task_setup task_setup_data = { |
| 6793 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6794 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6795 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6796 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6797 | .flags = RPC_TASK_ASYNC, |
| 6798 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6799 | int ret; |
| 6800 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6801 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6802 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6803 | fl->fl_u.nfs4_fl.owner, |
| 6804 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6805 | if (data == NULL) |
| 6806 | return -ENOMEM; |
| 6807 | if (IS_SETLKW(cmd)) |
| 6808 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6809 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 6810 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6811 | msg.rpc_argp = &data->arg; |
| 6812 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6813 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6814 | if (recovery_type > NFS_LOCK_NEW) { |
| 6815 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6816 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6817 | } else |
| 6818 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6819 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6820 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6821 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6822 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6823 | if (ret == 0) { |
| 6824 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6825 | if (ret) |
| 6826 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6827 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6828 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6829 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6830 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6831 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6832 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6833 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6834 | } |
| 6835 | |
| 6836 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6837 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6838 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6839 | struct nfs4_exception exception = { |
| 6840 | .inode = state->inode, |
| 6841 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6842 | int err; |
| 6843 | |
| 6844 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6845 | /* Cache the lock if possible... */ |
| 6846 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6847 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6848 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6849 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6850 | break; |
| 6851 | nfs4_handle_exception(server, err, &exception); |
| 6852 | } while (exception.retry); |
| 6853 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6854 | } |
| 6855 | |
| 6856 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6857 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6858 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6859 | struct nfs4_exception exception = { |
| 6860 | .inode = state->inode, |
| 6861 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6862 | int err; |
| 6863 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6864 | err = nfs4_set_lock_state(state, request); |
| 6865 | if (err != 0) |
| 6866 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6867 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6868 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6869 | return 0; |
| 6870 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6871 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6872 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6873 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6874 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6875 | switch (err) { |
| 6876 | default: |
| 6877 | goto out; |
| 6878 | case -NFS4ERR_GRACE: |
| 6879 | case -NFS4ERR_DELAY: |
| 6880 | nfs4_handle_exception(server, err, &exception); |
| 6881 | err = 0; |
| 6882 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6883 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6884 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6885 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6886 | } |
| 6887 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6888 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6889 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6890 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6891 | struct nfs4_lock_state *lsp; |
| 6892 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6893 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6894 | status = nfs4_set_lock_state(state, request); |
| 6895 | if (status != 0) |
| 6896 | return status; |
| 6897 | lsp = request->fl_u.nfs4_fl.owner; |
| 6898 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6899 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6900 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6901 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6902 | } |
| 6903 | #endif |
| 6904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6905 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6906 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6907 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6908 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6909 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6910 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6911 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6912 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6913 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6914 | if (status < 0) |
| 6915 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6916 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6917 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6918 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6919 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6920 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6921 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6922 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6923 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6924 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6925 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6926 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6927 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6928 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6929 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6930 | out: |
| 6931 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6932 | return status; |
| 6933 | } |
| 6934 | |
| 6935 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6936 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6937 | struct nfs4_exception exception = { |
| 6938 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6939 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6940 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6941 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6942 | int err; |
| 6943 | |
| 6944 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6945 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6946 | if (err == -NFS4ERR_DENIED) |
| 6947 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6948 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6949 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6950 | } while (exception.retry); |
| 6951 | return err; |
| 6952 | } |
| 6953 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6954 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6955 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6956 | |
| 6957 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6958 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6959 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6960 | { |
| 6961 | int status = -ERESTARTSYS; |
| 6962 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6963 | |
| 6964 | while(!signalled()) { |
| 6965 | status = nfs4_proc_setlk(state, cmd, request); |
| 6966 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6967 | break; |
| 6968 | freezable_schedule_timeout_interruptible(timeout); |
| 6969 | timeout *= 2; |
| 6970 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6971 | status = -ERESTARTSYS; |
| 6972 | } |
| 6973 | return status; |
| 6974 | } |
| 6975 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6976 | #ifdef CONFIG_NFS_V4_1 |
| 6977 | struct nfs4_lock_waiter { |
| 6978 | struct task_struct *task; |
| 6979 | struct inode *inode; |
| 6980 | struct nfs_lowner *owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6981 | }; |
| 6982 | |
| 6983 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6984 | 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] | 6985 | { |
| 6986 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6987 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6988 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6989 | /* NULL key means to wake up everyone */ |
| 6990 | if (key) { |
| 6991 | struct cb_notify_lock_args *cbnl = key; |
| 6992 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6993 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6994 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6995 | /* Only wake if the callback was for the same owner. */ |
| 6996 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 6997 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6998 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6999 | /* Make sure it's for the right inode */ |
| 7000 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7001 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7002 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7003 | |
| 7004 | /* override "private" so we can use default_wake_function */ |
| 7005 | wait->private = waiter->task; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7006 | ret = woken_wake_function(wait, mode, flags, key); |
| 7007 | if (ret) |
| 7008 | list_del_init(&wait->entry); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7009 | wait->private = waiter; |
| 7010 | return ret; |
| 7011 | } |
| 7012 | |
| 7013 | static int |
| 7014 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7015 | { |
| 7016 | int status = -ERESTARTSYS; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7017 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7018 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7019 | struct nfs_client *clp = server->nfs_client; |
| 7020 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 7021 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 7022 | .id = lsp->ls_seqid.owner_id, |
| 7023 | .s_dev = server->s_dev }; |
| 7024 | struct nfs4_lock_waiter waiter = { .task = current, |
| 7025 | .inode = state->inode, |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7026 | .owner = &owner}; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7027 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7028 | |
| 7029 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7030 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7031 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7032 | |
| 7033 | init_wait(&wait); |
| 7034 | wait.private = &waiter; |
| 7035 | wait.func = nfs4_wake_lock_waiter; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7036 | |
| 7037 | while(!signalled()) { |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7038 | add_wait_queue(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7039 | status = nfs4_proc_setlk(state, cmd, request); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7040 | if ((status != -EAGAIN) || IS_SETLK(cmd)) { |
| 7041 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7042 | break; |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7043 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7044 | |
| 7045 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7046 | freezer_do_not_count(); |
| 7047 | wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT); |
| 7048 | freezer_count(); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7049 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7050 | } |
| 7051 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7052 | return status; |
| 7053 | } |
| 7054 | #else /* !CONFIG_NFS_V4_1 */ |
| 7055 | static inline int |
| 7056 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7057 | { |
| 7058 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7059 | } |
| 7060 | #endif |
| 7061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7062 | static int |
| 7063 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7064 | { |
| 7065 | struct nfs_open_context *ctx; |
| 7066 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7067 | int status; |
| 7068 | |
| 7069 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7070 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7071 | state = ctx->state; |
| 7072 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7073 | if (IS_GETLK(cmd)) { |
| 7074 | if (state != NULL) |
| 7075 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7076 | return 0; |
| 7077 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7078 | |
| 7079 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7080 | return -EINVAL; |
| 7081 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7082 | if (request->fl_type == F_UNLCK) { |
| 7083 | if (state != NULL) |
| 7084 | return nfs4_proc_unlck(state, cmd, request); |
| 7085 | return 0; |
| 7086 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7087 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7088 | if (state == NULL) |
| 7089 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7090 | |
| 7091 | if ((request->fl_flags & FL_POSIX) && |
| 7092 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7093 | return -ENOLCK; |
| 7094 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7095 | /* |
| 7096 | * Don't rely on the VFS having checked the file open mode, |
| 7097 | * since it won't do this for flock() locks. |
| 7098 | */ |
| 7099 | switch (request->fl_type) { |
| 7100 | case F_RDLCK: |
| 7101 | if (!(filp->f_mode & FMODE_READ)) |
| 7102 | return -EBADF; |
| 7103 | break; |
| 7104 | case F_WRLCK: |
| 7105 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7106 | return -EBADF; |
| 7107 | } |
| 7108 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7109 | status = nfs4_set_lock_state(state, request); |
| 7110 | if (status != 0) |
| 7111 | return status; |
| 7112 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7113 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7114 | } |
| 7115 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7116 | 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] | 7117 | { |
| 7118 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7119 | int err; |
| 7120 | |
| 7121 | err = nfs4_set_lock_state(state, fl); |
| 7122 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7123 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 7124 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7125 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7126 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7127 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7128 | struct nfs_release_lockowner_data { |
| 7129 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7130 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7131 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7132 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7133 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7134 | }; |
| 7135 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7136 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7137 | { |
| 7138 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7139 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7140 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7141 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7142 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7143 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7147 | { |
| 7148 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7149 | struct nfs_server *server = data->server; |
| 7150 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7151 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7152 | |
| 7153 | switch (task->tk_status) { |
| 7154 | case 0: |
| 7155 | renew_lease(server, data->timestamp); |
| 7156 | break; |
| 7157 | case -NFS4ERR_STALE_CLIENTID: |
| 7158 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7159 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7160 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7161 | case -NFS4ERR_LEASE_MOVED: |
| 7162 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7163 | if (nfs4_async_handle_error(task, server, |
| 7164 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7165 | rpc_restart_call_prepare(task); |
| 7166 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7167 | } |
| 7168 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7169 | static void nfs4_release_lockowner_release(void *calldata) |
| 7170 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7171 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7172 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7173 | kfree(calldata); |
| 7174 | } |
| 7175 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7176 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7177 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7178 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7179 | .rpc_release = nfs4_release_lockowner_release, |
| 7180 | }; |
| 7181 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7182 | static void |
| 7183 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7184 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7185 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7186 | struct rpc_message msg = { |
| 7187 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7188 | }; |
| 7189 | |
| 7190 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7191 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7192 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7193 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7194 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7195 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7196 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7197 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7198 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7199 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7200 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7201 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7202 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7203 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7204 | 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] | 7205 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7206 | } |
| 7207 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7208 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7209 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7210 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7211 | struct dentry *unused, struct inode *inode, |
| 7212 | const char *key, const void *buf, |
| 7213 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7214 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7215 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7216 | } |
| 7217 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7218 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7219 | struct dentry *unused, struct inode *inode, |
| 7220 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7221 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7222 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7223 | } |
| 7224 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7225 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7226 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7227 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7228 | } |
| 7229 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7230 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7231 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7232 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7233 | struct dentry *unused, struct inode *inode, |
| 7234 | const char *key, const void *buf, |
| 7235 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7236 | { |
| 7237 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7238 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7239 | |
| 7240 | return -EOPNOTSUPP; |
| 7241 | } |
| 7242 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7243 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7244 | struct dentry *unused, struct inode *inode, |
| 7245 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7246 | { |
| 7247 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7248 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7249 | return -EOPNOTSUPP; |
| 7250 | } |
| 7251 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7252 | static ssize_t |
| 7253 | 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] | 7254 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7255 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7256 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7257 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7258 | len = security_inode_listsecurity(inode, list, list_len); |
| 7259 | if (list_len && len > list_len) |
| 7260 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7261 | } |
| 7262 | return len; |
| 7263 | } |
| 7264 | |
| 7265 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7266 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7267 | .get = nfs4_xattr_get_nfs4_label, |
| 7268 | .set = nfs4_xattr_set_nfs4_label, |
| 7269 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7270 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7271 | #else |
| 7272 | |
| 7273 | static ssize_t |
| 7274 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7275 | { |
| 7276 | return 0; |
| 7277 | } |
| 7278 | |
| 7279 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7280 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7281 | /* |
| 7282 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7283 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7284 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7285 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7286 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7287 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7288 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7289 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7290 | return; |
| 7291 | |
| 7292 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7293 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7294 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7295 | fattr->nlink = 2; |
| 7296 | } |
| 7297 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7298 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7299 | const struct qstr *name, |
| 7300 | struct nfs4_fs_locations *fs_locations, |
| 7301 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7302 | { |
| 7303 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7304 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7305 | struct nfs4_fs_locations_arg args = { |
| 7306 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7307 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7308 | .page = page, |
| 7309 | .bitmask = bitmask, |
| 7310 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7311 | struct nfs4_fs_locations_res res = { |
| 7312 | .fs_locations = fs_locations, |
| 7313 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7314 | struct rpc_message msg = { |
| 7315 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7316 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7317 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7318 | }; |
| 7319 | int status; |
| 7320 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7321 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7322 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7323 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7324 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7325 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7326 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7327 | * is not supported */ |
| 7328 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7329 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7330 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7331 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7332 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7333 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7334 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7335 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7336 | 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] | 7337 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7338 | return status; |
| 7339 | } |
| 7340 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7341 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7342 | const struct qstr *name, |
| 7343 | struct nfs4_fs_locations *fs_locations, |
| 7344 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7345 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7346 | struct nfs4_exception exception = { |
| 7347 | .interruptible = true, |
| 7348 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7349 | int err; |
| 7350 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7351 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7352 | fs_locations, page); |
| 7353 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7354 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7355 | &exception); |
| 7356 | } while (exception.retry); |
| 7357 | return err; |
| 7358 | } |
| 7359 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7360 | /* |
| 7361 | * This operation also signals the server that this client is |
| 7362 | * performing migration recovery. The server can stop returning |
| 7363 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7364 | * appended to this compound to identify the client ID which is |
| 7365 | * performing recovery. |
| 7366 | */ |
| 7367 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7368 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7369 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7370 | { |
| 7371 | struct nfs_server *server = NFS_SERVER(inode); |
| 7372 | struct rpc_clnt *clnt = server->client; |
| 7373 | u32 bitmask[2] = { |
| 7374 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7375 | }; |
| 7376 | struct nfs4_fs_locations_arg args = { |
| 7377 | .clientid = server->nfs_client->cl_clientid, |
| 7378 | .fh = NFS_FH(inode), |
| 7379 | .page = page, |
| 7380 | .bitmask = bitmask, |
| 7381 | .migration = 1, /* skip LOOKUP */ |
| 7382 | .renew = 1, /* append RENEW */ |
| 7383 | }; |
| 7384 | struct nfs4_fs_locations_res res = { |
| 7385 | .fs_locations = locations, |
| 7386 | .migration = 1, |
| 7387 | .renew = 1, |
| 7388 | }; |
| 7389 | struct rpc_message msg = { |
| 7390 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7391 | .rpc_argp = &args, |
| 7392 | .rpc_resp = &res, |
| 7393 | .rpc_cred = cred, |
| 7394 | }; |
| 7395 | unsigned long now = jiffies; |
| 7396 | int status; |
| 7397 | |
| 7398 | nfs_fattr_init(&locations->fattr); |
| 7399 | locations->server = server; |
| 7400 | locations->nlocations = 0; |
| 7401 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7402 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7403 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7404 | &args.seq_args, &res.seq_res); |
| 7405 | if (status) |
| 7406 | return status; |
| 7407 | |
| 7408 | renew_lease(server, now); |
| 7409 | return 0; |
| 7410 | } |
| 7411 | |
| 7412 | #ifdef CONFIG_NFS_V4_1 |
| 7413 | |
| 7414 | /* |
| 7415 | * This operation also signals the server that this client is |
| 7416 | * performing migration recovery. The server can stop asserting |
| 7417 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7418 | * performing this operation is identified in the SEQUENCE |
| 7419 | * operation in this compound. |
| 7420 | * |
| 7421 | * When the client supports GETATTR(fs_locations_info), it can |
| 7422 | * be plumbed in here. |
| 7423 | */ |
| 7424 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7425 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7426 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7427 | { |
| 7428 | struct nfs_server *server = NFS_SERVER(inode); |
| 7429 | struct rpc_clnt *clnt = server->client; |
| 7430 | u32 bitmask[2] = { |
| 7431 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7432 | }; |
| 7433 | struct nfs4_fs_locations_arg args = { |
| 7434 | .fh = NFS_FH(inode), |
| 7435 | .page = page, |
| 7436 | .bitmask = bitmask, |
| 7437 | .migration = 1, /* skip LOOKUP */ |
| 7438 | }; |
| 7439 | struct nfs4_fs_locations_res res = { |
| 7440 | .fs_locations = locations, |
| 7441 | .migration = 1, |
| 7442 | }; |
| 7443 | struct rpc_message msg = { |
| 7444 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7445 | .rpc_argp = &args, |
| 7446 | .rpc_resp = &res, |
| 7447 | .rpc_cred = cred, |
| 7448 | }; |
| 7449 | int status; |
| 7450 | |
| 7451 | nfs_fattr_init(&locations->fattr); |
| 7452 | locations->server = server; |
| 7453 | locations->nlocations = 0; |
| 7454 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7455 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7456 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7457 | &args.seq_args, &res.seq_res); |
| 7458 | if (status == NFS4_OK && |
| 7459 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7460 | status = -NFS4ERR_LEASE_MOVED; |
| 7461 | return status; |
| 7462 | } |
| 7463 | |
| 7464 | #endif /* CONFIG_NFS_V4_1 */ |
| 7465 | |
| 7466 | /** |
| 7467 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7468 | * @inode: inode on FSID that is migrating |
| 7469 | * @locations: result of query |
| 7470 | * @page: buffer |
| 7471 | * @cred: credential to use for this operation |
| 7472 | * |
| 7473 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7474 | * operation failed, or a negative errno if a local error occurred. |
| 7475 | * |
| 7476 | * On success, "locations" is filled in, but if the server has |
| 7477 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7478 | * asserted. |
| 7479 | * |
| 7480 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7481 | * from this client that require migration recovery. |
| 7482 | */ |
| 7483 | int nfs4_proc_get_locations(struct inode *inode, |
| 7484 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7485 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7486 | { |
| 7487 | struct nfs_server *server = NFS_SERVER(inode); |
| 7488 | struct nfs_client *clp = server->nfs_client; |
| 7489 | const struct nfs4_mig_recovery_ops *ops = |
| 7490 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7491 | struct nfs4_exception exception = { |
| 7492 | .interruptible = true, |
| 7493 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7494 | int status; |
| 7495 | |
| 7496 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7497 | (unsigned long long)server->fsid.major, |
| 7498 | (unsigned long long)server->fsid.minor, |
| 7499 | clp->cl_hostname); |
| 7500 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7501 | |
| 7502 | do { |
| 7503 | status = ops->get_locations(inode, locations, page, cred); |
| 7504 | if (status != -NFS4ERR_DELAY) |
| 7505 | break; |
| 7506 | nfs4_handle_exception(server, status, &exception); |
| 7507 | } while (exception.retry); |
| 7508 | return status; |
| 7509 | } |
| 7510 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7511 | /* |
| 7512 | * This operation also signals the server that this client is |
| 7513 | * performing "lease moved" recovery. The server can stop |
| 7514 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7515 | * is appended to this compound to identify the client ID which is |
| 7516 | * performing recovery. |
| 7517 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7518 | 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] | 7519 | { |
| 7520 | struct nfs_server *server = NFS_SERVER(inode); |
| 7521 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7522 | struct rpc_clnt *clnt = server->client; |
| 7523 | struct nfs4_fsid_present_arg args = { |
| 7524 | .fh = NFS_FH(inode), |
| 7525 | .clientid = clp->cl_clientid, |
| 7526 | .renew = 1, /* append RENEW */ |
| 7527 | }; |
| 7528 | struct nfs4_fsid_present_res res = { |
| 7529 | .renew = 1, |
| 7530 | }; |
| 7531 | struct rpc_message msg = { |
| 7532 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7533 | .rpc_argp = &args, |
| 7534 | .rpc_resp = &res, |
| 7535 | .rpc_cred = cred, |
| 7536 | }; |
| 7537 | unsigned long now = jiffies; |
| 7538 | int status; |
| 7539 | |
| 7540 | res.fh = nfs_alloc_fhandle(); |
| 7541 | if (res.fh == NULL) |
| 7542 | return -ENOMEM; |
| 7543 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7544 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7545 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7546 | &args.seq_args, &res.seq_res); |
| 7547 | nfs_free_fhandle(res.fh); |
| 7548 | if (status) |
| 7549 | return status; |
| 7550 | |
| 7551 | do_renew_lease(clp, now); |
| 7552 | return 0; |
| 7553 | } |
| 7554 | |
| 7555 | #ifdef CONFIG_NFS_V4_1 |
| 7556 | |
| 7557 | /* |
| 7558 | * This operation also signals the server that this client is |
| 7559 | * performing "lease moved" recovery. The server can stop asserting |
| 7560 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7561 | * this operation is identified in the SEQUENCE operation in this |
| 7562 | * compound. |
| 7563 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7564 | 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] | 7565 | { |
| 7566 | struct nfs_server *server = NFS_SERVER(inode); |
| 7567 | struct rpc_clnt *clnt = server->client; |
| 7568 | struct nfs4_fsid_present_arg args = { |
| 7569 | .fh = NFS_FH(inode), |
| 7570 | }; |
| 7571 | struct nfs4_fsid_present_res res = { |
| 7572 | }; |
| 7573 | struct rpc_message msg = { |
| 7574 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7575 | .rpc_argp = &args, |
| 7576 | .rpc_resp = &res, |
| 7577 | .rpc_cred = cred, |
| 7578 | }; |
| 7579 | int status; |
| 7580 | |
| 7581 | res.fh = nfs_alloc_fhandle(); |
| 7582 | if (res.fh == NULL) |
| 7583 | return -ENOMEM; |
| 7584 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7585 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7586 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7587 | &args.seq_args, &res.seq_res); |
| 7588 | nfs_free_fhandle(res.fh); |
| 7589 | if (status == NFS4_OK && |
| 7590 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7591 | status = -NFS4ERR_LEASE_MOVED; |
| 7592 | return status; |
| 7593 | } |
| 7594 | |
| 7595 | #endif /* CONFIG_NFS_V4_1 */ |
| 7596 | |
| 7597 | /** |
| 7598 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7599 | * @inode: inode on FSID to check |
| 7600 | * @cred: credential to use for this operation |
| 7601 | * |
| 7602 | * Server indicates whether the FSID is present, moved, or not |
| 7603 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7604 | * condition for this client ID. |
| 7605 | * |
| 7606 | * Returns NFS4_OK if the FSID is present on this server, |
| 7607 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7608 | * NFS4ERR code if some error occurred on the server, or a |
| 7609 | * negative errno if a local failure occurred. |
| 7610 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7611 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7612 | { |
| 7613 | struct nfs_server *server = NFS_SERVER(inode); |
| 7614 | struct nfs_client *clp = server->nfs_client; |
| 7615 | const struct nfs4_mig_recovery_ops *ops = |
| 7616 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7617 | struct nfs4_exception exception = { |
| 7618 | .interruptible = true, |
| 7619 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7620 | int status; |
| 7621 | |
| 7622 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7623 | (unsigned long long)server->fsid.major, |
| 7624 | (unsigned long long)server->fsid.minor, |
| 7625 | clp->cl_hostname); |
| 7626 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7627 | |
| 7628 | do { |
| 7629 | status = ops->fsid_present(inode, cred); |
| 7630 | if (status != -NFS4ERR_DELAY) |
| 7631 | break; |
| 7632 | nfs4_handle_exception(server, status, &exception); |
| 7633 | } while (exception.retry); |
| 7634 | return status; |
| 7635 | } |
| 7636 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 7637 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7638 | * If 'use_integrity' is true and the state managment nfs_client |
| 7639 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7640 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7641 | * Considerations sections. Otherwise, just use the user cred with the |
| 7642 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7643 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7644 | 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] | 7645 | { |
| 7646 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame^] | 7647 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 7648 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7649 | struct nfs4_secinfo_arg args = { |
| 7650 | .dir_fh = NFS_FH(dir), |
| 7651 | .name = name, |
| 7652 | }; |
| 7653 | struct nfs4_secinfo_res res = { |
| 7654 | .flavors = flavors, |
| 7655 | }; |
| 7656 | struct rpc_message msg = { |
| 7657 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7658 | .rpc_argp = &args, |
| 7659 | .rpc_resp = &res, |
| 7660 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame^] | 7661 | struct nfs4_call_sync_data data = { |
| 7662 | .seq_server = NFS_SERVER(dir), |
| 7663 | .seq_args = &args.seq_args, |
| 7664 | .seq_res = &res.seq_res, |
| 7665 | }; |
| 7666 | struct rpc_task_setup task_setup = { |
| 7667 | .rpc_client = clnt, |
| 7668 | .rpc_message = &msg, |
| 7669 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 7670 | .callback_data = &data, |
| 7671 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 7672 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7673 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7674 | |
| 7675 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame^] | 7676 | clnt = clp->cl_rpcclient; |
| 7677 | task_setup.rpc_client = clnt; |
| 7678 | |
| 7679 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7680 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7681 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7682 | |
| 7683 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7684 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame^] | 7685 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7686 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 7687 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7688 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7689 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7690 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7691 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7692 | return status; |
| 7693 | } |
| 7694 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7695 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7696 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7697 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7698 | struct nfs4_exception exception = { |
| 7699 | .interruptible = true, |
| 7700 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7701 | int err; |
| 7702 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7703 | err = -NFS4ERR_WRONGSEC; |
| 7704 | |
| 7705 | /* try to use integrity protection with machine cred */ |
| 7706 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7707 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7708 | |
| 7709 | /* |
| 7710 | * if unable to use integrity protection, or SECINFO with |
| 7711 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7712 | * disallowed by spec, but exists in deployed servers) use |
| 7713 | * the current filesystem's rpc_client and the user cred. |
| 7714 | */ |
| 7715 | if (err == -NFS4ERR_WRONGSEC) |
| 7716 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7717 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7718 | trace_nfs4_secinfo(dir, name, err); |
| 7719 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7720 | &exception); |
| 7721 | } while (exception.retry); |
| 7722 | return err; |
| 7723 | } |
| 7724 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7725 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7726 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7727 | * Check the exchange flags returned by the server for invalid flags, having |
| 7728 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7729 | * DS flags set. |
| 7730 | */ |
| 7731 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7732 | { |
| 7733 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7734 | goto out_inval; |
| 7735 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7736 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7737 | goto out_inval; |
| 7738 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7739 | goto out_inval; |
| 7740 | return NFS_OK; |
| 7741 | out_inval: |
| 7742 | return -NFS4ERR_INVAL; |
| 7743 | } |
| 7744 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7745 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7746 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7747 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7748 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7749 | if (a->server_scope_sz != b->server_scope_sz) |
| 7750 | return false; |
| 7751 | 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] | 7752 | } |
| 7753 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7754 | static void |
| 7755 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7756 | { |
| 7757 | } |
| 7758 | |
| 7759 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7760 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7761 | }; |
| 7762 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7763 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7764 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7765 | * |
| 7766 | * The 4.1 client currently uses the same TCP connection for the |
| 7767 | * fore and backchannel. |
| 7768 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7769 | static |
| 7770 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7771 | struct rpc_xprt *xprt, |
| 7772 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7773 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7774 | { |
| 7775 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7776 | struct nfs41_bind_conn_to_session_args args = { |
| 7777 | .client = clp, |
| 7778 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7779 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7780 | struct nfs41_bind_conn_to_session_res res; |
| 7781 | struct rpc_message msg = { |
| 7782 | .rpc_proc = |
| 7783 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7784 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7785 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7786 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7787 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7788 | struct rpc_task_setup task_setup_data = { |
| 7789 | .rpc_client = clnt, |
| 7790 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7791 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7792 | .rpc_message = &msg, |
| 7793 | .flags = RPC_TASK_TIMEOUT, |
| 7794 | }; |
| 7795 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7796 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7797 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7798 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7799 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7800 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7801 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7802 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7803 | args.dir = NFS4_CDFC4_FORE; |
| 7804 | |
| 7805 | task = rpc_run_task(&task_setup_data); |
| 7806 | if (!IS_ERR(task)) { |
| 7807 | status = task->tk_status; |
| 7808 | rpc_put_task(task); |
| 7809 | } else |
| 7810 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7811 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7812 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7813 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7814 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7815 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7816 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7817 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7818 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7819 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7820 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7821 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7822 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7823 | 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] | 7824 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7825 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7826 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7827 | } |
| 7828 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7829 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7830 | return status; |
| 7831 | } |
| 7832 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7833 | struct rpc_bind_conn_calldata { |
| 7834 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7835 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7836 | }; |
| 7837 | |
| 7838 | static int |
| 7839 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7840 | struct rpc_xprt *xprt, |
| 7841 | void *calldata) |
| 7842 | { |
| 7843 | struct rpc_bind_conn_calldata *p = calldata; |
| 7844 | |
| 7845 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7846 | } |
| 7847 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7848 | 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] | 7849 | { |
| 7850 | struct rpc_bind_conn_calldata data = { |
| 7851 | .clp = clp, |
| 7852 | .cred = cred, |
| 7853 | }; |
| 7854 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7855 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7856 | } |
| 7857 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7858 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7859 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7860 | * 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] | 7861 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7862 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7863 | .how = SP4_MACH_CRED, |
| 7864 | .enforce.u.words = { |
| 7865 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7866 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7867 | 1 << (OP_CREATE_SESSION - 32) | |
| 7868 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7869 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7870 | }, |
| 7871 | .allow.u.words = { |
| 7872 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7873 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7874 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7875 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7876 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7877 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7878 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7879 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7880 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7881 | 1 << (OP_FREE_STATEID - 32) | |
| 7882 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7883 | } |
| 7884 | }; |
| 7885 | |
| 7886 | /* |
| 7887 | * Select the state protection mode for client `clp' given the server results |
| 7888 | * from exchange_id in `sp'. |
| 7889 | * |
| 7890 | * Returns 0 on success, negative errno otherwise. |
| 7891 | */ |
| 7892 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7893 | struct nfs41_state_protection *sp) |
| 7894 | { |
| 7895 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7896 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7897 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7898 | 1 << (OP_CREATE_SESSION - 32) | |
| 7899 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7900 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7901 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7902 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7903 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7904 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7905 | |
| 7906 | if (sp->how == SP4_MACH_CRED) { |
| 7907 | /* Print state protect result */ |
| 7908 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7909 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7910 | if (test_bit(i, sp->enforce.u.longs)) |
| 7911 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7912 | if (test_bit(i, sp->allow.u.longs)) |
| 7913 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7914 | } |
| 7915 | |
| 7916 | /* make sure nothing is on enforce list that isn't supported */ |
| 7917 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7918 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7919 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7920 | ret = -EINVAL; |
| 7921 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7922 | } |
| 7923 | } |
| 7924 | |
| 7925 | /* |
| 7926 | * Minimal mode - state operations are allowed to use machine |
| 7927 | * credential. Note this already happens by default, so the |
| 7928 | * client doesn't have to do anything more than the negotiation. |
| 7929 | * |
| 7930 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7931 | * we're already using the machine cred for exchange_id |
| 7932 | * and will never use a different cred. |
| 7933 | */ |
| 7934 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7935 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7936 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7937 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7938 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7939 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7940 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7941 | } else { |
| 7942 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7943 | ret = -EINVAL; |
| 7944 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7945 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7946 | |
| 7947 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7948 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7949 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7950 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7951 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7952 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7953 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7954 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7955 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7956 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7957 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7958 | } |
| 7959 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7960 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7961 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7962 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7963 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7964 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7965 | |
| 7966 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7967 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7968 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7969 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7970 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7971 | |
| 7972 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7973 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7974 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7975 | } |
| 7976 | |
| 7977 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7978 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7979 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7980 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7981 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7982 | out: |
| 7983 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 7984 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7985 | } |
| 7986 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7987 | struct nfs41_exchange_id_data { |
| 7988 | struct nfs41_exchange_id_res res; |
| 7989 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7990 | }; |
| 7991 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7992 | static void nfs4_exchange_id_release(void *data) |
| 7993 | { |
| 7994 | struct nfs41_exchange_id_data *cdata = |
| 7995 | (struct nfs41_exchange_id_data *)data; |
| 7996 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7997 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7998 | kfree(cdata->res.impl_id); |
| 7999 | kfree(cdata->res.server_scope); |
| 8000 | kfree(cdata->res.server_owner); |
| 8001 | kfree(cdata); |
| 8002 | } |
| 8003 | |
| 8004 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8005 | .rpc_release = nfs4_exchange_id_release, |
| 8006 | }; |
| 8007 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8008 | /* |
| 8009 | * _nfs4_proc_exchange_id() |
| 8010 | * |
| 8011 | * Wrapper for EXCHANGE_ID operation. |
| 8012 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8013 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8014 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8015 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8016 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8017 | struct rpc_message msg = { |
| 8018 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8019 | .rpc_cred = cred, |
| 8020 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8021 | struct rpc_task_setup task_setup_data = { |
| 8022 | .rpc_client = clp->cl_rpcclient, |
| 8023 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8024 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8025 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8026 | }; |
| 8027 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8028 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8029 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8030 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8031 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8032 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8033 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8034 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8035 | if (!calldata) |
| 8036 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8037 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8038 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8039 | |
| 8040 | status = nfs4_init_uniform_client_string(clp); |
| 8041 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8042 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8043 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8044 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8045 | GFP_NOFS); |
| 8046 | status = -ENOMEM; |
| 8047 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8048 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8049 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8050 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8051 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8052 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8053 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8054 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8055 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8056 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8057 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8058 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8059 | switch (sp4_how) { |
| 8060 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8061 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8062 | break; |
| 8063 | |
| 8064 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8065 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8066 | break; |
| 8067 | |
| 8068 | default: |
| 8069 | /* unsupported! */ |
| 8070 | WARN_ON_ONCE(1); |
| 8071 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8072 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8073 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8074 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8075 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8076 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8077 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8078 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8079 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8080 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8081 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8082 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8083 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8084 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8085 | #endif |
| 8086 | msg.rpc_argp = &calldata->args; |
| 8087 | msg.rpc_resp = &calldata->res; |
| 8088 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8089 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8090 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8091 | |
| 8092 | out_impl_id: |
| 8093 | kfree(calldata->res.impl_id); |
| 8094 | out_server_scope: |
| 8095 | kfree(calldata->res.server_scope); |
| 8096 | out_server_owner: |
| 8097 | kfree(calldata->res.server_owner); |
| 8098 | out_calldata: |
| 8099 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8100 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8101 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8102 | return ERR_PTR(status); |
| 8103 | } |
| 8104 | |
| 8105 | /* |
| 8106 | * _nfs4_proc_exchange_id() |
| 8107 | * |
| 8108 | * Wrapper for EXCHANGE_ID operation. |
| 8109 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8110 | 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] | 8111 | u32 sp4_how) |
| 8112 | { |
| 8113 | struct rpc_task *task; |
| 8114 | struct nfs41_exchange_id_args *argp; |
| 8115 | struct nfs41_exchange_id_res *resp; |
| 8116 | int status; |
| 8117 | |
| 8118 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8119 | if (IS_ERR(task)) |
| 8120 | return PTR_ERR(task); |
| 8121 | |
| 8122 | argp = task->tk_msg.rpc_argp; |
| 8123 | resp = task->tk_msg.rpc_resp; |
| 8124 | status = task->tk_status; |
| 8125 | if (status != 0) |
| 8126 | goto out; |
| 8127 | |
| 8128 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 8129 | if (status != 0) |
| 8130 | goto out; |
| 8131 | |
| 8132 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8133 | if (status != 0) |
| 8134 | goto out; |
| 8135 | |
| 8136 | clp->cl_clientid = resp->clientid; |
| 8137 | clp->cl_exchange_flags = resp->flags; |
| 8138 | clp->cl_seqid = resp->seqid; |
| 8139 | /* Client ID is not confirmed */ |
| 8140 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8141 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8142 | &clp->cl_session->session_state); |
| 8143 | |
| 8144 | if (clp->cl_serverscope != NULL && |
| 8145 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8146 | resp->server_scope)) { |
| 8147 | dprintk("%s: server_scope mismatch detected\n", |
| 8148 | __func__); |
| 8149 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8150 | } |
| 8151 | |
| 8152 | swap(clp->cl_serverowner, resp->server_owner); |
| 8153 | swap(clp->cl_serverscope, resp->server_scope); |
| 8154 | swap(clp->cl_implid, resp->impl_id); |
| 8155 | |
| 8156 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8157 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8158 | sizeof(clp->cl_confirm.data)); |
| 8159 | out: |
| 8160 | trace_nfs4_exchange_id(clp, status); |
| 8161 | rpc_put_task(task); |
| 8162 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8163 | } |
| 8164 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8165 | /* |
| 8166 | * nfs4_proc_exchange_id() |
| 8167 | * |
| 8168 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8169 | * |
| 8170 | * Since the clientid has expired, all compounds using sessions |
| 8171 | * associated with the stale clientid will be returning |
| 8172 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8173 | * be in some phase of session reset. |
| 8174 | * |
| 8175 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8176 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8177 | 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] | 8178 | { |
| 8179 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8180 | int status; |
| 8181 | |
| 8182 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8183 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8184 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8185 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8186 | if (!status) |
| 8187 | return 0; |
| 8188 | } |
| 8189 | |
| 8190 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8191 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8192 | } |
| 8193 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8194 | /** |
| 8195 | * nfs4_test_session_trunk |
| 8196 | * |
| 8197 | * This is an add_xprt_test() test function called from |
| 8198 | * rpc_clnt_setup_test_and_add_xprt. |
| 8199 | * |
| 8200 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8201 | * and is dereferrenced in nfs4_exchange_id_release |
| 8202 | * |
| 8203 | * Upon success, add the new transport to the rpc_clnt |
| 8204 | * |
| 8205 | * @clnt: struct rpc_clnt to get new transport |
| 8206 | * @xprt: the rpc_xprt to test |
| 8207 | * @data: call data for _nfs4_proc_exchange_id. |
| 8208 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8209 | 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] | 8210 | void *data) |
| 8211 | { |
| 8212 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8213 | struct rpc_task *task; |
| 8214 | int status; |
| 8215 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8216 | u32 sp4_how; |
| 8217 | |
| 8218 | dprintk("--> %s try %s\n", __func__, |
| 8219 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8220 | |
| 8221 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8222 | |
| 8223 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8224 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8225 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8226 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8227 | |
| 8228 | status = task->tk_status; |
| 8229 | if (status == 0) |
| 8230 | status = nfs4_detect_session_trunking(adata->clp, |
| 8231 | task->tk_msg.rpc_resp, xprt); |
| 8232 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8233 | if (status == 0) |
| 8234 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8235 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8236 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8237 | } |
| 8238 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8239 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8240 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8241 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8242 | { |
| 8243 | struct rpc_message msg = { |
| 8244 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8245 | .rpc_argp = clp, |
| 8246 | .rpc_cred = cred, |
| 8247 | }; |
| 8248 | int status; |
| 8249 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8250 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8251 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8252 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8253 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8254 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8255 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8256 | return status; |
| 8257 | } |
| 8258 | |
| 8259 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8260 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8261 | { |
| 8262 | unsigned int loop; |
| 8263 | int ret; |
| 8264 | |
| 8265 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8266 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8267 | switch (ret) { |
| 8268 | case -NFS4ERR_DELAY: |
| 8269 | case -NFS4ERR_CLIENTID_BUSY: |
| 8270 | ssleep(1); |
| 8271 | break; |
| 8272 | default: |
| 8273 | return ret; |
| 8274 | } |
| 8275 | } |
| 8276 | return 0; |
| 8277 | } |
| 8278 | |
| 8279 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8280 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8281 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8282 | int ret = 0; |
| 8283 | |
| 8284 | if (clp->cl_mvops->minor_version < 1) |
| 8285 | goto out; |
| 8286 | if (clp->cl_exchange_flags == 0) |
| 8287 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8288 | if (clp->cl_preserve_clid) |
| 8289 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8290 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8291 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8292 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8293 | switch (ret) { |
| 8294 | case 0: |
| 8295 | case -NFS4ERR_STALE_CLIENTID: |
| 8296 | clp->cl_exchange_flags = 0; |
| 8297 | } |
| 8298 | out: |
| 8299 | return ret; |
| 8300 | } |
| 8301 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8302 | #endif /* CONFIG_NFS_V4_1 */ |
| 8303 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8304 | struct nfs4_get_lease_time_data { |
| 8305 | struct nfs4_get_lease_time_args *args; |
| 8306 | struct nfs4_get_lease_time_res *res; |
| 8307 | struct nfs_client *clp; |
| 8308 | }; |
| 8309 | |
| 8310 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8311 | void *calldata) |
| 8312 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8313 | struct nfs4_get_lease_time_data *data = |
| 8314 | (struct nfs4_get_lease_time_data *)calldata; |
| 8315 | |
| 8316 | dprintk("--> %s\n", __func__); |
| 8317 | /* just setup sequence, do not trigger session recovery |
| 8318 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8319 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8320 | &data->args->la_seq_args, |
| 8321 | &data->res->lr_seq_res, |
| 8322 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8323 | dprintk("<-- %s\n", __func__); |
| 8324 | } |
| 8325 | |
| 8326 | /* |
| 8327 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8328 | * from sequence operation or clientid errors. |
| 8329 | */ |
| 8330 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8331 | { |
| 8332 | struct nfs4_get_lease_time_data *data = |
| 8333 | (struct nfs4_get_lease_time_data *)calldata; |
| 8334 | |
| 8335 | dprintk("--> %s\n", __func__); |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8336 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8337 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8338 | switch (task->tk_status) { |
| 8339 | case -NFS4ERR_DELAY: |
| 8340 | case -NFS4ERR_GRACE: |
| 8341 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8342 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8343 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8344 | /* fall through */ |
| 8345 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8346 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8347 | return; |
| 8348 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8349 | dprintk("<-- %s\n", __func__); |
| 8350 | } |
| 8351 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8352 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8353 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8354 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8355 | }; |
| 8356 | |
| 8357 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8358 | { |
| 8359 | struct rpc_task *task; |
| 8360 | struct nfs4_get_lease_time_args args; |
| 8361 | struct nfs4_get_lease_time_res res = { |
| 8362 | .lr_fsinfo = fsinfo, |
| 8363 | }; |
| 8364 | struct nfs4_get_lease_time_data data = { |
| 8365 | .args = &args, |
| 8366 | .res = &res, |
| 8367 | .clp = clp, |
| 8368 | }; |
| 8369 | struct rpc_message msg = { |
| 8370 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8371 | .rpc_argp = &args, |
| 8372 | .rpc_resp = &res, |
| 8373 | }; |
| 8374 | struct rpc_task_setup task_setup = { |
| 8375 | .rpc_client = clp->cl_rpcclient, |
| 8376 | .rpc_message = &msg, |
| 8377 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8378 | .callback_data = &data, |
| 8379 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8380 | }; |
| 8381 | int status; |
| 8382 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8383 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0, 1); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8384 | task = rpc_run_task(&task_setup); |
| 8385 | |
| 8386 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8387 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8388 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8389 | status = task->tk_status; |
| 8390 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8391 | return status; |
| 8392 | } |
| 8393 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8394 | #ifdef CONFIG_NFS_V4_1 |
| 8395 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8396 | /* |
| 8397 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8398 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8399 | * use them. |
| 8400 | * |
| 8401 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8402 | * always set csa_cachethis to FALSE because the current implementation |
| 8403 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8404 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8405 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8406 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8407 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8408 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8409 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8410 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8411 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8412 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8413 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8414 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8415 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8416 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8417 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8418 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8419 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8420 | |
| 8421 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8422 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8423 | __func__, |
| 8424 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8425 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8426 | |
| 8427 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8428 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8429 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8430 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8431 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8432 | 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] | 8433 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8434 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8435 | |
| 8436 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8437 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8438 | __func__, |
| 8439 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8440 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8441 | args->bc_attrs.max_reqs); |
| 8442 | } |
| 8443 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8444 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8445 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8446 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8447 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8448 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8449 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8450 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8451 | return -EINVAL; |
| 8452 | /* |
| 8453 | * Our requested max_ops is the minimum we need; we're not |
| 8454 | * prepared to break up compounds into smaller pieces than that. |
| 8455 | * So, no point even trying to continue if the server won't |
| 8456 | * cooperate: |
| 8457 | */ |
| 8458 | if (rcvd->max_ops < sent->max_ops) |
| 8459 | return -EINVAL; |
| 8460 | if (rcvd->max_reqs == 0) |
| 8461 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8462 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8463 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8464 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8465 | } |
| 8466 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8467 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8468 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8469 | { |
| 8470 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8471 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8472 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8473 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8474 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8475 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8476 | return -EINVAL; |
| 8477 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8478 | return -EINVAL; |
| 8479 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8480 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8481 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8482 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8483 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8484 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8485 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8486 | return 0; |
| 8487 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8488 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8489 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8490 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8491 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8492 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8493 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8494 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8495 | if (ret) |
| 8496 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8497 | return nfs4_verify_back_channel_attrs(args, res); |
| 8498 | } |
| 8499 | |
| 8500 | static void nfs4_update_session(struct nfs4_session *session, |
| 8501 | struct nfs41_create_session_res *res) |
| 8502 | { |
| 8503 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8504 | /* Mark client id and session as being confirmed */ |
| 8505 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8506 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8507 | session->flags = res->flags; |
| 8508 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8509 | if (res->flags & SESSION4_BACK_CHAN) |
| 8510 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8511 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8512 | } |
| 8513 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8514 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8515 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8516 | { |
| 8517 | struct nfs4_session *session = clp->cl_session; |
| 8518 | struct nfs41_create_session_args args = { |
| 8519 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8520 | .clientid = clp->cl_clientid, |
| 8521 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8522 | .cb_program = NFS4_CALLBACK, |
| 8523 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8524 | struct nfs41_create_session_res res; |
| 8525 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8526 | struct rpc_message msg = { |
| 8527 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8528 | .rpc_argp = &args, |
| 8529 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8530 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8531 | }; |
| 8532 | int status; |
| 8533 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8534 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8535 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8536 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8537 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8538 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8539 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8540 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8541 | switch (status) { |
| 8542 | case -NFS4ERR_STALE_CLIENTID: |
| 8543 | case -NFS4ERR_DELAY: |
| 8544 | case -ETIMEDOUT: |
| 8545 | case -EACCES: |
| 8546 | case -EAGAIN: |
| 8547 | goto out; |
| 8548 | }; |
| 8549 | |
| 8550 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8551 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8552 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8553 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8554 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8555 | if (status) |
| 8556 | goto out; |
| 8557 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8558 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8559 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8560 | return status; |
| 8561 | } |
| 8562 | |
| 8563 | /* |
| 8564 | * Issues a CREATE_SESSION operation to the server. |
| 8565 | * It is the responsibility of the caller to verify the session is |
| 8566 | * expired before calling this routine. |
| 8567 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8568 | 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] | 8569 | { |
| 8570 | int status; |
| 8571 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8572 | struct nfs4_session *session = clp->cl_session; |
| 8573 | |
| 8574 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8575 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8576 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8577 | if (status) |
| 8578 | goto out; |
| 8579 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8580 | /* Init or reset the session slot tables */ |
| 8581 | status = nfs4_setup_session_slot_tables(session); |
| 8582 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8583 | if (status) |
| 8584 | goto out; |
| 8585 | |
| 8586 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8587 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8588 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8589 | out: |
| 8590 | dprintk("<-- %s\n", __func__); |
| 8591 | return status; |
| 8592 | } |
| 8593 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8594 | /* |
| 8595 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8596 | * The caller must serialize access to this routine. |
| 8597 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8598 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8599 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8600 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8601 | struct rpc_message msg = { |
| 8602 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8603 | .rpc_argp = session, |
| 8604 | .rpc_cred = cred, |
| 8605 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8606 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8607 | |
| 8608 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8609 | |
| 8610 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8611 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8612 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8613 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8614 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8615 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8616 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8617 | |
| 8618 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8619 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8620 | "Session has been destroyed regardless...\n", status); |
| 8621 | |
| 8622 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8623 | return status; |
| 8624 | } |
| 8625 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8626 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8627 | * Renew the cl_session lease. |
| 8628 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8629 | struct nfs4_sequence_data { |
| 8630 | struct nfs_client *clp; |
| 8631 | struct nfs4_sequence_args args; |
| 8632 | struct nfs4_sequence_res res; |
| 8633 | }; |
| 8634 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8635 | static void nfs41_sequence_release(void *data) |
| 8636 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8637 | struct nfs4_sequence_data *calldata = data; |
| 8638 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8639 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8640 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8641 | nfs4_schedule_state_renewal(clp); |
| 8642 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8643 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8644 | } |
| 8645 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8646 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8647 | { |
| 8648 | switch(task->tk_status) { |
| 8649 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8650 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8651 | return -EAGAIN; |
| 8652 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8653 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8654 | } |
| 8655 | return 0; |
| 8656 | } |
| 8657 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8658 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8659 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8660 | struct nfs4_sequence_data *calldata = data; |
| 8661 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8662 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8663 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8664 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8665 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8666 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8667 | if (task->tk_status < 0) { |
| 8668 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8669 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8670 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8671 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8672 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8673 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8674 | return; |
| 8675 | } |
| 8676 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8677 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8678 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8679 | dprintk("<-- %s\n", __func__); |
| 8680 | } |
| 8681 | |
| 8682 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8683 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8684 | struct nfs4_sequence_data *calldata = data; |
| 8685 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8686 | struct nfs4_sequence_args *args; |
| 8687 | struct nfs4_sequence_res *res; |
| 8688 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8689 | args = task->tk_msg.rpc_argp; |
| 8690 | res = task->tk_msg.rpc_resp; |
| 8691 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8692 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8693 | } |
| 8694 | |
| 8695 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8696 | .rpc_call_done = nfs41_sequence_call_done, |
| 8697 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8698 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8699 | }; |
| 8700 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8701 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8702 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8703 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8704 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8705 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8706 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8707 | struct rpc_message msg = { |
| 8708 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8709 | .rpc_cred = cred, |
| 8710 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8711 | struct rpc_task_setup task_setup_data = { |
| 8712 | .rpc_client = clp->cl_rpcclient, |
| 8713 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8714 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8715 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8716 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8717 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8718 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8719 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8720 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8721 | goto out_err; |
| 8722 | |
| 8723 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8724 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8725 | if (calldata == NULL) |
| 8726 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8727 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8728 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8729 | msg.rpc_argp = &calldata->args; |
| 8730 | msg.rpc_resp = &calldata->res; |
| 8731 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8732 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8733 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8734 | ret = rpc_run_task(&task_setup_data); |
| 8735 | if (IS_ERR(ret)) |
| 8736 | goto out_err; |
| 8737 | return ret; |
| 8738 | out_put_clp: |
| 8739 | nfs_put_client(clp); |
| 8740 | out_err: |
| 8741 | nfs41_release_slot(slot); |
| 8742 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8743 | } |
| 8744 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8745 | 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] | 8746 | { |
| 8747 | struct rpc_task *task; |
| 8748 | int ret = 0; |
| 8749 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8750 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8751 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8752 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8753 | if (IS_ERR(task)) |
| 8754 | ret = PTR_ERR(task); |
| 8755 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8756 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8757 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8758 | return ret; |
| 8759 | } |
| 8760 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8761 | 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] | 8762 | { |
| 8763 | struct rpc_task *task; |
| 8764 | int ret; |
| 8765 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8766 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8767 | if (IS_ERR(task)) { |
| 8768 | ret = PTR_ERR(task); |
| 8769 | goto out; |
| 8770 | } |
| 8771 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8772 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8773 | ret = task->tk_status; |
| 8774 | rpc_put_task(task); |
| 8775 | out: |
| 8776 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8777 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8778 | } |
| 8779 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8780 | struct nfs4_reclaim_complete_data { |
| 8781 | struct nfs_client *clp; |
| 8782 | struct nfs41_reclaim_complete_args arg; |
| 8783 | struct nfs41_reclaim_complete_res res; |
| 8784 | }; |
| 8785 | |
| 8786 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8787 | { |
| 8788 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8789 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8790 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8791 | &calldata->arg.seq_args, |
| 8792 | &calldata->res.seq_res, |
| 8793 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8794 | } |
| 8795 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8796 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8797 | { |
| 8798 | switch(task->tk_status) { |
| 8799 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8800 | wake_up_all(&clp->cl_lock_waitq); |
| 8801 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8802 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8803 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8804 | break; |
| 8805 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8806 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8807 | /* fall through */ |
| 8808 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8809 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8810 | case -NFS4ERR_BADSESSION: |
| 8811 | case -NFS4ERR_DEADSESSION: |
| 8812 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8813 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8814 | task->tk_status); |
| 8815 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8816 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8817 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8818 | } |
| 8819 | return 0; |
| 8820 | } |
| 8821 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8822 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8823 | { |
| 8824 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8825 | struct nfs_client *clp = calldata->clp; |
| 8826 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8827 | |
| 8828 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8829 | if (!nfs41_sequence_done(task, res)) |
| 8830 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8831 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8832 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8833 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8834 | rpc_restart_call_prepare(task); |
| 8835 | return; |
| 8836 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8837 | dprintk("<-- %s\n", __func__); |
| 8838 | } |
| 8839 | |
| 8840 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8841 | { |
| 8842 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8843 | |
| 8844 | kfree(calldata); |
| 8845 | } |
| 8846 | |
| 8847 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8848 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8849 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8850 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8851 | }; |
| 8852 | |
| 8853 | /* |
| 8854 | * Issue a global reclaim complete. |
| 8855 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8856 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8857 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8858 | { |
| 8859 | struct nfs4_reclaim_complete_data *calldata; |
| 8860 | struct rpc_task *task; |
| 8861 | struct rpc_message msg = { |
| 8862 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8863 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8864 | }; |
| 8865 | struct rpc_task_setup task_setup_data = { |
| 8866 | .rpc_client = clp->cl_rpcclient, |
| 8867 | .rpc_message = &msg, |
| 8868 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8869 | .flags = RPC_TASK_ASYNC | RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8870 | }; |
| 8871 | int status = -ENOMEM; |
| 8872 | |
| 8873 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8874 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8875 | if (calldata == NULL) |
| 8876 | goto out; |
| 8877 | calldata->clp = clp; |
| 8878 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8879 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8880 | 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] | 8881 | msg.rpc_argp = &calldata->arg; |
| 8882 | msg.rpc_resp = &calldata->res; |
| 8883 | task_setup_data.callback_data = calldata; |
| 8884 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8885 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8886 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8887 | goto out; |
| 8888 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8889 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8890 | if (status == 0) |
| 8891 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8892 | rpc_put_task(task); |
| 8893 | out: |
| 8894 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8895 | return status; |
| 8896 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8897 | |
| 8898 | static void |
| 8899 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8900 | { |
| 8901 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8902 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8903 | |
| 8904 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8905 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8906 | &lgp->res.seq_res, task); |
| 8907 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8908 | } |
| 8909 | |
| 8910 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8911 | { |
| 8912 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8913 | |
| 8914 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8915 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8916 | dprintk("<-- %s\n", __func__); |
| 8917 | } |
| 8918 | |
| 8919 | static int |
| 8920 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8921 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8922 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8923 | struct inode *inode = lgp->args.inode; |
| 8924 | struct nfs_server *server = NFS_SERVER(inode); |
| 8925 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8926 | int nfs4err = task->tk_status; |
| 8927 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8928 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8929 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8930 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8931 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 8932 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 8933 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8934 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8935 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8936 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8937 | |
| 8938 | /* |
| 8939 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8940 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8941 | * retry go inband. |
| 8942 | */ |
| 8943 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8944 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8945 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8946 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8947 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8948 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8949 | */ |
| 8950 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8951 | status = -EOVERFLOW; |
| 8952 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8953 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8954 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8955 | * (or clients) writing to the same RAID stripe except when |
| 8956 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8957 | * |
| 8958 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8959 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8960 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8961 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8962 | if (lgp->args.minlength == 0) { |
| 8963 | status = -EOVERFLOW; |
| 8964 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8965 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8966 | status = -EBUSY; |
| 8967 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8968 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8969 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8970 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8971 | case -NFS4ERR_DELEG_REVOKED: |
| 8972 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8973 | case -NFS4ERR_EXPIRED: |
| 8974 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8975 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8976 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8977 | lo = NFS_I(inode)->layout; |
| 8978 | /* If the open stateid was bad, then recover it. */ |
| 8979 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 8980 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8981 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8982 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8983 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8984 | break; |
| 8985 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8986 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8987 | /* |
| 8988 | * Mark the bad layout state as invalid, then retry |
| 8989 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8990 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8991 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8992 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8993 | pnfs_free_lseg_list(&head); |
| 8994 | status = -EAGAIN; |
| 8995 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8996 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8997 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8998 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8999 | if (!status) { |
| 9000 | if (exception->retry) |
| 9001 | status = -EAGAIN; |
| 9002 | else |
| 9003 | status = err; |
| 9004 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9005 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9006 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9007 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9008 | } |
| 9009 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9010 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9011 | { |
| 9012 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9013 | return nfs_page_array_len(0, max_resp_sz); |
| 9014 | } |
| 9015 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9016 | static void nfs4_layoutget_release(void *calldata) |
| 9017 | { |
| 9018 | struct nfs4_layoutget *lgp = calldata; |
| 9019 | |
| 9020 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9021 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9022 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9023 | dprintk("<-- %s\n", __func__); |
| 9024 | } |
| 9025 | |
| 9026 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9027 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9028 | .rpc_call_done = nfs4_layoutget_done, |
| 9029 | .rpc_release = nfs4_layoutget_release, |
| 9030 | }; |
| 9031 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9032 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9033 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9034 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9035 | struct inode *inode = lgp->args.inode; |
| 9036 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9037 | struct rpc_task *task; |
| 9038 | struct rpc_message msg = { |
| 9039 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9040 | .rpc_argp = &lgp->args, |
| 9041 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9042 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9043 | }; |
| 9044 | struct rpc_task_setup task_setup_data = { |
| 9045 | .rpc_client = server->client, |
| 9046 | .rpc_message = &msg, |
| 9047 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9048 | .callback_data = lgp, |
| 9049 | .flags = RPC_TASK_ASYNC, |
| 9050 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9051 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9052 | struct nfs4_exception exception = { |
| 9053 | .inode = inode, |
| 9054 | .timeout = *timeout, |
| 9055 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9056 | int status = 0; |
| 9057 | |
| 9058 | dprintk("--> %s\n", __func__); |
| 9059 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 9060 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 9061 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 9062 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9063 | 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] | 9064 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9065 | task = rpc_run_task(&task_setup_data); |
| 9066 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9067 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9068 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9069 | if (status != 0) |
| 9070 | goto out; |
| 9071 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9072 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9073 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9074 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9075 | } else if (lgp->res.layoutp->len == 0) { |
| 9076 | status = -EAGAIN; |
| 9077 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9078 | } else |
| 9079 | lseg = pnfs_layout_process(lgp); |
| 9080 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9081 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9082 | &lgp->args.range, |
| 9083 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9084 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9085 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9086 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9087 | rpc_put_task(task); |
| 9088 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9089 | if (status) |
| 9090 | return ERR_PTR(status); |
| 9091 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9092 | } |
| 9093 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9094 | static void |
| 9095 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9096 | { |
| 9097 | struct nfs4_layoutreturn *lrp = calldata; |
| 9098 | |
| 9099 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9100 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9101 | &lrp->args.seq_args, |
| 9102 | &lrp->res.seq_res, |
| 9103 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9104 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9105 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9106 | } |
| 9107 | |
| 9108 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9109 | { |
| 9110 | struct nfs4_layoutreturn *lrp = calldata; |
| 9111 | struct nfs_server *server; |
| 9112 | |
| 9113 | dprintk("--> %s\n", __func__); |
| 9114 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9115 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9116 | return; |
| 9117 | |
| 9118 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9119 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9120 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | c16467d | 2018-07-29 22:39:15 -0400 | [diff] [blame] | 9121 | if (nfs4_layoutreturn_refresh_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9122 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9123 | lrp->args.inode)) |
| 9124 | goto out_restart; |
| 9125 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9126 | default: |
| 9127 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9128 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9129 | case 0: |
| 9130 | break; |
| 9131 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9132 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9133 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9134 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9135 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9136 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9137 | return; |
| 9138 | out_restart: |
| 9139 | task->tk_status = 0; |
| 9140 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9141 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9142 | } |
| 9143 | |
| 9144 | static void nfs4_layoutreturn_release(void *calldata) |
| 9145 | { |
| 9146 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9147 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9148 | |
| 9149 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9150 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9151 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9152 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9153 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9154 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9155 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9156 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9157 | kfree(calldata); |
| 9158 | dprintk("<-- %s\n", __func__); |
| 9159 | } |
| 9160 | |
| 9161 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9162 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9163 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9164 | .rpc_release = nfs4_layoutreturn_release, |
| 9165 | }; |
| 9166 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9167 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9168 | { |
| 9169 | struct rpc_task *task; |
| 9170 | struct rpc_message msg = { |
| 9171 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9172 | .rpc_argp = &lrp->args, |
| 9173 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9174 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9175 | }; |
| 9176 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9177 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9178 | .rpc_message = &msg, |
| 9179 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9180 | .callback_data = lrp, |
| 9181 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9182 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9183 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9184 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9185 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9186 | &task_setup_data.rpc_client, &msg); |
| 9187 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9188 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9189 | if (!sync) { |
| 9190 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 9191 | if (!lrp->inode) { |
| 9192 | nfs4_layoutreturn_release(lrp); |
| 9193 | return -EAGAIN; |
| 9194 | } |
| 9195 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9196 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9197 | 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] | 9198 | task = rpc_run_task(&task_setup_data); |
| 9199 | if (IS_ERR(task)) |
| 9200 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9201 | if (sync) |
| 9202 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9203 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9204 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9205 | rpc_put_task(task); |
| 9206 | return status; |
| 9207 | } |
| 9208 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9209 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9210 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9211 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9212 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9213 | { |
| 9214 | struct nfs4_getdeviceinfo_args args = { |
| 9215 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9216 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9217 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9218 | }; |
| 9219 | struct nfs4_getdeviceinfo_res res = { |
| 9220 | .pdev = pdev, |
| 9221 | }; |
| 9222 | struct rpc_message msg = { |
| 9223 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9224 | .rpc_argp = &args, |
| 9225 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9226 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9227 | }; |
| 9228 | int status; |
| 9229 | |
| 9230 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9231 | 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] | 9232 | if (res.notification & ~args.notify_types) |
| 9233 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9234 | if (res.notification != args.notify_types) |
| 9235 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9236 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9237 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9238 | |
| 9239 | return status; |
| 9240 | } |
| 9241 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9242 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9243 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9244 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9245 | { |
| 9246 | struct nfs4_exception exception = { }; |
| 9247 | int err; |
| 9248 | |
| 9249 | do { |
| 9250 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9251 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9252 | &exception); |
| 9253 | } while (exception.retry); |
| 9254 | return err; |
| 9255 | } |
| 9256 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9257 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9258 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9259 | { |
| 9260 | struct nfs4_layoutcommit_data *data = calldata; |
| 9261 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9262 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9263 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9264 | &data->args.seq_args, |
| 9265 | &data->res.seq_res, |
| 9266 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9267 | } |
| 9268 | |
| 9269 | static void |
| 9270 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9271 | { |
| 9272 | struct nfs4_layoutcommit_data *data = calldata; |
| 9273 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9274 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9275 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9276 | return; |
| 9277 | |
| 9278 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9279 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9280 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9281 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9282 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9283 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9284 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9285 | break; |
| 9286 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9287 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9288 | rpc_restart_call_prepare(task); |
| 9289 | return; |
| 9290 | } |
| 9291 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9292 | } |
| 9293 | |
| 9294 | static void nfs4_layoutcommit_release(void *calldata) |
| 9295 | { |
| 9296 | struct nfs4_layoutcommit_data *data = calldata; |
| 9297 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9298 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9299 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9300 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9301 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9302 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9303 | kfree(data); |
| 9304 | } |
| 9305 | |
| 9306 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9307 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9308 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9309 | .rpc_release = nfs4_layoutcommit_release, |
| 9310 | }; |
| 9311 | |
| 9312 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9313 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9314 | { |
| 9315 | struct rpc_message msg = { |
| 9316 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9317 | .rpc_argp = &data->args, |
| 9318 | .rpc_resp = &data->res, |
| 9319 | .rpc_cred = data->cred, |
| 9320 | }; |
| 9321 | struct rpc_task_setup task_setup_data = { |
| 9322 | .task = &data->task, |
| 9323 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9324 | .rpc_message = &msg, |
| 9325 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9326 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9327 | }; |
| 9328 | struct rpc_task *task; |
| 9329 | int status = 0; |
| 9330 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9331 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9332 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9333 | data->args.lastbytewritten, |
| 9334 | data->args.inode->i_ino); |
| 9335 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9336 | if (!sync) { |
| 9337 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9338 | if (data->inode == NULL) { |
| 9339 | nfs4_layoutcommit_release(data); |
| 9340 | return -EAGAIN; |
| 9341 | } |
| 9342 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9343 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9344 | 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] | 9345 | task = rpc_run_task(&task_setup_data); |
| 9346 | if (IS_ERR(task)) |
| 9347 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9348 | if (sync) |
| 9349 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9350 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9351 | dprintk("%s: status %d\n", __func__, status); |
| 9352 | rpc_put_task(task); |
| 9353 | return status; |
| 9354 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9355 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9356 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9357 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9358 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9359 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9360 | static int |
| 9361 | _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] | 9362 | struct nfs_fsinfo *info, |
| 9363 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9364 | { |
| 9365 | struct nfs41_secinfo_no_name_args args = { |
| 9366 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9367 | }; |
| 9368 | struct nfs4_secinfo_res res = { |
| 9369 | .flavors = flavors, |
| 9370 | }; |
| 9371 | struct rpc_message msg = { |
| 9372 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9373 | .rpc_argp = &args, |
| 9374 | .rpc_resp = &res, |
| 9375 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9376 | struct rpc_clnt *clnt = server->client; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9377 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9378 | int status; |
| 9379 | |
| 9380 | if (use_integrity) { |
| 9381 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9382 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9383 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9384 | } |
| 9385 | |
| 9386 | dprintk("--> %s\n", __func__); |
| 9387 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 9388 | &res.seq_res, RPC_TASK_NO_ROUND_ROBIN); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9389 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9390 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9391 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9392 | |
| 9393 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9394 | } |
| 9395 | |
| 9396 | static int |
| 9397 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9398 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9399 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9400 | struct nfs4_exception exception = { |
| 9401 | .interruptible = true, |
| 9402 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9403 | int err; |
| 9404 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9405 | /* first try using integrity protection */ |
| 9406 | err = -NFS4ERR_WRONGSEC; |
| 9407 | |
| 9408 | /* try to use integrity protection with machine cred */ |
| 9409 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9410 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9411 | flavors, true); |
| 9412 | |
| 9413 | /* |
| 9414 | * if unable to use integrity protection, or SECINFO with |
| 9415 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9416 | * disallowed by spec, but exists in deployed servers) use |
| 9417 | * the current filesystem's rpc_client and the user cred. |
| 9418 | */ |
| 9419 | if (err == -NFS4ERR_WRONGSEC) |
| 9420 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9421 | flavors, false); |
| 9422 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9423 | switch (err) { |
| 9424 | case 0: |
| 9425 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9426 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9427 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9428 | default: |
| 9429 | err = nfs4_handle_exception(server, err, &exception); |
| 9430 | } |
| 9431 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9432 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9433 | return err; |
| 9434 | } |
| 9435 | |
| 9436 | static int |
| 9437 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9438 | struct nfs_fsinfo *info) |
| 9439 | { |
| 9440 | int err; |
| 9441 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9442 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9443 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9444 | struct nfs4_secinfo4 *secinfo; |
| 9445 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9446 | |
| 9447 | page = alloc_page(GFP_KERNEL); |
| 9448 | if (!page) { |
| 9449 | err = -ENOMEM; |
| 9450 | goto out; |
| 9451 | } |
| 9452 | |
| 9453 | flavors = page_address(page); |
| 9454 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9455 | |
| 9456 | /* |
| 9457 | * Fall back on "guess and check" method if |
| 9458 | * the server doesn't support SECINFO_NO_NAME |
| 9459 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9460 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9461 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9462 | goto out_freepage; |
| 9463 | } |
| 9464 | if (err) |
| 9465 | goto out_freepage; |
| 9466 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9467 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9468 | secinfo = &flavors->flavors[i]; |
| 9469 | |
| 9470 | switch (secinfo->flavor) { |
| 9471 | case RPC_AUTH_NULL: |
| 9472 | case RPC_AUTH_UNIX: |
| 9473 | case RPC_AUTH_GSS: |
| 9474 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9475 | &secinfo->flavor_info); |
| 9476 | break; |
| 9477 | default: |
| 9478 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9479 | break; |
| 9480 | } |
| 9481 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9482 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9483 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9484 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9485 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9486 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9487 | info, flavor); |
| 9488 | if (!err) |
| 9489 | break; |
| 9490 | } |
| 9491 | } |
| 9492 | |
| 9493 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9494 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9495 | |
| 9496 | out_freepage: |
| 9497 | put_page(page); |
| 9498 | if (err == -EACCES) |
| 9499 | return -EPERM; |
| 9500 | out: |
| 9501 | return err; |
| 9502 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9503 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9504 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9505 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9506 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9507 | { |
| 9508 | int status; |
| 9509 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9510 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9511 | }; |
| 9512 | struct nfs41_test_stateid_res res; |
| 9513 | struct rpc_message msg = { |
| 9514 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9515 | .rpc_argp = &args, |
| 9516 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9517 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9518 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9519 | struct rpc_clnt *rpc_client = server->client; |
| 9520 | |
| 9521 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9522 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9523 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9524 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9525 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9526 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9527 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9528 | if (status != NFS_OK) { |
| 9529 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9530 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9531 | } |
| 9532 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9533 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9534 | } |
| 9535 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9536 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9537 | int err, struct nfs4_exception *exception) |
| 9538 | { |
| 9539 | exception->retry = 0; |
| 9540 | switch(err) { |
| 9541 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9542 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9543 | nfs4_handle_exception(server, err, exception); |
| 9544 | break; |
| 9545 | case -NFS4ERR_BADSESSION: |
| 9546 | case -NFS4ERR_BADSLOT: |
| 9547 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9548 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9549 | case -NFS4ERR_DEADSESSION: |
| 9550 | nfs4_do_handle_exception(server, err, exception); |
| 9551 | } |
| 9552 | } |
| 9553 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9554 | /** |
| 9555 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9556 | * |
| 9557 | * @server: server / transport on which to perform the operation |
| 9558 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9559 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9560 | * |
| 9561 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9562 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9563 | * failed or the state ID is not currently valid. |
| 9564 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9565 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9566 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9567 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9568 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9569 | struct nfs4_exception exception = { |
| 9570 | .interruptible = true, |
| 9571 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9572 | int err; |
| 9573 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9574 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9575 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9576 | } while (exception.retry); |
| 9577 | return err; |
| 9578 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9579 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9580 | struct nfs_free_stateid_data { |
| 9581 | struct nfs_server *server; |
| 9582 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9583 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9584 | }; |
| 9585 | |
| 9586 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9587 | { |
| 9588 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9589 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9590 | &data->args.seq_args, |
| 9591 | &data->res.seq_res, |
| 9592 | task); |
| 9593 | } |
| 9594 | |
| 9595 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9596 | { |
| 9597 | struct nfs_free_stateid_data *data = calldata; |
| 9598 | |
| 9599 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9600 | |
| 9601 | switch (task->tk_status) { |
| 9602 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9603 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9604 | rpc_restart_call_prepare(task); |
| 9605 | } |
| 9606 | } |
| 9607 | |
| 9608 | static void nfs41_free_stateid_release(void *calldata) |
| 9609 | { |
| 9610 | kfree(calldata); |
| 9611 | } |
| 9612 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9613 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9614 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9615 | .rpc_call_done = nfs41_free_stateid_done, |
| 9616 | .rpc_release = nfs41_free_stateid_release, |
| 9617 | }; |
| 9618 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9619 | /** |
| 9620 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9621 | * |
| 9622 | * @server: server / transport on which to perform the operation |
| 9623 | * @stateid: state ID to release |
| 9624 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9625 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9626 | * |
| 9627 | * Note: this function is always asynchronous. |
| 9628 | */ |
| 9629 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9630 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9631 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9632 | bool privileged) |
| 9633 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9634 | struct rpc_message msg = { |
| 9635 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9636 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9637 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9638 | struct rpc_task_setup task_setup = { |
| 9639 | .rpc_client = server->client, |
| 9640 | .rpc_message = &msg, |
| 9641 | .callback_ops = &nfs41_free_stateid_ops, |
| 9642 | .flags = RPC_TASK_ASYNC, |
| 9643 | }; |
| 9644 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9645 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9646 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9647 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9648 | &task_setup.rpc_client, &msg); |
| 9649 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9650 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9651 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9652 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9653 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9654 | data->server = server; |
| 9655 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9656 | |
| 9657 | task_setup.callback_data = data; |
| 9658 | |
| 9659 | msg.rpc_argp = &data->args; |
| 9660 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9661 | 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] | 9662 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9663 | if (IS_ERR(task)) |
| 9664 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9665 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9666 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9667 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9668 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9669 | static void |
| 9670 | 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] | 9671 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9672 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9673 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9674 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9675 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9676 | } |
| 9677 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9678 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9679 | const nfs4_stateid *s2) |
| 9680 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9681 | if (s1->type != s2->type) |
| 9682 | return false; |
| 9683 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9684 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9685 | return false; |
| 9686 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9687 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9688 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9689 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9690 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9691 | } |
| 9692 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9693 | #endif /* CONFIG_NFS_V4_1 */ |
| 9694 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9695 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9696 | const nfs4_stateid *s2) |
| 9697 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9698 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9699 | } |
| 9700 | |
| 9701 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9702 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9703 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9704 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9705 | .recover_open = nfs4_open_reclaim, |
| 9706 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9707 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9708 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9709 | }; |
| 9710 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9711 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9712 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9713 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9714 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9715 | .recover_open = nfs4_open_reclaim, |
| 9716 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9717 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9718 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9719 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9720 | }; |
| 9721 | #endif /* CONFIG_NFS_V4_1 */ |
| 9722 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9723 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9724 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9725 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9726 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9727 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9728 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9729 | }; |
| 9730 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9731 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9732 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9733 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9734 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9735 | .recover_open = nfs41_open_expired, |
| 9736 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9737 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9738 | }; |
| 9739 | #endif /* CONFIG_NFS_V4_1 */ |
| 9740 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9741 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9742 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 9743 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9744 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9745 | }; |
| 9746 | |
| 9747 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9748 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9749 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 9750 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9751 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9752 | }; |
| 9753 | #endif |
| 9754 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9755 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9756 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9757 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9758 | }; |
| 9759 | |
| 9760 | #if defined(CONFIG_NFS_V4_1) |
| 9761 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9762 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9763 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9764 | }; |
| 9765 | #endif /* CONFIG_NFS_V4_1 */ |
| 9766 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9767 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9768 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9769 | .init_caps = NFS_CAP_READDIRPLUS |
| 9770 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9771 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9772 | .init_client = nfs40_init_client, |
| 9773 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9774 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9775 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9776 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9777 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9778 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9779 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9780 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9781 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9782 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9783 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9784 | }; |
| 9785 | |
| 9786 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9787 | static struct nfs_seqid * |
| 9788 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9789 | { |
| 9790 | return NULL; |
| 9791 | } |
| 9792 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9793 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9794 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9795 | .init_caps = NFS_CAP_READDIRPLUS |
| 9796 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9797 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9798 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9799 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 9800 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9801 | .init_client = nfs41_init_client, |
| 9802 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9803 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9804 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9805 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9806 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9807 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9808 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9809 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9810 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9811 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9812 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9813 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9814 | }; |
| 9815 | #endif |
| 9816 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9817 | #if defined(CONFIG_NFS_V4_2) |
| 9818 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9819 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9820 | .init_caps = NFS_CAP_READDIRPLUS |
| 9821 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9822 | | NFS_CAP_POSIX_LOCK |
| 9823 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9824 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9825 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9826 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9827 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 9828 | | NFS_CAP_OFFLOAD_CANCEL |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9829 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9830 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9831 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 9832 | | NFS_CAP_CLONE |
| 9833 | | NFS_CAP_LAYOUTERROR, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9834 | .init_client = nfs41_init_client, |
| 9835 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9836 | .match_stateid = nfs41_match_stateid, |
| 9837 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9838 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9839 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9840 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9841 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9842 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9843 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9844 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9845 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9846 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9847 | }; |
| 9848 | #endif |
| 9849 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9850 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9851 | [0] = &nfs_v4_0_minor_ops, |
| 9852 | #if defined(CONFIG_NFS_V4_1) |
| 9853 | [1] = &nfs_v4_1_minor_ops, |
| 9854 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9855 | #if defined(CONFIG_NFS_V4_2) |
| 9856 | [2] = &nfs_v4_2_minor_ops, |
| 9857 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9858 | }; |
| 9859 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9860 | 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] | 9861 | { |
| 9862 | ssize_t error, error2; |
| 9863 | |
| 9864 | error = generic_listxattr(dentry, list, size); |
| 9865 | if (error < 0) |
| 9866 | return error; |
| 9867 | if (list) { |
| 9868 | list += error; |
| 9869 | size -= error; |
| 9870 | } |
| 9871 | |
| 9872 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9873 | if (error2 < 0) |
| 9874 | return error2; |
| 9875 | return error + error2; |
| 9876 | } |
| 9877 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9878 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9879 | .create = nfs_create, |
| 9880 | .lookup = nfs_lookup, |
| 9881 | .atomic_open = nfs_atomic_open, |
| 9882 | .link = nfs_link, |
| 9883 | .unlink = nfs_unlink, |
| 9884 | .symlink = nfs_symlink, |
| 9885 | .mkdir = nfs_mkdir, |
| 9886 | .rmdir = nfs_rmdir, |
| 9887 | .mknod = nfs_mknod, |
| 9888 | .rename = nfs_rename, |
| 9889 | .permission = nfs_permission, |
| 9890 | .getattr = nfs_getattr, |
| 9891 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9892 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9893 | }; |
| 9894 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9895 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9896 | .permission = nfs_permission, |
| 9897 | .getattr = nfs_getattr, |
| 9898 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9899 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9900 | }; |
| 9901 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9902 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9903 | .version = 4, /* protocol version */ |
| 9904 | .dentry_ops = &nfs4_dentry_operations, |
| 9905 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9906 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9907 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9908 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9909 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9910 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9911 | .getattr = nfs4_proc_getattr, |
| 9912 | .setattr = nfs4_proc_setattr, |
| 9913 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9914 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9915 | .access = nfs4_proc_access, |
| 9916 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9917 | .create = nfs4_proc_create, |
| 9918 | .remove = nfs4_proc_remove, |
| 9919 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9920 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9921 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9922 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9923 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9924 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9925 | .link = nfs4_proc_link, |
| 9926 | .symlink = nfs4_proc_symlink, |
| 9927 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 9928 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9929 | .readdir = nfs4_proc_readdir, |
| 9930 | .mknod = nfs4_proc_mknod, |
| 9931 | .statfs = nfs4_proc_statfs, |
| 9932 | .fsinfo = nfs4_proc_fsinfo, |
| 9933 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9934 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9935 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9936 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9937 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9938 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9939 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9940 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9941 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9942 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9943 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9944 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9945 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9946 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9947 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9948 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9949 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9950 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9951 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9952 | .create_server = nfs4_create_server, |
| 9953 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9954 | }; |
| 9955 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9956 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9957 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9958 | .list = nfs4_xattr_list_nfs4_acl, |
| 9959 | .get = nfs4_xattr_get_nfs4_acl, |
| 9960 | .set = nfs4_xattr_set_nfs4_acl, |
| 9961 | }; |
| 9962 | |
| 9963 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9964 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9965 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9966 | &nfs4_xattr_nfs4_label_handler, |
| 9967 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9968 | NULL |
| 9969 | }; |
| 9970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9971 | /* |
| 9972 | * Local variables: |
| 9973 | * c-basic-offset: 8 |
| 9974 | * End: |
| 9975 | */ |