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 *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] | 95 | static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 96 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 97 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 98 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 100 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 101 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 102 | struct nfs4_slot *slot, |
| 103 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 104 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 105 | const struct cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 106 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 107 | const struct cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 108 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 109 | |
| 110 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 111 | static inline struct nfs4_label * |
| 112 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 113 | struct iattr *sattr, struct nfs4_label *label) |
| 114 | { |
| 115 | int err; |
| 116 | |
| 117 | if (label == NULL) |
| 118 | return NULL; |
| 119 | |
| 120 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 121 | return NULL; |
| 122 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 123 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 124 | &dentry->d_name, (void **)&label->label, &label->len); |
| 125 | if (err == 0) |
| 126 | return label; |
| 127 | |
| 128 | return NULL; |
| 129 | } |
| 130 | static inline void |
| 131 | nfs4_label_release_security(struct nfs4_label *label) |
| 132 | { |
| 133 | if (label) |
| 134 | security_release_secctx(label->label, label->len); |
| 135 | } |
| 136 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 137 | { |
| 138 | if (label) |
| 139 | return server->attr_bitmask; |
| 140 | |
| 141 | return server->attr_bitmask_nl; |
| 142 | } |
| 143 | #else |
| 144 | static inline struct nfs4_label * |
| 145 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 146 | struct iattr *sattr, struct nfs4_label *l) |
| 147 | { return NULL; } |
| 148 | static inline void |
| 149 | nfs4_label_release_security(struct nfs4_label *label) |
| 150 | { return; } |
| 151 | static inline u32 * |
| 152 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 153 | { return server->attr_bitmask; } |
| 154 | #endif |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 157 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 159 | if (err >= -1000) |
| 160 | return err; |
| 161 | switch (err) { |
| 162 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 163 | case -NFS4ERR_LAYOUTTRYLATER: |
| 164 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 165 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 166 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 167 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 168 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 169 | case -NFS4ERR_BADOWNER: |
| 170 | case -NFS4ERR_BADNAME: |
| 171 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 172 | case -NFS4ERR_SHARE_DENIED: |
| 173 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 174 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 175 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 176 | case -NFS4ERR_FILE_OPEN: |
| 177 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 178 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 180 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 181 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 183 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /* |
| 187 | * This is our standard bitmap for GETATTR requests. |
| 188 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 189 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | FATTR4_WORD0_TYPE |
| 191 | | FATTR4_WORD0_CHANGE |
| 192 | | FATTR4_WORD0_SIZE |
| 193 | | FATTR4_WORD0_FSID |
| 194 | | FATTR4_WORD0_FILEID, |
| 195 | FATTR4_WORD1_MODE |
| 196 | | FATTR4_WORD1_NUMLINKS |
| 197 | | FATTR4_WORD1_OWNER |
| 198 | | FATTR4_WORD1_OWNER_GROUP |
| 199 | | FATTR4_WORD1_RAWDEV |
| 200 | | FATTR4_WORD1_SPACE_USED |
| 201 | | FATTR4_WORD1_TIME_ACCESS |
| 202 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 203 | | FATTR4_WORD1_TIME_MODIFY |
| 204 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 205 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 206 | FATTR4_WORD2_SECURITY_LABEL |
| 207 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 210 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 211 | FATTR4_WORD0_TYPE |
| 212 | | FATTR4_WORD0_CHANGE |
| 213 | | FATTR4_WORD0_SIZE |
| 214 | | FATTR4_WORD0_FSID |
| 215 | | FATTR4_WORD0_FILEID, |
| 216 | FATTR4_WORD1_MODE |
| 217 | | FATTR4_WORD1_NUMLINKS |
| 218 | | FATTR4_WORD1_OWNER |
| 219 | | FATTR4_WORD1_OWNER_GROUP |
| 220 | | FATTR4_WORD1_RAWDEV |
| 221 | | FATTR4_WORD1_SPACE_USED |
| 222 | | FATTR4_WORD1_TIME_ACCESS |
| 223 | | FATTR4_WORD1_TIME_METADATA |
| 224 | | FATTR4_WORD1_TIME_MODIFY, |
| 225 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 226 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 227 | | FATTR4_WORD2_SECURITY_LABEL |
| 228 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 229 | }; |
| 230 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 231 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 232 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 233 | | FATTR4_WORD0_FILEID, |
| 234 | }; |
| 235 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 236 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | FATTR4_WORD0_FILES_AVAIL |
| 238 | | FATTR4_WORD0_FILES_FREE |
| 239 | | FATTR4_WORD0_FILES_TOTAL, |
| 240 | FATTR4_WORD1_SPACE_AVAIL |
| 241 | | FATTR4_WORD1_SPACE_FREE |
| 242 | | FATTR4_WORD1_SPACE_TOTAL |
| 243 | }; |
| 244 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 245 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | FATTR4_WORD0_MAXLINK |
| 247 | | FATTR4_WORD0_MAXNAME, |
| 248 | 0 |
| 249 | }; |
| 250 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 251 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | | FATTR4_WORD0_MAXREAD |
| 253 | | FATTR4_WORD0_MAXWRITE |
| 254 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 255 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 256 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 257 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 258 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | }; |
| 260 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 261 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 262 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 263 | | FATTR4_WORD0_SIZE |
| 264 | | FATTR4_WORD0_FSID |
| 265 | | FATTR4_WORD0_FILEID |
| 266 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 267 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 268 | | FATTR4_WORD1_OWNER_GROUP |
| 269 | | FATTR4_WORD1_RAWDEV |
| 270 | | FATTR4_WORD1_SPACE_USED |
| 271 | | FATTR4_WORD1_TIME_ACCESS |
| 272 | | FATTR4_WORD1_TIME_METADATA |
| 273 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 274 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 277 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
| 278 | struct inode *inode) |
| 279 | { |
| 280 | unsigned long cache_validity; |
| 281 | |
| 282 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 283 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 284 | return; |
| 285 | |
| 286 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 287 | if (!(cache_validity & NFS_INO_REVAL_FORCED)) |
| 288 | cache_validity &= ~(NFS_INO_INVALID_CHANGE |
| 289 | | NFS_INO_INVALID_SIZE); |
| 290 | |
| 291 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 292 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 293 | |
| 294 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 295 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
| 296 | } |
| 297 | |
| 298 | static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, |
| 299 | const __u32 *src, struct inode *inode) |
| 300 | { |
| 301 | nfs4_bitmap_copy_adjust(dst, src, inode); |
| 302 | } |
| 303 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 304 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | struct nfs4_readdir_arg *readdir) |
| 306 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 307 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 308 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 311 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | readdir->cookie = 0; |
| 317 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 318 | if (cookie == 2) |
| 319 | return; |
| 320 | |
| 321 | /* |
| 322 | * NFSv4 servers do not return entries for '.' and '..' |
| 323 | * Therefore, we fake these entries here. We let '.' |
| 324 | * have cookie 0 and '..' have cookie 1. Note that |
| 325 | * when talking to the server, we always send cookie 0 |
| 326 | * instead of 1 or 2. |
| 327 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 328 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | if (cookie == 0) { |
| 331 | *p++ = xdr_one; /* next */ |
| 332 | *p++ = xdr_zero; /* cookie, first word */ |
| 333 | *p++ = xdr_one; /* cookie, second word */ |
| 334 | *p++ = xdr_one; /* entry len */ |
| 335 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 336 | p++; |
| 337 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 338 | *p++ = htonl(attrs); /* bitmap */ |
| 339 | *p++ = htonl(12); /* attribute buffer length */ |
| 340 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 341 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | *p++ = xdr_one; /* next */ |
| 345 | *p++ = xdr_zero; /* cookie, first word */ |
| 346 | *p++ = xdr_two; /* cookie, second word */ |
| 347 | *p++ = xdr_two; /* entry len */ |
| 348 | memcpy(p, "..\0\0", 4); /* entry */ |
| 349 | p++; |
| 350 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 351 | *p++ = htonl(attrs); /* bitmap */ |
| 352 | *p++ = htonl(12); /* attribute buffer length */ |
| 353 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 354 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | readdir->pgbase = (char *)p - (char *)start; |
| 357 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 358 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 361 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 362 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 363 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 364 | { |
| 365 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 366 | |
| 367 | ops->test_and_free_expired(server, stateid, cred); |
| 368 | } |
| 369 | |
| 370 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 371 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 372 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 373 | { |
| 374 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 375 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 376 | } |
| 377 | |
| 378 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 379 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 380 | const struct cred *cred) |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 381 | { |
| 382 | nfs4_stateid tmp; |
| 383 | |
| 384 | nfs4_stateid_copy(&tmp, stateid); |
| 385 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 386 | } |
| 387 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 388 | static long nfs4_update_delay(long *timeout) |
| 389 | { |
| 390 | long ret; |
| 391 | if (!timeout) |
| 392 | return NFS4_POLL_RETRY_MAX; |
| 393 | if (*timeout <= 0) |
| 394 | *timeout = NFS4_POLL_RETRY_MIN; |
| 395 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 396 | *timeout = NFS4_POLL_RETRY_MAX; |
| 397 | ret = *timeout; |
| 398 | *timeout <<= 1; |
| 399 | return ret; |
| 400 | } |
| 401 | |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 402 | static int nfs4_delay_killable(long *timeout) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 403 | { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | might_sleep(); |
| 405 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 406 | freezable_schedule_timeout_killable_unsafe( |
| 407 | nfs4_update_delay(timeout)); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 408 | if (!__fatal_signal_pending(current)) |
| 409 | return 0; |
| 410 | return -EINTR; |
| 411 | } |
| 412 | |
| 413 | static int nfs4_delay_interruptible(long *timeout) |
| 414 | { |
| 415 | might_sleep(); |
| 416 | |
| 417 | freezable_schedule_timeout_interruptible(nfs4_update_delay(timeout)); |
| 418 | if (!signal_pending(current)) |
| 419 | return 0; |
| 420 | return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
| 421 | } |
| 422 | |
| 423 | static int nfs4_delay(long *timeout, bool interruptible) |
| 424 | { |
| 425 | if (interruptible) |
| 426 | return nfs4_delay_interruptible(timeout); |
| 427 | return nfs4_delay_killable(timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 428 | } |
| 429 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 430 | static const nfs4_stateid * |
| 431 | nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
| 432 | { |
| 433 | if (!stateid) |
| 434 | return NULL; |
| 435 | switch (stateid->type) { |
| 436 | case NFS4_OPEN_STATEID_TYPE: |
| 437 | case NFS4_LOCK_STATEID_TYPE: |
| 438 | case NFS4_DELEGATION_STATEID_TYPE: |
| 439 | return stateid; |
| 440 | default: |
| 441 | break; |
| 442 | } |
| 443 | return NULL; |
| 444 | } |
| 445 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 446 | /* This is the error handling routine for processes that are allowed |
| 447 | * to sleep. |
| 448 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 449 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 450 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 451 | { |
| 452 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 453 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 454 | const nfs4_stateid *stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 455 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 456 | int ret = errorcode; |
| 457 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 458 | exception->delay = 0; |
| 459 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 460 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 461 | |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 462 | stateid = nfs4_recoverable_stateid(exception->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 463 | if (stateid == NULL && state != NULL) |
Trond Myklebust | 50c8000 | 2019-07-11 19:02:18 -0400 | [diff] [blame] | 464 | stateid = nfs4_recoverable_stateid(&state->stateid); |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 465 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 466 | switch(errorcode) { |
| 467 | case 0: |
| 468 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 469 | case -NFS4ERR_BADHANDLE: |
| 470 | case -ESTALE: |
| 471 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 472 | pnfs_destroy_layout(NFS_I(inode)); |
| 473 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 474 | case -NFS4ERR_DELEG_REVOKED: |
| 475 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 476 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 477 | case -NFS4ERR_BAD_STATEID: |
Olga Kornievskaia | fefa1a8 | 2019-06-14 14:22:12 -0400 | [diff] [blame^] | 478 | case -NFS4ERR_PARTNER_NO_AUTH: |
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 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 1721 | int update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 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 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3316 | /* |
| 3317 | * Update the seqid of an open stateid |
| 3318 | */ |
| 3319 | static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
| 3320 | struct nfs4_state *state) |
| 3321 | { |
| 3322 | __be32 seqid_open; |
| 3323 | u32 dst_seqid; |
| 3324 | int seq; |
| 3325 | |
| 3326 | for (;;) { |
| 3327 | if (!nfs4_valid_open_stateid(state)) |
| 3328 | break; |
| 3329 | seq = read_seqbegin(&state->seqlock); |
| 3330 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3331 | nfs4_stateid_copy(dst, &state->open_stateid); |
| 3332 | if (read_seqretry(&state->seqlock, seq)) |
| 3333 | continue; |
| 3334 | break; |
| 3335 | } |
| 3336 | seqid_open = state->open_stateid.seqid; |
| 3337 | if (read_seqretry(&state->seqlock, seq)) |
| 3338 | continue; |
| 3339 | |
| 3340 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3341 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
| 3342 | dst->seqid = seqid_open; |
| 3343 | break; |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | /* |
| 3348 | * Update the seqid of an open stateid after receiving |
| 3349 | * NFS4ERR_OLD_STATEID |
| 3350 | */ |
| 3351 | static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
| 3352 | struct nfs4_state *state) |
| 3353 | { |
| 3354 | __be32 seqid_open; |
| 3355 | u32 dst_seqid; |
| 3356 | bool ret; |
| 3357 | int seq; |
| 3358 | |
| 3359 | for (;;) { |
| 3360 | ret = false; |
| 3361 | if (!nfs4_valid_open_stateid(state)) |
| 3362 | break; |
| 3363 | seq = read_seqbegin(&state->seqlock); |
| 3364 | if (!nfs4_state_match_open_stateid_other(state, dst)) { |
| 3365 | if (read_seqretry(&state->seqlock, seq)) |
| 3366 | continue; |
| 3367 | break; |
| 3368 | } |
| 3369 | seqid_open = state->open_stateid.seqid; |
| 3370 | if (read_seqretry(&state->seqlock, seq)) |
| 3371 | continue; |
| 3372 | |
| 3373 | dst_seqid = be32_to_cpu(dst->seqid); |
| 3374 | if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) >= 0) |
| 3375 | dst->seqid = cpu_to_be32(dst_seqid + 1); |
| 3376 | else |
| 3377 | dst->seqid = seqid_open; |
| 3378 | ret = true; |
| 3379 | break; |
| 3380 | } |
| 3381 | |
| 3382 | return ret; |
| 3383 | } |
| 3384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | struct nfs4_closedata { |
| 3386 | struct inode *inode; |
| 3387 | struct nfs4_state *state; |
| 3388 | struct nfs_closeargs arg; |
| 3389 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3390 | struct { |
| 3391 | struct nfs4_layoutreturn_args arg; |
| 3392 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3393 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3394 | u32 roc_barrier; |
| 3395 | bool roc; |
| 3396 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3397 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3398 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | }; |
| 3400 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3401 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3402 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3403 | struct nfs4_closedata *calldata = data; |
| 3404 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3405 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3406 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3407 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3408 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3409 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3410 | nfs4_put_open_state(calldata->state); |
| 3411 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3412 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3413 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3414 | kfree(calldata); |
| 3415 | } |
| 3416 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3417 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3419 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3422 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3423 | struct nfs4_exception exception = { |
| 3424 | .state = state, |
| 3425 | .inode = calldata->inode, |
| 3426 | .stateid = &calldata->arg.stateid, |
| 3427 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3429 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3430 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3431 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3432 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3433 | |
| 3434 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 3435 | if (pnfs_roc_done(task, calldata->inode, |
| 3436 | &calldata->arg.lr_args, |
| 3437 | &calldata->res.lr_res, |
| 3438 | &calldata->res.lr_ret) == -EAGAIN) |
| 3439 | goto out_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3440 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3441 | /* 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] | 3442 | * the state_owner. we keep this around to process errors |
| 3443 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | switch (task->tk_status) { |
| 3445 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3446 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3447 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3448 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3449 | case -NFS4ERR_ACCESS: |
| 3450 | if (calldata->arg.bitmask != NULL) { |
| 3451 | calldata->arg.bitmask = NULL; |
| 3452 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3453 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3454 | |
| 3455 | } |
| 3456 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3457 | case -NFS4ERR_OLD_STATEID: |
| 3458 | /* Did we race with OPEN? */ |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3459 | if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3460 | state)) |
| 3461 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3462 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3463 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3465 | case -NFS4ERR_EXPIRED: |
| 3466 | nfs4_free_revoked_stateid(server, |
| 3467 | &calldata->arg.stateid, |
| 3468 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3469 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3470 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | e217e82 | 2019-09-20 07:23:46 -0400 | [diff] [blame] | 3471 | if (calldata->arg.fmode == 0) |
| 3472 | break; |
| 3473 | /* Fallthrough */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3475 | task->tk_status = nfs4_async_handle_exception(task, |
| 3476 | server, task->tk_status, &exception); |
| 3477 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3478 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3480 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3481 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3482 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3483 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3484 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3485 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3486 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3487 | return; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3488 | out_restart: |
| 3489 | task->tk_status = 0; |
| 3490 | rpc_restart_call_prepare(task); |
| 3491 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | } |
| 3493 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3494 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3496 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3497 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3498 | struct inode *inode = calldata->inode; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3499 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3500 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3501 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3502 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3503 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3504 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3505 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3506 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3507 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3508 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3509 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3510 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3511 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3512 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3513 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3514 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3515 | if (state->n_rdonly == 0) |
| 3516 | call_close |= is_rdonly; |
| 3517 | else if (is_rdonly) |
| 3518 | calldata->arg.fmode |= FMODE_READ; |
| 3519 | if (state->n_wronly == 0) |
| 3520 | call_close |= is_wronly; |
| 3521 | else if (is_wronly) |
| 3522 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3523 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3524 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3525 | } else if (is_rdwr) |
| 3526 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3527 | |
Trond Myklebust | 0e0cb35 | 2019-09-20 07:23:47 -0400 | [diff] [blame] | 3528 | nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
| 3529 | if (!nfs4_valid_open_stateid(state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3530 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3531 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3532 | |
| 3533 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3534 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3535 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3536 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3537 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3538 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3539 | nfs_release_seqid(calldata->arg.seqid); |
| 3540 | goto out_wait; |
| 3541 | } |
| 3542 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3543 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3544 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3545 | calldata->arg.lr_args = NULL; |
| 3546 | calldata->res.lr_res = NULL; |
| 3547 | } |
| 3548 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3549 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3550 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3551 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3552 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3553 | /* Close-to-open cache consistency revalidation */ |
| 3554 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3555 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3556 | else |
| 3557 | calldata->arg.bitmask = NULL; |
| 3558 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3559 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3560 | calldata->arg.share_access = |
| 3561 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3562 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3563 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3564 | if (calldata->res.fattr == NULL) |
| 3565 | calldata->arg.bitmask = NULL; |
| 3566 | else if (calldata->arg.bitmask == NULL) |
| 3567 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3568 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3569 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3570 | &calldata->arg.seq_args, |
| 3571 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3572 | task) != 0) |
| 3573 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3574 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3575 | return; |
| 3576 | out_no_action: |
| 3577 | task->tk_action = NULL; |
| 3578 | out_wait: |
| 3579 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3582 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3583 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3584 | .rpc_call_done = nfs4_close_done, |
| 3585 | .rpc_release = nfs4_free_closedata, |
| 3586 | }; |
| 3587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | /* |
| 3589 | * It is possible for data to be read/written from a mem-mapped file |
| 3590 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3591 | * This means that we can't safely call nfsv4 close on a file until |
| 3592 | * the inode is cleared. This in turn means that we are not good |
| 3593 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3594 | * share state even when we are done with one of the three share |
| 3595 | * stateid's in the inode. |
| 3596 | * |
| 3597 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3598 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3599 | 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] | 3600 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3601 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3602 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3604 | struct nfs4_state_owner *sp = state->owner; |
| 3605 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3606 | struct rpc_message msg = { |
| 3607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3608 | .rpc_cred = state->owner->so_cred, |
| 3609 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3610 | struct rpc_task_setup task_setup_data = { |
| 3611 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3612 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3613 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3614 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3615 | .flags = RPC_TASK_ASYNC, |
| 3616 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3617 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3619 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3620 | &task_setup_data.rpc_client, &msg); |
| 3621 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3622 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3624 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3625 | 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] | 3626 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3628 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3629 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3630 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3632 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3633 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3634 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3635 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3636 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3637 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3638 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3639 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3640 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3641 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3642 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3643 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3644 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3645 | if (calldata->lr.roc) { |
| 3646 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3647 | calldata->res.lr_res = &calldata->lr.res; |
| 3648 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3649 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3650 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3651 | msg.rpc_argp = &calldata->arg; |
| 3652 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3653 | task_setup_data.callback_data = calldata; |
| 3654 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3655 | if (IS_ERR(task)) |
| 3656 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3657 | status = 0; |
| 3658 | if (wait) |
| 3659 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3660 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3661 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3662 | out_free_calldata: |
| 3663 | kfree(calldata); |
| 3664 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3665 | nfs4_put_open_state(state); |
| 3666 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3667 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3670 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3671 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3672 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3675 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3676 | |
| 3677 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3679 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3680 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3681 | |
| 3682 | nfs4_label_release_security(label); |
| 3683 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3684 | if (IS_ERR(state)) |
| 3685 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3686 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3689 | 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] | 3690 | { |
| 3691 | if (ctx->state == NULL) |
| 3692 | return; |
| 3693 | if (is_sync) |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3694 | nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3695 | else |
Trond Myklebust | 1bf85d8 | 2019-06-27 06:30:48 -0400 | [diff] [blame] | 3696 | nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3699 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3700 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3701 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3704 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3705 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3706 | struct nfs4_server_caps_arg args = { |
| 3707 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3708 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3709 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | struct nfs4_server_caps_res res = {}; |
| 3711 | struct rpc_message msg = { |
| 3712 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3713 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | .rpc_resp = &res, |
| 3715 | }; |
| 3716 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3717 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3719 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3720 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3721 | FATTR4_WORD0_LINK_SUPPORT | |
| 3722 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3723 | FATTR4_WORD0_ACLSUPPORT; |
| 3724 | if (minorversion) |
| 3725 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3726 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3727 | 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] | 3728 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3729 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3730 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3731 | case 0: |
| 3732 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3733 | res.attr_bitmask[2] = 0; |
| 3734 | break; |
| 3735 | case 1: |
| 3736 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3737 | break; |
| 3738 | case 2: |
| 3739 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3740 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3742 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3743 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3744 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3745 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3746 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3747 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3748 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3749 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | server->caps |= NFS_CAP_ACLS; |
| 3751 | if (res.has_links != 0) |
| 3752 | server->caps |= NFS_CAP_HARDLINKS; |
| 3753 | if (res.has_symlinks != 0) |
| 3754 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3755 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3756 | server->caps |= NFS_CAP_FILEID; |
| 3757 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3758 | server->caps |= NFS_CAP_MODE; |
| 3759 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3760 | server->caps |= NFS_CAP_NLINK; |
| 3761 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3762 | server->caps |= NFS_CAP_OWNER; |
| 3763 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3764 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3765 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3766 | server->caps |= NFS_CAP_ATIME; |
| 3767 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3768 | server->caps |= NFS_CAP_CTIME; |
| 3769 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3770 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3771 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3772 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3773 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3774 | #endif |
| 3775 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3776 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3777 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3778 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3779 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3780 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3781 | 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] | 3782 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3783 | |
| 3784 | /* Avoid a regression due to buggy server */ |
| 3785 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3786 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3787 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3788 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3791 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | return status; |
| 3795 | } |
| 3796 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3797 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3799 | struct nfs4_exception exception = { |
| 3800 | .interruptible = true, |
| 3801 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | int err; |
| 3803 | do { |
| 3804 | err = nfs4_handle_exception(server, |
| 3805 | _nfs4_server_capabilities(server, fhandle), |
| 3806 | &exception); |
| 3807 | } while (exception.retry); |
| 3808 | return err; |
| 3809 | } |
| 3810 | |
| 3811 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3812 | struct nfs_fsinfo *info) |
| 3813 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3814 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3816 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | }; |
| 3818 | struct nfs4_lookup_res res = { |
| 3819 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3820 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | .fh = fhandle, |
| 3822 | }; |
| 3823 | struct rpc_message msg = { |
| 3824 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3825 | .rpc_argp = &args, |
| 3826 | .rpc_resp = &res, |
| 3827 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3828 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3829 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3830 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3831 | /* |
| 3832 | * Process the label in the upcoming getfattr |
| 3833 | */ |
| 3834 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3835 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3836 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3837 | 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] | 3838 | } |
| 3839 | |
| 3840 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3841 | struct nfs_fsinfo *info) |
| 3842 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 3843 | struct nfs4_exception exception = { |
| 3844 | .interruptible = true, |
| 3845 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | int err; |
| 3847 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3848 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3849 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3850 | switch (err) { |
| 3851 | case 0: |
| 3852 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3853 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3854 | default: |
| 3855 | err = nfs4_handle_exception(server, err, &exception); |
| 3856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3858 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | return err; |
| 3860 | } |
| 3861 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3862 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3863 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3864 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3865 | struct rpc_auth_create_args auth_args = { |
| 3866 | .pseudoflavor = flavor, |
| 3867 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3868 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3869 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3870 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3871 | if (IS_ERR(auth)) |
| 3872 | return -EACCES; |
| 3873 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3876 | /* |
| 3877 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3878 | * |
| 3879 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3880 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3881 | * |
| 3882 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3883 | * negative errno value. |
| 3884 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3885 | 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] | 3886 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3888 | /* Per 3530bis 15.33.5 */ |
| 3889 | static const rpc_authflavor_t flav_array[] = { |
| 3890 | RPC_AUTH_GSS_KRB5P, |
| 3891 | RPC_AUTH_GSS_KRB5I, |
| 3892 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3893 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3894 | RPC_AUTH_NULL, |
| 3895 | }; |
| 3896 | int status = -EPERM; |
| 3897 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3899 | if (server->auth_info.flavor_len > 0) { |
| 3900 | /* try each flavor specified by user */ |
| 3901 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3902 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3903 | server->auth_info.flavors[i]); |
| 3904 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3905 | continue; |
| 3906 | break; |
| 3907 | } |
| 3908 | } else { |
| 3909 | /* no flavors specified by user, try default list */ |
| 3910 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3911 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3912 | flav_array[i]); |
| 3913 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3914 | continue; |
| 3915 | break; |
| 3916 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3917 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3918 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3919 | /* |
Colin Ian King | d3787af | 2018-10-26 19:10:31 +0100 | [diff] [blame] | 3920 | * -EACCES could mean that the user doesn't have correct permissions |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3921 | * to access the mount. It could also mean that we tried to mount |
| 3922 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3923 | * existing mount programs don't handle -EACCES very well so it should |
| 3924 | * be mapped to -EPERM instead. |
| 3925 | */ |
| 3926 | if (status == -EACCES) |
| 3927 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3928 | return status; |
| 3929 | } |
| 3930 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3931 | /** |
| 3932 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3933 | * @server: initialized nfs_server handle |
| 3934 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3935 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3936 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3937 | * |
| 3938 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3939 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3940 | 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] | 3941 | struct nfs_fsinfo *info, |
| 3942 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3943 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3944 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3945 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3946 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3947 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3948 | |
| 3949 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3950 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3951 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | if (status == 0) |
| 3954 | status = nfs4_server_capabilities(server, fhandle); |
| 3955 | if (status == 0) |
| 3956 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3957 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3958 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | } |
| 3960 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3961 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3962 | struct nfs_fsinfo *info) |
| 3963 | { |
| 3964 | int error; |
| 3965 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3966 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3967 | |
| 3968 | error = nfs4_server_capabilities(server, mntfh); |
| 3969 | if (error < 0) { |
| 3970 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3971 | return error; |
| 3972 | } |
| 3973 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3974 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3975 | if (IS_ERR(label)) |
| 3976 | return PTR_ERR(label); |
| 3977 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3978 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3979 | if (error < 0) { |
| 3980 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3981 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3985 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3986 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3987 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3988 | err_free_label: |
| 3989 | nfs4_label_free(label); |
| 3990 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3991 | return error; |
| 3992 | } |
| 3993 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3994 | /* |
| 3995 | * Get locations and (maybe) other attributes of a referral. |
| 3996 | * Note that we'll actually follow the referral later when |
| 3997 | * we detect fsid mismatch in inode revalidation |
| 3998 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3999 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 4000 | const struct qstr *name, struct nfs_fattr *fattr, |
| 4001 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4002 | { |
| 4003 | int status = -ENOMEM; |
| 4004 | struct page *page = NULL; |
| 4005 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4006 | |
| 4007 | page = alloc_page(GFP_KERNEL); |
| 4008 | if (page == NULL) |
| 4009 | goto out; |
| 4010 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 4011 | if (locations == NULL) |
| 4012 | goto out; |
| 4013 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4014 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4015 | if (status != 0) |
| 4016 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4017 | |
| 4018 | /* |
| 4019 | * If the fsid didn't change, this is a migration event, not a |
| 4020 | * referral. Cause us to drop into the exception handler, which |
| 4021 | * will kick off migration recovery. |
| 4022 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4023 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4024 | dprintk("%s: server did not return a different fsid for" |
| 4025 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4026 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4027 | goto out; |
| 4028 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4029 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 4030 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4031 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4032 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4033 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4034 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 4035 | out: |
| 4036 | if (page) |
| 4037 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 4038 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 4039 | return status; |
| 4040 | } |
| 4041 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4042 | 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] | 4043 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4044 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4046 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | struct nfs4_getattr_arg args = { |
| 4048 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4049 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | }; |
| 4051 | struct nfs4_getattr_res res = { |
| 4052 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4053 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | .server = server, |
| 4055 | }; |
| 4056 | struct rpc_message msg = { |
| 4057 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4058 | .rpc_argp = &args, |
| 4059 | .rpc_resp = &res, |
| 4060 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4061 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 4062 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4063 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4064 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4065 | 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] | 4066 | } |
| 4067 | |
Olga Kornievskaia | ec4b092 | 2019-10-08 16:33:53 -0400 | [diff] [blame] | 4068 | int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4069 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 4070 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4072 | struct nfs4_exception exception = { |
| 4073 | .interruptible = true, |
| 4074 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | int err; |
| 4076 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 4077 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4078 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 4079 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | &exception); |
| 4081 | } while (exception.retry); |
| 4082 | return err; |
| 4083 | } |
| 4084 | |
| 4085 | /* |
| 4086 | * The file is not closed if it is opened due to the a request to change |
| 4087 | * the size of the file. The open call will not be needed once the |
| 4088 | * VFS layer lookup-intents are implemented. |
| 4089 | * |
| 4090 | * Close is called when the inode is destroyed. |
| 4091 | * If we haven't opened the file for O_WRONLY, we |
| 4092 | * need to in the size_change case to obtain a stateid. |
| 4093 | * |
| 4094 | * Got race? |
| 4095 | * Because OPEN is always done by name in nfsv4, it is |
| 4096 | * possible that we opened a different file by the same |
| 4097 | * name. We can recognize this race condition, but we |
| 4098 | * can't do anything about it besides returning an error. |
| 4099 | * |
| 4100 | * This will be fixed with VFS changes (lookup-intent). |
| 4101 | */ |
| 4102 | static int |
| 4103 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 4104 | struct iattr *sattr) |
| 4105 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4106 | struct inode *inode = d_inode(dentry); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 4107 | const struct cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4108 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4109 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | int status; |
| 4111 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 4112 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 4113 | sattr->ia_valid & ATTR_SIZE && |
| 4114 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 4115 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 4116 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4117 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4119 | /* Deal with open(O_TRUNC) */ |
| 4120 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4121 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4122 | |
| 4123 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 4124 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 4125 | return 0; |
| 4126 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 4127 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4128 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4129 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4130 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4131 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 4132 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 4133 | } |
| 4134 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4135 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4136 | if (IS_ERR(label)) |
| 4137 | return PTR_ERR(label); |
| 4138 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4139 | /* Return any delegations if we're going to change ACLs */ |
| 4140 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4141 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 4142 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4143 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4144 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 4145 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4146 | nfs_setsecurity(inode, fattr, label); |
| 4147 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4148 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | return status; |
| 4150 | } |
| 4151 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4152 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 4153 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4154 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4155 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4156 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4157 | int status; |
| 4158 | struct nfs4_lookup_arg args = { |
| 4159 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4160 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4161 | .name = name, |
| 4162 | }; |
| 4163 | struct nfs4_lookup_res res = { |
| 4164 | .server = server, |
| 4165 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4166 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4167 | .fh = fhandle, |
| 4168 | }; |
| 4169 | struct rpc_message msg = { |
| 4170 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4171 | .rpc_argp = &args, |
| 4172 | .rpc_resp = &res, |
| 4173 | }; |
| 4174 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4175 | args.bitmask = nfs4_bitmask(server, label); |
| 4176 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4177 | nfs_fattr_init(fattr); |
| 4178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4180 | 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] | 4181 | dprintk("NFS reply lookup: %d\n", status); |
| 4182 | return status; |
| 4183 | } |
| 4184 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4185 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4186 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4187 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4188 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4189 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4190 | fattr->nlink = 2; |
| 4191 | } |
| 4192 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4193 | 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] | 4194 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4195 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4196 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4197 | struct nfs4_exception exception = { |
| 4198 | .interruptible = true, |
| 4199 | }; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4200 | struct rpc_clnt *client = *clnt; |
| 4201 | int err; |
| 4202 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4203 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4204 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4205 | switch (err) { |
| 4206 | case -NFS4ERR_BADNAME: |
| 4207 | err = -ENOENT; |
| 4208 | goto out; |
| 4209 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4210 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4211 | if (err == -NFS4ERR_MOVED) |
| 4212 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4213 | goto out; |
| 4214 | case -NFS4ERR_WRONGSEC: |
| 4215 | err = -EPERM; |
| 4216 | if (client != *clnt) |
| 4217 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4218 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4219 | if (IS_ERR(client)) |
| 4220 | return PTR_ERR(client); |
| 4221 | |
| 4222 | exception.retry = 1; |
| 4223 | break; |
| 4224 | default: |
| 4225 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4226 | } |
| 4227 | } while (exception.retry); |
| 4228 | |
| 4229 | out: |
| 4230 | if (err == 0) |
| 4231 | *clnt = client; |
| 4232 | else if (client != *clnt) |
| 4233 | rpc_shutdown_client(client); |
| 4234 | |
| 4235 | return err; |
| 4236 | } |
| 4237 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4238 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4239 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4240 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4242 | int status; |
| 4243 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4244 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4245 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4246 | if (client != NFS_CLIENT(dir)) { |
| 4247 | rpc_shutdown_client(client); |
| 4248 | nfs_fixup_secinfo_attributes(fattr); |
| 4249 | } |
| 4250 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | } |
| 4252 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4253 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4254 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4255 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4256 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4257 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4258 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4259 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4260 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4261 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4262 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4263 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4264 | } |
| 4265 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4266 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4267 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4268 | struct nfs4_label *label) |
| 4269 | { |
| 4270 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4271 | struct nfs_server *server = NFS_SERVER(inode); |
| 4272 | int status; |
| 4273 | struct nfs4_lookupp_arg args = { |
| 4274 | .bitmask = server->attr_bitmask, |
| 4275 | .fh = NFS_FH(inode), |
| 4276 | }; |
| 4277 | struct nfs4_lookupp_res res = { |
| 4278 | .server = server, |
| 4279 | .fattr = fattr, |
| 4280 | .label = label, |
| 4281 | .fh = fhandle, |
| 4282 | }; |
| 4283 | struct rpc_message msg = { |
| 4284 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4285 | .rpc_argp = &args, |
| 4286 | .rpc_resp = &res, |
| 4287 | }; |
| 4288 | |
| 4289 | args.bitmask = nfs4_bitmask(server, label); |
| 4290 | |
| 4291 | nfs_fattr_init(fattr); |
| 4292 | |
| 4293 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4294 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4295 | &res.seq_res, 0); |
| 4296 | dprintk("NFS reply lookupp: %d\n", status); |
| 4297 | return status; |
| 4298 | } |
| 4299 | |
| 4300 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4301 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4302 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4303 | struct nfs4_exception exception = { |
| 4304 | .interruptible = true, |
| 4305 | }; |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4306 | int err; |
| 4307 | do { |
| 4308 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4309 | trace_nfs4_lookupp(inode, err); |
| 4310 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4311 | &exception); |
| 4312 | } while (exception.retry); |
| 4313 | return err; |
| 4314 | } |
| 4315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4317 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4318 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | struct nfs4_accessargs args = { |
| 4320 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4321 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4323 | struct nfs4_accessres res = { |
| 4324 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4325 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | struct rpc_message msg = { |
| 4327 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4328 | .rpc_argp = &args, |
| 4329 | .rpc_resp = &res, |
| 4330 | .rpc_cred = entry->cred, |
| 4331 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4332 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4334 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4335 | res.fattr = nfs_alloc_fattr(); |
| 4336 | if (res.fattr == NULL) |
| 4337 | return -ENOMEM; |
| 4338 | args.bitmask = server->cache_consistency_bitmask; |
| 4339 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4340 | 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] | 4341 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4342 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4343 | if (res.fattr) |
| 4344 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4346 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | return status; |
| 4348 | } |
| 4349 | |
| 4350 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4351 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4352 | struct nfs4_exception exception = { |
| 4353 | .interruptible = true, |
| 4354 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | int err; |
| 4356 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4357 | err = _nfs4_proc_access(inode, entry); |
| 4358 | trace_nfs4_access(inode, err); |
| 4359 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | &exception); |
| 4361 | } while (exception.retry); |
| 4362 | return err; |
| 4363 | } |
| 4364 | |
| 4365 | /* |
| 4366 | * TODO: For the time being, we don't try to get any attributes |
| 4367 | * along with any of the zero-copy operations READ, READDIR, |
| 4368 | * READLINK, WRITE. |
| 4369 | * |
| 4370 | * In the case of the first three, we want to put the GETATTR |
| 4371 | * after the read-type operation -- this is because it is hard |
| 4372 | * to predict the length of a GETATTR response in v4, and thus |
| 4373 | * align the READ data correctly. This means that the GETATTR |
| 4374 | * may end up partially falling into the page cache, and we should |
| 4375 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4376 | * To do this efficiently, we need to know the total length |
| 4377 | * of data received, which doesn't seem to be available outside |
| 4378 | * of the RPC layer. |
| 4379 | * |
| 4380 | * In the case of WRITE, we also want to put the GETATTR after |
| 4381 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4382 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | * |
| 4384 | * Both of these changes to the XDR layer would in fact be quite |
| 4385 | * minor, but I decided to leave them for a subsequent patch. |
| 4386 | */ |
| 4387 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4388 | unsigned int pgbase, unsigned int pglen) |
| 4389 | { |
| 4390 | struct nfs4_readlink args = { |
| 4391 | .fh = NFS_FH(inode), |
| 4392 | .pgbase = pgbase, |
| 4393 | .pglen = pglen, |
| 4394 | .pages = &page, |
| 4395 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4396 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | struct rpc_message msg = { |
| 4398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4399 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4400 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | }; |
| 4402 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4403 | 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] | 4404 | } |
| 4405 | |
| 4406 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4407 | unsigned int pgbase, unsigned int pglen) |
| 4408 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4409 | struct nfs4_exception exception = { |
| 4410 | .interruptible = true, |
| 4411 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | int err; |
| 4413 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4414 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4415 | trace_nfs4_readlink(inode, err); |
| 4416 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | &exception); |
| 4418 | } while (exception.retry); |
| 4419 | return err; |
| 4420 | } |
| 4421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4423 | * 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] | 4424 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | static int |
| 4426 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4427 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4429 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4430 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4431 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | int status = 0; |
| 4434 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4435 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4436 | if (IS_ERR(ctx)) |
| 4437 | return PTR_ERR(ctx); |
| 4438 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4439 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4440 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4441 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4442 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4443 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | if (IS_ERR(state)) { |
| 4445 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4446 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4449 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4450 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | return status; |
| 4452 | } |
| 4453 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4454 | static int |
| 4455 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4457 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4458 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4460 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4462 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4463 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4464 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4466 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4467 | .rpc_argp = &args, |
| 4468 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4470 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4471 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4472 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4473 | 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] | 4474 | if (status == 0) { |
| 4475 | spin_lock(&dir->i_lock); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4476 | update_changeattr_locked(dir, &res.cinfo, timestamp, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4477 | /* Removing a directory decrements nlink in the parent */ |
| 4478 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4479 | nfs4_dec_nlink_locked(dir); |
| 4480 | spin_unlock(&dir->i_lock); |
| 4481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | return status; |
| 4483 | } |
| 4484 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4485 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4486 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4487 | struct nfs4_exception exception = { |
| 4488 | .interruptible = true, |
| 4489 | }; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4490 | struct inode *inode = d_inode(dentry); |
| 4491 | int err; |
| 4492 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4493 | if (inode) { |
| 4494 | if (inode->i_nlink == 1) |
| 4495 | nfs4_inode_return_delegation(inode); |
| 4496 | else |
| 4497 | nfs4_inode_make_writeable(inode); |
| 4498 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4499 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4500 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4501 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4502 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4503 | &exception); |
| 4504 | } while (exception.retry); |
| 4505 | return err; |
| 4506 | } |
| 4507 | |
| 4508 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4510 | struct nfs4_exception exception = { |
| 4511 | .interruptible = true, |
| 4512 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4516 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4517 | trace_nfs4_remove(dir, name, err); |
| 4518 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | &exception); |
| 4520 | } while (exception.retry); |
| 4521 | return err; |
| 4522 | } |
| 4523 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4524 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4525 | struct dentry *dentry, |
| 4526 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4528 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4529 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4531 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4533 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4534 | |
| 4535 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4536 | |
| 4537 | if (inode) |
| 4538 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4541 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4542 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4543 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4544 | &data->args.seq_args, |
| 4545 | &data->res.seq_res, |
| 4546 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | } |
| 4548 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4549 | 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] | 4550 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4551 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4552 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4553 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4554 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4555 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4556 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4557 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4558 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4559 | if (task->tk_status == 0) |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4560 | update_changeattr(dir, &res->cinfo, |
| 4561 | res->dir_attr->time_start, 0); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4562 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | } |
| 4564 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4565 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4566 | struct dentry *old_dentry, |
| 4567 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4568 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4569 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4570 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4571 | struct inode *old_inode = d_inode(old_dentry); |
| 4572 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4573 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4574 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4575 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4576 | if (new_inode) |
| 4577 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4578 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4579 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4580 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4581 | } |
| 4582 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4583 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4584 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4585 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4586 | &data->args.seq_args, |
| 4587 | &data->res.seq_res, |
| 4588 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4592 | struct inode *new_dir) |
| 4593 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4594 | struct nfs_renamedata *data = task->tk_calldata; |
| 4595 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4596 | |
| 4597 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4598 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4599 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4600 | return 0; |
| 4601 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4602 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4603 | if (new_dir != old_dir) { |
| 4604 | /* Note: If we moved a directory, nlink will change */ |
| 4605 | update_changeattr(old_dir, &res->old_cinfo, |
| 4606 | res->old_fattr->time_start, |
| 4607 | NFS_INO_INVALID_OTHER); |
| 4608 | update_changeattr(new_dir, &res->new_cinfo, |
| 4609 | res->new_fattr->time_start, |
| 4610 | NFS_INO_INVALID_OTHER); |
| 4611 | } else |
| 4612 | update_changeattr(old_dir, &res->old_cinfo, |
| 4613 | res->old_fattr->time_start, |
| 4614 | 0); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4615 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4616 | return 1; |
| 4617 | } |
| 4618 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4619 | 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] | 4620 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4621 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4622 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | struct nfs4_link_arg arg = { |
| 4624 | .fh = NFS_FH(inode), |
| 4625 | .dir_fh = NFS_FH(dir), |
| 4626 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4627 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4629 | struct nfs4_link_res res = { |
| 4630 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4631 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4632 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | struct rpc_message msg = { |
| 4634 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4635 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4636 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4638 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4640 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4641 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4642 | goto out; |
| 4643 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4644 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4645 | if (IS_ERR(res.label)) { |
| 4646 | status = PTR_ERR(res.label); |
| 4647 | goto out; |
| 4648 | } |
| 4649 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4650 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4651 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4652 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4653 | 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] | 4654 | if (!status) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4655 | update_changeattr(dir, &res.cinfo, res.fattr->time_start, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4656 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4657 | if (!status) |
| 4658 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4659 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4660 | |
| 4661 | |
| 4662 | nfs4_label_free(res.label); |
| 4663 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4664 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4665 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | return status; |
| 4667 | } |
| 4668 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4669 | 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] | 4670 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4671 | struct nfs4_exception exception = { |
| 4672 | .interruptible = true, |
| 4673 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | int err; |
| 4675 | do { |
| 4676 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4677 | _nfs4_proc_link(inode, dir, name), |
| 4678 | &exception); |
| 4679 | } while (exception.retry); |
| 4680 | return err; |
| 4681 | } |
| 4682 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4683 | struct nfs4_createdata { |
| 4684 | struct rpc_message msg; |
| 4685 | struct nfs4_create_arg arg; |
| 4686 | struct nfs4_create_res res; |
| 4687 | struct nfs_fh fh; |
| 4688 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4689 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4690 | }; |
| 4691 | |
| 4692 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4693 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4694 | { |
| 4695 | struct nfs4_createdata *data; |
| 4696 | |
| 4697 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4698 | if (data != NULL) { |
| 4699 | struct nfs_server *server = NFS_SERVER(dir); |
| 4700 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4701 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4702 | if (IS_ERR(data->label)) |
| 4703 | goto out_free; |
| 4704 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4705 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4706 | data->msg.rpc_argp = &data->arg; |
| 4707 | data->msg.rpc_resp = &data->res; |
| 4708 | data->arg.dir_fh = NFS_FH(dir); |
| 4709 | data->arg.server = server; |
| 4710 | data->arg.name = name; |
| 4711 | data->arg.attrs = sattr; |
| 4712 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4713 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4714 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4715 | data->res.server = server; |
| 4716 | data->res.fh = &data->fh; |
| 4717 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4718 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4719 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4720 | } |
| 4721 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4722 | out_free: |
| 4723 | kfree(data); |
| 4724 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4728 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4729 | 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] | 4730 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4731 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4732 | spin_lock(&dir->i_lock); |
| 4733 | update_changeattr_locked(dir, &data->res.dir_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4734 | data->res.fattr->time_start, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4735 | /* Creating a directory bumps nlink in the parent */ |
| 4736 | if (data->arg.ftype == NF4DIR) |
| 4737 | nfs4_inc_nlink_locked(dir); |
| 4738 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4739 | 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] | 4740 | } |
| 4741 | return status; |
| 4742 | } |
| 4743 | |
| 4744 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4745 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4746 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4747 | kfree(data); |
| 4748 | } |
| 4749 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4750 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4751 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4752 | 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 = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4757 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4758 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4759 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4760 | status = -ENOMEM; |
| 4761 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4762 | if (data == NULL) |
| 4763 | goto out; |
| 4764 | |
| 4765 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4766 | data->arg.u.symlink.pages = &page; |
| 4767 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4768 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4770 | status = nfs4_do_create(dir, dentry, data); |
| 4771 | |
| 4772 | nfs4_free_createdata(data); |
| 4773 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | return status; |
| 4775 | } |
| 4776 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4777 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4778 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4780 | struct nfs4_exception exception = { |
| 4781 | .interruptible = true, |
| 4782 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4783 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4785 | |
| 4786 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4788 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4789 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4790 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4791 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | &exception); |
| 4793 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4794 | |
| 4795 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | return err; |
| 4797 | } |
| 4798 | |
| 4799 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4800 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4802 | struct nfs4_createdata *data; |
| 4803 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4805 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4806 | if (data == NULL) |
| 4807 | goto out; |
| 4808 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4809 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4810 | status = nfs4_do_create(dir, dentry, data); |
| 4811 | |
| 4812 | nfs4_free_createdata(data); |
| 4813 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | return status; |
| 4815 | } |
| 4816 | |
| 4817 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4818 | struct iattr *sattr) |
| 4819 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4820 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4821 | struct nfs4_exception exception = { |
| 4822 | .interruptible = true, |
| 4823 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4824 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4826 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4827 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4828 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4829 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4830 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4832 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4833 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4834 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | &exception); |
| 4836 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4837 | nfs4_label_release_security(label); |
| 4838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | return err; |
| 4840 | } |
| 4841 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4842 | static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4843 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4845 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | struct nfs4_readdir_arg args = { |
| 4847 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4848 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | .pgbase = 0, |
| 4850 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4851 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4852 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | }; |
| 4854 | struct nfs4_readdir_res res; |
| 4855 | struct rpc_message msg = { |
| 4856 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4857 | .rpc_argp = &args, |
| 4858 | .rpc_resp = &res, |
| 4859 | .rpc_cred = cred, |
| 4860 | }; |
| 4861 | int status; |
| 4862 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4863 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4864 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4865 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4866 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4868 | 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] | 4869 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4870 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4871 | status += args.pgbase; |
| 4872 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4873 | |
| 4874 | nfs_invalidate_atime(dir); |
| 4875 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4876 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | return status; |
| 4878 | } |
| 4879 | |
NeilBrown | 684f39b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 4880 | static int nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4881 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4883 | struct nfs4_exception exception = { |
| 4884 | .interruptible = true, |
| 4885 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | int err; |
| 4887 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4888 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4889 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4890 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4891 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | &exception); |
| 4893 | } while (exception.retry); |
| 4894 | return err; |
| 4895 | } |
| 4896 | |
| 4897 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4898 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4900 | struct nfs4_createdata *data; |
| 4901 | int mode = sattr->ia_mode; |
| 4902 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4904 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4905 | if (data == NULL) |
| 4906 | goto out; |
| 4907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4909 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4911 | data->arg.ftype = NF4BLK; |
| 4912 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4913 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | } |
| 4915 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4916 | data->arg.ftype = NF4CHR; |
| 4917 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4918 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4919 | } else if (!S_ISSOCK(mode)) { |
| 4920 | status = -EINVAL; |
| 4921 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4923 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4924 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4925 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4926 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4927 | nfs4_free_createdata(data); |
| 4928 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | return status; |
| 4930 | } |
| 4931 | |
| 4932 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4933 | struct iattr *sattr, dev_t rdev) |
| 4934 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4935 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4936 | struct nfs4_exception exception = { |
| 4937 | .interruptible = true, |
| 4938 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4939 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4941 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4942 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4943 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4944 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4945 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4947 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4948 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4949 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | &exception); |
| 4951 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4952 | |
| 4953 | nfs4_label_release_security(label); |
| 4954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4955 | return err; |
| 4956 | } |
| 4957 | |
| 4958 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4959 | struct nfs_fsstat *fsstat) |
| 4960 | { |
| 4961 | struct nfs4_statfs_arg args = { |
| 4962 | .fh = fhandle, |
| 4963 | .bitmask = server->attr_bitmask, |
| 4964 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4965 | struct nfs4_statfs_res res = { |
| 4966 | .fsstat = fsstat, |
| 4967 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | struct rpc_message msg = { |
| 4969 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4970 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4971 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | }; |
| 4973 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4974 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4975 | 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] | 4976 | } |
| 4977 | |
| 4978 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4979 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 4980 | struct nfs4_exception exception = { |
| 4981 | .interruptible = true, |
| 4982 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | int err; |
| 4984 | do { |
| 4985 | err = nfs4_handle_exception(server, |
| 4986 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4987 | &exception); |
| 4988 | } while (exception.retry); |
| 4989 | return err; |
| 4990 | } |
| 4991 | |
| 4992 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4993 | struct nfs_fsinfo *fsinfo) |
| 4994 | { |
| 4995 | struct nfs4_fsinfo_arg args = { |
| 4996 | .fh = fhandle, |
| 4997 | .bitmask = server->attr_bitmask, |
| 4998 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4999 | struct nfs4_fsinfo_res res = { |
| 5000 | .fsinfo = fsinfo, |
| 5001 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | struct rpc_message msg = { |
| 5003 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 5004 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 5005 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | }; |
| 5007 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5008 | 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] | 5009 | } |
| 5010 | |
| 5011 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5012 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5013 | struct nfs4_exception exception = { |
| 5014 | .interruptible = true, |
| 5015 | }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5016 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | int err; |
| 5018 | |
| 5019 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5020 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 5021 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5022 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 5023 | nfs4_set_lease_period(server->nfs_client, |
| 5024 | fsinfo->lease_time * HZ, |
| 5025 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 5026 | break; |
| 5027 | } |
| 5028 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | } while (exception.retry); |
| 5030 | return err; |
| 5031 | } |
| 5032 | |
| 5033 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 5034 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5035 | int error; |
| 5036 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5037 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5038 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5039 | if (error == 0) { |
| 5040 | /* block layout checks this! */ |
| 5041 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 5042 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 5043 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 5044 | |
| 5045 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5049 | struct nfs_pathconf *pathconf) |
| 5050 | { |
| 5051 | struct nfs4_pathconf_arg args = { |
| 5052 | .fh = fhandle, |
| 5053 | .bitmask = server->attr_bitmask, |
| 5054 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5055 | struct nfs4_pathconf_res res = { |
| 5056 | .pathconf = pathconf, |
| 5057 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | struct rpc_message msg = { |
| 5059 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 5060 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 5061 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | }; |
| 5063 | |
| 5064 | /* None of the pathconf attributes are mandatory to implement */ |
| 5065 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 5066 | memset(pathconf, 0, sizeof(*pathconf)); |
| 5067 | return 0; |
| 5068 | } |
| 5069 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 5070 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5071 | 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] | 5072 | } |
| 5073 | |
| 5074 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5075 | struct nfs_pathconf *pathconf) |
| 5076 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5077 | struct nfs4_exception exception = { |
| 5078 | .interruptible = true, |
| 5079 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | int err; |
| 5081 | |
| 5082 | do { |
| 5083 | err = nfs4_handle_exception(server, |
| 5084 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 5085 | &exception); |
| 5086 | } while (exception.retry); |
| 5087 | return err; |
| 5088 | } |
| 5089 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5090 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5091 | const struct nfs_open_context *ctx, |
| 5092 | const struct nfs_lock_context *l_ctx, |
| 5093 | fmode_t fmode) |
| 5094 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 5095 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5096 | } |
| 5097 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 5098 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5099 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 5100 | const struct nfs_open_context *ctx, |
| 5101 | const struct nfs_lock_context *l_ctx, |
| 5102 | fmode_t fmode) |
| 5103 | { |
| 5104 | nfs4_stateid current_stateid; |
| 5105 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 5106 | /* If the current stateid represents a lost lock, then exit */ |
| 5107 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 5108 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5109 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 5110 | } |
| 5111 | |
| 5112 | static bool nfs4_error_stateid_expired(int err) |
| 5113 | { |
| 5114 | switch (err) { |
| 5115 | case -NFS4ERR_DELEG_REVOKED: |
| 5116 | case -NFS4ERR_ADMIN_REVOKED: |
| 5117 | case -NFS4ERR_BAD_STATEID: |
| 5118 | case -NFS4ERR_STALE_STATEID: |
| 5119 | case -NFS4ERR_OLD_STATEID: |
| 5120 | case -NFS4ERR_OPENMODE: |
| 5121 | case -NFS4ERR_EXPIRED: |
| 5122 | return true; |
| 5123 | } |
| 5124 | return false; |
| 5125 | } |
| 5126 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5127 | 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] | 5128 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5129 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5131 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5132 | if (task->tk_status < 0) { |
| 5133 | struct nfs4_exception exception = { |
| 5134 | .inode = hdr->inode, |
| 5135 | .state = hdr->args.context->state, |
| 5136 | .stateid = &hdr->args.stateid, |
| 5137 | }; |
| 5138 | task->tk_status = nfs4_async_handle_exception(task, |
| 5139 | server, task->tk_status, &exception); |
| 5140 | if (exception.retry) { |
| 5141 | rpc_restart_call_prepare(task); |
| 5142 | return -EAGAIN; |
| 5143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5144 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 5145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5147 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5148 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5151 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5152 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5153 | { |
| 5154 | |
| 5155 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5156 | nfs4_stateid_is_current(&args->stateid, |
| 5157 | args->context, |
| 5158 | args->lock_context, |
| 5159 | FMODE_READ)) |
| 5160 | return false; |
| 5161 | rpc_restart_call_prepare(task); |
| 5162 | return true; |
| 5163 | } |
| 5164 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5165 | 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] | 5166 | { |
| 5167 | |
| 5168 | dprintk("--> %s\n", __func__); |
| 5169 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5170 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5171 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5172 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5173 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 5174 | if (task->tk_status > 0) |
| 5175 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5176 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5177 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 5178 | } |
| 5179 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5180 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 5181 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5183 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 5184 | if (!hdr->pgio_done_cb) |
| 5185 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5186 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5187 | 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] | 5188 | } |
| 5189 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5190 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 5191 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5192 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5193 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5194 | &hdr->args.seq_args, |
| 5195 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5196 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5197 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5198 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5199 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5200 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5201 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5202 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5203 | return -EIO; |
| 5204 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | } |
| 5206 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5207 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5208 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5210 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5211 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5212 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5213 | if (task->tk_status < 0) { |
| 5214 | struct nfs4_exception exception = { |
| 5215 | .inode = hdr->inode, |
| 5216 | .state = hdr->args.context->state, |
| 5217 | .stateid = &hdr->args.stateid, |
| 5218 | }; |
| 5219 | task->tk_status = nfs4_async_handle_exception(task, |
| 5220 | NFS_SERVER(inode), task->tk_status, |
| 5221 | &exception); |
| 5222 | if (exception.retry) { |
| 5223 | rpc_restart_call_prepare(task); |
| 5224 | return -EAGAIN; |
| 5225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5227 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5228 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5229 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5230 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5231 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | } |
| 5233 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5234 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5235 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5236 | { |
| 5237 | |
| 5238 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5239 | nfs4_stateid_is_current(&args->stateid, |
| 5240 | args->context, |
| 5241 | args->lock_context, |
| 5242 | FMODE_WRITE)) |
| 5243 | return false; |
| 5244 | rpc_restart_call_prepare(task); |
| 5245 | return true; |
| 5246 | } |
| 5247 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5248 | 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] | 5249 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5250 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5251 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5252 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5253 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5254 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5255 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5256 | } |
| 5257 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5258 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5259 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5260 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5261 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5262 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5263 | return false; |
| 5264 | /* Otherwise, request attributes if and only if we don't hold |
| 5265 | * a delegation |
| 5266 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5267 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5268 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5269 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5270 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5271 | struct rpc_message *msg, |
| 5272 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5273 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5274 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5275 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5276 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5277 | hdr->args.bitmask = NULL; |
| 5278 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 5279 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5280 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5281 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5282 | if (!hdr->pgio_done_cb) |
| 5283 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5284 | hdr->res.server = server; |
| 5285 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5287 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5288 | 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] | 5289 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5292 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5293 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5294 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5295 | &data->args.seq_args, |
| 5296 | &data->res.seq_res, |
| 5297 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5300 | 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] | 5301 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5303 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5304 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5305 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5306 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5307 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5308 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5309 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5310 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5311 | } |
| 5312 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5313 | 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] | 5314 | { |
| 5315 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5316 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5317 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5318 | } |
| 5319 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5320 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5321 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5323 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5324 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5325 | if (data->commit_done_cb == NULL) |
| 5326 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5327 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5328 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5329 | 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] | 5330 | 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] | 5331 | } |
| 5332 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5333 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5334 | struct nfs_commitres *res) |
| 5335 | { |
| 5336 | struct inode *dst_inode = file_inode(dst); |
| 5337 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5338 | struct rpc_message msg = { |
| 5339 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5340 | .rpc_argp = args, |
| 5341 | .rpc_resp = res, |
| 5342 | }; |
| 5343 | |
| 5344 | args->fh = NFS_FH(dst_inode); |
| 5345 | return nfs4_call_sync(server->client, server, &msg, |
| 5346 | &args->seq_args, &res->seq_res, 1); |
| 5347 | } |
| 5348 | |
| 5349 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5350 | { |
| 5351 | struct nfs_commitargs args = { |
| 5352 | .offset = offset, |
| 5353 | .count = count, |
| 5354 | }; |
| 5355 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5356 | struct nfs4_exception exception = { }; |
| 5357 | int status; |
| 5358 | |
| 5359 | do { |
| 5360 | status = _nfs4_proc_commit(dst, &args, res); |
| 5361 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5362 | } while (exception.retry); |
| 5363 | |
| 5364 | return status; |
| 5365 | } |
| 5366 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5367 | struct nfs4_renewdata { |
| 5368 | struct nfs_client *client; |
| 5369 | unsigned long timestamp; |
| 5370 | }; |
| 5371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5372 | /* |
| 5373 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5374 | * standalone procedure for queueing an asynchronous RENEW. |
| 5375 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5376 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5377 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5378 | struct nfs4_renewdata *data = calldata; |
| 5379 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5380 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5381 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5382 | nfs4_schedule_state_renewal(clp); |
| 5383 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5384 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5385 | } |
| 5386 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5387 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5389 | struct nfs4_renewdata *data = calldata; |
| 5390 | struct nfs_client *clp = data->client; |
| 5391 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5392 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5393 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5394 | switch (task->tk_status) { |
| 5395 | case 0: |
| 5396 | break; |
| 5397 | case -NFS4ERR_LEASE_MOVED: |
| 5398 | nfs4_schedule_lease_moved_recovery(clp); |
| 5399 | break; |
| 5400 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5401 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5402 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5403 | return; |
| 5404 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5405 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5406 | return; |
| 5407 | } |
| 5408 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5409 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5410 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | } |
| 5412 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5413 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5414 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5415 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5416 | }; |
| 5417 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5418 | 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] | 5419 | { |
| 5420 | struct rpc_message msg = { |
| 5421 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5422 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5423 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5424 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5425 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5426 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5427 | if (renew_flags == 0) |
| 5428 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5429 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5430 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5431 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5432 | if (data == NULL) { |
| 5433 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5434 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5435 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5436 | data->client = clp; |
| 5437 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5438 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5439 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5440 | } |
| 5441 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 5442 | 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] | 5443 | { |
| 5444 | struct rpc_message msg = { |
| 5445 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5446 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5447 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | }; |
| 5449 | unsigned long now = jiffies; |
| 5450 | int status; |
| 5451 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5452 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5453 | if (status < 0) |
| 5454 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5455 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5456 | return 0; |
| 5457 | } |
| 5458 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5459 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5460 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5461 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5462 | } |
| 5463 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5464 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5465 | * 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] | 5466 | * the stack. |
| 5467 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5468 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5469 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5470 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5471 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5472 | { |
| 5473 | struct page *newpage, **spages; |
| 5474 | int rc = 0; |
| 5475 | size_t len; |
| 5476 | spages = pages; |
| 5477 | |
| 5478 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5479 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5480 | newpage = alloc_page(GFP_KERNEL); |
| 5481 | |
| 5482 | if (newpage == NULL) |
| 5483 | goto unwind; |
| 5484 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5485 | buf += len; |
| 5486 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5487 | *pages++ = newpage; |
| 5488 | rc++; |
| 5489 | } while (buflen != 0); |
| 5490 | |
| 5491 | return rc; |
| 5492 | |
| 5493 | unwind: |
| 5494 | for(; rc > 0; rc--) |
| 5495 | __free_page(spages[rc-1]); |
| 5496 | return -ENOMEM; |
| 5497 | } |
| 5498 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5499 | struct nfs4_cached_acl { |
| 5500 | int cached; |
| 5501 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5502 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5503 | }; |
| 5504 | |
| 5505 | 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] | 5506 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5507 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5508 | |
| 5509 | spin_lock(&inode->i_lock); |
| 5510 | kfree(nfsi->nfs4_acl); |
| 5511 | nfsi->nfs4_acl = acl; |
| 5512 | spin_unlock(&inode->i_lock); |
| 5513 | } |
| 5514 | |
| 5515 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5516 | { |
| 5517 | nfs4_set_cached_acl(inode, NULL); |
| 5518 | } |
| 5519 | |
| 5520 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5521 | { |
| 5522 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5523 | struct nfs4_cached_acl *acl; |
| 5524 | int ret = -ENOENT; |
| 5525 | |
| 5526 | spin_lock(&inode->i_lock); |
| 5527 | acl = nfsi->nfs4_acl; |
| 5528 | if (acl == NULL) |
| 5529 | goto out; |
| 5530 | if (buf == NULL) /* user is just asking for length */ |
| 5531 | goto out_len; |
| 5532 | if (acl->cached == 0) |
| 5533 | goto out; |
| 5534 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5535 | if (acl->len > buflen) |
| 5536 | goto out; |
| 5537 | memcpy(buf, acl->data, acl->len); |
| 5538 | out_len: |
| 5539 | ret = acl->len; |
| 5540 | out: |
| 5541 | spin_unlock(&inode->i_lock); |
| 5542 | return ret; |
| 5543 | } |
| 5544 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5545 | 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] | 5546 | { |
| 5547 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5548 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5549 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5550 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5551 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5552 | if (acl == NULL) |
| 5553 | goto out; |
| 5554 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5555 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5556 | } else { |
| 5557 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5558 | if (acl == NULL) |
| 5559 | goto out; |
| 5560 | acl->cached = 0; |
| 5561 | } |
| 5562 | acl->len = acl_len; |
| 5563 | out: |
| 5564 | nfs4_set_cached_acl(inode, acl); |
| 5565 | } |
| 5566 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5567 | /* |
| 5568 | * The getxattr API returns the required buffer length when called with a |
| 5569 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5570 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5571 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5572 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5573 | * the cache. If not so, we throw away the page, and cache the required |
| 5574 | * length. The next getxattr call will then produce another round trip to |
| 5575 | * the server, this time with the input buf of the required size. |
| 5576 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5577 | 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] | 5578 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5579 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5580 | struct nfs_getaclargs args = { |
| 5581 | .fh = NFS_FH(inode), |
| 5582 | .acl_pages = pages, |
| 5583 | .acl_len = buflen, |
| 5584 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5585 | struct nfs_getaclres res = { |
| 5586 | .acl_len = buflen, |
| 5587 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5588 | struct rpc_message msg = { |
| 5589 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5590 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5591 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5592 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5593 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5594 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5595 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5596 | if (npages > ARRAY_SIZE(pages)) |
| 5597 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5598 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5599 | for (i = 0; i < npages; i++) { |
| 5600 | pages[i] = alloc_page(GFP_KERNEL); |
| 5601 | if (!pages[i]) |
| 5602 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5603 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5604 | |
| 5605 | /* for decoding across pages */ |
| 5606 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5607 | if (!res.acl_scratch) |
| 5608 | goto out_free; |
| 5609 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5610 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5611 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5612 | 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] | 5613 | __func__, buf, buflen, npages, args.acl_len); |
| 5614 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5615 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5616 | if (ret) |
| 5617 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5618 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5619 | /* Handle the case where the passed-in buffer is too short */ |
| 5620 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5621 | /* Did the user only issue a request for the acl length? */ |
| 5622 | if (buf == NULL) |
| 5623 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5624 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5625 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5626 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5627 | 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] | 5628 | if (buf) { |
| 5629 | if (res.acl_len > buflen) { |
| 5630 | ret = -ERANGE; |
| 5631 | goto out_free; |
| 5632 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5633 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5634 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5635 | out_ok: |
| 5636 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5637 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5638 | for (i = 0; i < npages; i++) |
| 5639 | if (pages[i]) |
| 5640 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5641 | if (res.acl_scratch) |
| 5642 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5643 | return ret; |
| 5644 | } |
| 5645 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5646 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5647 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5648 | struct nfs4_exception exception = { |
| 5649 | .interruptible = true, |
| 5650 | }; |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5651 | ssize_t ret; |
| 5652 | do { |
| 5653 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5654 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5655 | if (ret >= 0) |
| 5656 | break; |
| 5657 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5658 | } while (exception.retry); |
| 5659 | return ret; |
| 5660 | } |
| 5661 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5662 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5663 | { |
| 5664 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5665 | int ret; |
| 5666 | |
| 5667 | if (!nfs4_server_supports_acls(server)) |
| 5668 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5669 | ret = nfs_revalidate_inode(server, inode); |
| 5670 | if (ret < 0) |
| 5671 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5672 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5673 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5674 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5675 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5676 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5677 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5678 | return ret; |
| 5679 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5682 | 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] | 5683 | { |
| 5684 | struct nfs_server *server = NFS_SERVER(inode); |
| 5685 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5686 | struct nfs_setaclargs arg = { |
| 5687 | .fh = NFS_FH(inode), |
| 5688 | .acl_pages = pages, |
| 5689 | .acl_len = buflen, |
| 5690 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5691 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5692 | struct rpc_message msg = { |
| 5693 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5694 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5695 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5696 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5697 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5698 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5699 | |
| 5700 | if (!nfs4_server_supports_acls(server)) |
| 5701 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5702 | if (npages > ARRAY_SIZE(pages)) |
| 5703 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5704 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5705 | if (i < 0) |
| 5706 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5707 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5708 | 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] | 5709 | |
| 5710 | /* |
| 5711 | * Free each page after tx, so the only ref left is |
| 5712 | * held by the network stack |
| 5713 | */ |
| 5714 | for (; i > 0; i--) |
| 5715 | put_page(pages[i-1]); |
| 5716 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5717 | /* |
| 5718 | * Acl update can result in inode attribute update. |
| 5719 | * so mark the attribute cache invalid. |
| 5720 | */ |
| 5721 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5722 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5723 | | NFS_INO_INVALID_CTIME |
| 5724 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5725 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5726 | nfs_access_zap_cache(inode); |
| 5727 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5728 | return ret; |
| 5729 | } |
| 5730 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5731 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5732 | { |
| 5733 | struct nfs4_exception exception = { }; |
| 5734 | int err; |
| 5735 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5736 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5737 | trace_nfs4_set_acl(inode, err); |
| 5738 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5739 | &exception); |
| 5740 | } while (exception.retry); |
| 5741 | return err; |
| 5742 | } |
| 5743 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5744 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5745 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5746 | size_t buflen) |
| 5747 | { |
| 5748 | struct nfs_server *server = NFS_SERVER(inode); |
| 5749 | struct nfs_fattr fattr; |
| 5750 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5751 | |
| 5752 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5753 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5754 | .fh = NFS_FH(inode), |
| 5755 | .bitmask = bitmask, |
| 5756 | }; |
| 5757 | struct nfs4_getattr_res res = { |
| 5758 | .fattr = &fattr, |
| 5759 | .label = &label, |
| 5760 | .server = server, |
| 5761 | }; |
| 5762 | struct rpc_message msg = { |
| 5763 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5764 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5765 | .rpc_resp = &res, |
| 5766 | }; |
| 5767 | int ret; |
| 5768 | |
| 5769 | nfs_fattr_init(&fattr); |
| 5770 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5771 | 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] | 5772 | if (ret) |
| 5773 | return ret; |
| 5774 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5775 | return -ENOENT; |
| 5776 | if (buflen < label.len) |
| 5777 | return -ERANGE; |
| 5778 | return 0; |
| 5779 | } |
| 5780 | |
| 5781 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5782 | size_t buflen) |
| 5783 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 5784 | struct nfs4_exception exception = { |
| 5785 | .interruptible = true, |
| 5786 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5787 | int err; |
| 5788 | |
| 5789 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5790 | return -EOPNOTSUPP; |
| 5791 | |
| 5792 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5793 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5794 | trace_nfs4_get_security_label(inode, err); |
| 5795 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5796 | &exception); |
| 5797 | } while (exception.retry); |
| 5798 | return err; |
| 5799 | } |
| 5800 | |
| 5801 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5802 | struct nfs4_label *ilabel, |
| 5803 | struct nfs_fattr *fattr, |
| 5804 | struct nfs4_label *olabel) |
| 5805 | { |
| 5806 | |
| 5807 | struct iattr sattr = {0}; |
| 5808 | struct nfs_server *server = NFS_SERVER(inode); |
| 5809 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5810 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5811 | .fh = NFS_FH(inode), |
| 5812 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5813 | .server = server, |
| 5814 | .bitmask = bitmask, |
| 5815 | .label = ilabel, |
| 5816 | }; |
| 5817 | struct nfs_setattrres res = { |
| 5818 | .fattr = fattr, |
| 5819 | .label = olabel, |
| 5820 | .server = server, |
| 5821 | }; |
| 5822 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5823 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5824 | .rpc_argp = &arg, |
| 5825 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5826 | }; |
| 5827 | int status; |
| 5828 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5829 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5830 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5831 | 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] | 5832 | if (status) |
| 5833 | dprintk("%s failed: %d\n", __func__, status); |
| 5834 | |
| 5835 | return status; |
| 5836 | } |
| 5837 | |
| 5838 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5839 | struct nfs4_label *ilabel, |
| 5840 | struct nfs_fattr *fattr, |
| 5841 | struct nfs4_label *olabel) |
| 5842 | { |
| 5843 | struct nfs4_exception exception = { }; |
| 5844 | int err; |
| 5845 | |
| 5846 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5847 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5848 | fattr, olabel); |
| 5849 | trace_nfs4_set_security_label(inode, err); |
| 5850 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5851 | &exception); |
| 5852 | } while (exception.retry); |
| 5853 | return err; |
| 5854 | } |
| 5855 | |
| 5856 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5857 | 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] | 5858 | { |
| 5859 | struct nfs4_label ilabel, *olabel = NULL; |
| 5860 | struct nfs_fattr fattr; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5861 | int status; |
| 5862 | |
| 5863 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5864 | return -EOPNOTSUPP; |
| 5865 | |
| 5866 | nfs_fattr_init(&fattr); |
| 5867 | |
| 5868 | ilabel.pi = 0; |
| 5869 | ilabel.lfs = 0; |
| 5870 | ilabel.label = (char *)buf; |
| 5871 | ilabel.len = buflen; |
| 5872 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5873 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5874 | if (IS_ERR(olabel)) { |
| 5875 | status = -PTR_ERR(olabel); |
| 5876 | goto out; |
| 5877 | } |
| 5878 | |
| 5879 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5880 | if (status == 0) |
| 5881 | nfs_setsecurity(inode, &fattr, olabel); |
| 5882 | |
| 5883 | nfs4_label_free(olabel); |
| 5884 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5885 | return status; |
| 5886 | } |
| 5887 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5888 | |
| 5889 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5890 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5891 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5892 | { |
| 5893 | __be32 verf[2]; |
| 5894 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5895 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5896 | /* An impossible timestamp guarantees this value |
| 5897 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5898 | verf[0] = cpu_to_be32(U32_MAX); |
| 5899 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5900 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5901 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5902 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5903 | |
| 5904 | verf[0] = cpu_to_be32(ns >> 32); |
| 5905 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5906 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5907 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5908 | } |
| 5909 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5910 | static int |
| 5911 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5912 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5913 | size_t len; |
| 5914 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5915 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5916 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5917 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5918 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5919 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5920 | len = 14 + |
| 5921 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 5922 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5923 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5924 | 1; |
| 5925 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5926 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 5927 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5928 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5929 | return -EINVAL; |
| 5930 | |
| 5931 | /* |
| 5932 | * Since this string is allocated at mount time, and held until the |
| 5933 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5934 | * about a memory-reclaim deadlock. |
| 5935 | */ |
| 5936 | str = kmalloc(len, GFP_KERNEL); |
| 5937 | if (!str) |
| 5938 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5939 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5940 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5941 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5942 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5943 | clp->cl_rpcclient->cl_nodename, |
| 5944 | nfs4_client_id_uniquifier, |
| 5945 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5946 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5947 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5948 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5949 | clp->cl_rpcclient->cl_nodename, |
| 5950 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5951 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5952 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5953 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5954 | clp->cl_owner_id = str; |
| 5955 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5956 | } |
| 5957 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5958 | static int |
| 5959 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5960 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5961 | size_t len; |
| 5962 | char *str; |
| 5963 | |
| 5964 | len = 10 + 10 + 1 + 10 + 1 + |
| 5965 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5966 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5967 | |
| 5968 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5969 | return -EINVAL; |
| 5970 | |
| 5971 | /* |
| 5972 | * Since this string is allocated at mount time, and held until the |
| 5973 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5974 | * about a memory-reclaim deadlock. |
| 5975 | */ |
| 5976 | str = kmalloc(len, GFP_KERNEL); |
| 5977 | if (!str) |
| 5978 | return -ENOMEM; |
| 5979 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5980 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5981 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5982 | nfs4_client_id_uniquifier, |
| 5983 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5984 | clp->cl_owner_id = str; |
| 5985 | return 0; |
| 5986 | } |
| 5987 | |
| 5988 | static int |
| 5989 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5990 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5991 | size_t len; |
| 5992 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5993 | |
| 5994 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5995 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5996 | |
| 5997 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5998 | return nfs4_init_uniquifier_client_string(clp); |
| 5999 | |
| 6000 | len = 10 + 10 + 1 + 10 + 1 + |
| 6001 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 6002 | |
| 6003 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 6004 | return -EINVAL; |
| 6005 | |
| 6006 | /* |
| 6007 | * Since this string is allocated at mount time, and held until the |
| 6008 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 6009 | * about a memory-reclaim deadlock. |
| 6010 | */ |
| 6011 | str = kmalloc(len, GFP_KERNEL); |
| 6012 | if (!str) |
| 6013 | return -ENOMEM; |
| 6014 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 6015 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6016 | clp->rpc_ops->version, clp->cl_minorversion, |
| 6017 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6018 | clp->cl_owner_id = str; |
| 6019 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6020 | } |
| 6021 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6022 | /* |
| 6023 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 6024 | * services. Advertise one based on the address family of the |
| 6025 | * clientaddr. |
| 6026 | */ |
| 6027 | static unsigned int |
| 6028 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 6029 | { |
| 6030 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 6031 | return scnprintf(buf, len, "tcp6"); |
| 6032 | else |
| 6033 | return scnprintf(buf, len, "tcp"); |
| 6034 | } |
| 6035 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6036 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 6037 | { |
| 6038 | struct nfs4_setclientid *sc = calldata; |
| 6039 | |
| 6040 | if (task->tk_status == 0) |
| 6041 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 6042 | } |
| 6043 | |
| 6044 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 6045 | .rpc_call_done = nfs4_setclientid_done, |
| 6046 | }; |
| 6047 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6048 | /** |
| 6049 | * nfs4_proc_setclientid - Negotiate client ID |
| 6050 | * @clp: state data structure |
| 6051 | * @program: RPC program for NFSv4 callback service |
| 6052 | * @port: IP port number for NFS4 callback service |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6053 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6054 | * @res: where to place the result |
| 6055 | * |
| 6056 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6057 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6058 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6059 | unsigned short port, const struct cred *cred, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6060 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6061 | { |
| 6062 | nfs4_verifier sc_verifier; |
| 6063 | struct nfs4_setclientid setclientid = { |
| 6064 | .sc_verifier = &sc_verifier, |
| 6065 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6066 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6067 | }; |
| 6068 | struct rpc_message msg = { |
| 6069 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 6070 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6071 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6072 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6073 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6074 | struct rpc_task_setup task_setup_data = { |
| 6075 | .rpc_client = clp->cl_rpcclient, |
| 6076 | .rpc_message = &msg, |
| 6077 | .callback_ops = &nfs4_setclientid_ops, |
| 6078 | .callback_data = &setclientid, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6079 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6080 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6081 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6082 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6083 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6084 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6085 | |
| 6086 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 6087 | status = nfs4_init_uniform_client_string(clp); |
| 6088 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 6089 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6090 | |
| 6091 | if (status) |
| 6092 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6093 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6094 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 6095 | setclientid.sc_netid_len = |
| 6096 | nfs4_init_callback_netid(clp, |
| 6097 | setclientid.sc_netid, |
| 6098 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 6099 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 6100 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6101 | clp->cl_ipaddr, port >> 8, port & 255); |
| 6102 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6103 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6104 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6105 | clp->cl_owner_id); |
Anna Schumaker | dae4096 | 2019-08-14 15:28:28 -0400 | [diff] [blame] | 6106 | |
| 6107 | status = nfs4_call_sync_custom(&task_setup_data); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6108 | if (setclientid.sc_cred) { |
| 6109 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 6110 | put_rpccred(setclientid.sc_cred); |
| 6111 | } |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 6112 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6113 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6114 | dprintk("NFS reply setclientid: %d\n", status); |
| 6115 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6116 | } |
| 6117 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6118 | /** |
| 6119 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 6120 | * @clp: state data structure |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 6121 | * @arg: result of a previous SETCLIENTID |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6122 | * @cred: credential to use for this call |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6123 | * |
| 6124 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6125 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 6126 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6127 | struct nfs4_setclientid_res *arg, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6128 | const struct cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6129 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | struct rpc_message msg = { |
| 6131 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 6132 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 6133 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6135 | int status; |
| 6136 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6137 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 6138 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6139 | clp->cl_clientid); |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 6140 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 6141 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6142 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6143 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | return status; |
| 6145 | } |
| 6146 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6147 | struct nfs4_delegreturndata { |
| 6148 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6149 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6150 | struct nfs_fh fh; |
| 6151 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6152 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6153 | struct { |
| 6154 | struct nfs4_layoutreturn_args arg; |
| 6155 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6156 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6157 | u32 roc_barrier; |
| 6158 | bool roc; |
| 6159 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6160 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6161 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6162 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6163 | }; |
| 6164 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6165 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 6166 | { |
| 6167 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6168 | struct nfs4_exception exception = { |
| 6169 | .inode = data->inode, |
| 6170 | .stateid = &data->stateid, |
| 6171 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6172 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6173 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6174 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6175 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 6176 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6177 | |
| 6178 | /* Handle Layoutreturn errors */ |
Trond Myklebust | 287a9c5 | 2019-09-20 07:23:41 -0400 | [diff] [blame] | 6179 | if (pnfs_roc_done(task, data->inode, |
| 6180 | &data->args.lr_args, |
| 6181 | &data->res.lr_res, |
| 6182 | &data->res.lr_ret) == -EAGAIN) |
| 6183 | goto out_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6184 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6185 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6186 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6187 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6188 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6189 | case -NFS4ERR_ADMIN_REVOKED: |
| 6190 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6191 | case -NFS4ERR_EXPIRED: |
| 6192 | nfs4_free_revoked_stateid(data->res.server, |
| 6193 | data->args.stateid, |
| 6194 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6195 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6196 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6197 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6198 | task->tk_status = 0; |
| 6199 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6200 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6201 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6202 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6203 | task->tk_status = 0; |
| 6204 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6205 | case -NFS4ERR_ACCESS: |
| 6206 | if (data->args.bitmask) { |
| 6207 | data->args.bitmask = NULL; |
| 6208 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6209 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6210 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6211 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6212 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6213 | task->tk_status = nfs4_async_handle_exception(task, |
| 6214 | data->res.server, task->tk_status, |
| 6215 | &exception); |
| 6216 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6217 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6218 | } |
| 6219 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6220 | return; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6221 | out_restart: |
| 6222 | task->tk_status = 0; |
| 6223 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | static void nfs4_delegreturn_release(void *calldata) |
| 6227 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6228 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6229 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6230 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6231 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6232 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6233 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6234 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6235 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6236 | nfs_iput_and_deactive(inode); |
| 6237 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6238 | kfree(calldata); |
| 6239 | } |
| 6240 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6241 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6242 | { |
| 6243 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6244 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6245 | |
| 6246 | d_data = (struct nfs4_delegreturndata *)data; |
| 6247 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6248 | 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] | 6249 | return; |
| 6250 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6251 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6252 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6253 | d_data->args.lr_args = NULL; |
| 6254 | d_data->res.lr_res = NULL; |
| 6255 | } |
| 6256 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6257 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6258 | &d_data->args.seq_args, |
| 6259 | &d_data->res.seq_res, |
| 6260 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6261 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6262 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6263 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6264 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6265 | .rpc_call_done = nfs4_delegreturn_done, |
| 6266 | .rpc_release = nfs4_delegreturn_release, |
| 6267 | }; |
| 6268 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6269 | 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] | 6270 | { |
| 6271 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6272 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6273 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6274 | struct rpc_message msg = { |
| 6275 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6276 | .rpc_cred = cred, |
| 6277 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6278 | struct rpc_task_setup task_setup_data = { |
| 6279 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6280 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6281 | .callback_ops = &nfs4_delegreturn_ops, |
| 6282 | .flags = RPC_TASK_ASYNC, |
| 6283 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6284 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6285 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6286 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6287 | if (data == NULL) |
| 6288 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6289 | 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] | 6290 | |
| 6291 | nfs4_state_protect(server->nfs_client, |
| 6292 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6293 | &task_setup_data.rpc_client, &msg); |
| 6294 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6295 | data->args.fhandle = &data->fh; |
| 6296 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6297 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6298 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6299 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6300 | data->res.fattr = &data->fattr; |
| 6301 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6302 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6303 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6304 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6305 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6306 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6307 | 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] | 6308 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6309 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6310 | if (data->lr.roc) { |
| 6311 | data->args.lr_args = &data->lr.arg; |
| 6312 | data->res.lr_res = &data->lr.res; |
| 6313 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6314 | } else if (data->lr.roc) { |
| 6315 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6316 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6317 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6318 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6319 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6320 | msg.rpc_argp = &data->args; |
| 6321 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6322 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6323 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6324 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6325 | if (!issync) |
| 6326 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6327 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6328 | if (status != 0) |
| 6329 | goto out; |
| 6330 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6331 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6332 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6333 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6334 | } |
| 6335 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 6336 | 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] | 6337 | { |
| 6338 | struct nfs_server *server = NFS_SERVER(inode); |
| 6339 | struct nfs4_exception exception = { }; |
| 6340 | int err; |
| 6341 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6342 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6343 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6344 | switch (err) { |
| 6345 | case -NFS4ERR_STALE_STATEID: |
| 6346 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | case 0: |
| 6348 | return 0; |
| 6349 | } |
| 6350 | err = nfs4_handle_exception(server, err, &exception); |
| 6351 | } while (exception.retry); |
| 6352 | return err; |
| 6353 | } |
| 6354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6355 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6356 | { |
| 6357 | struct inode *inode = state->inode; |
| 6358 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6359 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6360 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6361 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6362 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6363 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6364 | struct nfs_lockt_res res = { |
| 6365 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | }; |
| 6367 | struct rpc_message msg = { |
| 6368 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6369 | .rpc_argp = &arg, |
| 6370 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6371 | .rpc_cred = state->owner->so_cred, |
| 6372 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6373 | struct nfs4_lock_state *lsp; |
| 6374 | int status; |
| 6375 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6376 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6377 | status = nfs4_set_lock_state(state, request); |
| 6378 | if (status != 0) |
| 6379 | goto out; |
| 6380 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6381 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6382 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6383 | 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] | 6384 | switch (status) { |
| 6385 | case 0: |
| 6386 | request->fl_type = F_UNLCK; |
| 6387 | break; |
| 6388 | case -NFS4ERR_DENIED: |
| 6389 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6390 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6391 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6392 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6393 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6394 | return status; |
| 6395 | } |
| 6396 | |
| 6397 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6398 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 6399 | struct nfs4_exception exception = { |
| 6400 | .interruptible = true, |
| 6401 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6402 | int err; |
| 6403 | |
| 6404 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6405 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6406 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6407 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6408 | &exception); |
| 6409 | } while (exception.retry); |
| 6410 | return err; |
| 6411 | } |
| 6412 | |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6413 | /* |
| 6414 | * Update the seqid of a lock stateid after receiving |
| 6415 | * NFS4ERR_OLD_STATEID |
| 6416 | */ |
| 6417 | static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
| 6418 | struct nfs4_lock_state *lsp) |
| 6419 | { |
| 6420 | struct nfs4_state *state = lsp->ls_state; |
| 6421 | bool ret = false; |
| 6422 | |
| 6423 | spin_lock(&state->state_lock); |
| 6424 | if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
| 6425 | goto out; |
| 6426 | if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
| 6427 | nfs4_stateid_seqid_inc(dst); |
| 6428 | else |
| 6429 | dst->seqid = lsp->ls_stateid.seqid; |
| 6430 | ret = true; |
| 6431 | out: |
| 6432 | spin_unlock(&state->state_lock); |
| 6433 | return ret; |
| 6434 | } |
| 6435 | |
| 6436 | static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
| 6437 | struct nfs4_lock_state *lsp) |
| 6438 | { |
| 6439 | struct nfs4_state *state = lsp->ls_state; |
| 6440 | bool ret; |
| 6441 | |
| 6442 | spin_lock(&state->state_lock); |
| 6443 | ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
| 6444 | nfs4_stateid_copy(dst, &lsp->ls_stateid); |
| 6445 | spin_unlock(&state->state_lock); |
| 6446 | return ret; |
| 6447 | } |
| 6448 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6449 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6450 | struct nfs_locku_args arg; |
| 6451 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6452 | struct nfs4_lock_state *lsp; |
| 6453 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6454 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6455 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6456 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6457 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6458 | }; |
| 6459 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6460 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6461 | struct nfs_open_context *ctx, |
| 6462 | struct nfs4_lock_state *lsp, |
| 6463 | struct nfs_seqid *seqid) |
| 6464 | { |
| 6465 | struct nfs4_unlockdata *p; |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6466 | struct nfs4_state *state = lsp->ls_state; |
| 6467 | struct inode *inode = state->inode; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6468 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6469 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6470 | if (p == NULL) |
| 6471 | return NULL; |
| 6472 | p->arg.fh = NFS_FH(inode); |
| 6473 | p->arg.fl = &p->fl; |
| 6474 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6475 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6476 | p->lsp = lsp; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6477 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6478 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6479 | p->l_ctx = nfs_get_lock_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6480 | locks_init_lock(&p->fl); |
| 6481 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6482 | p->server = NFS_SERVER(inode); |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6483 | spin_lock(&state->state_lock); |
| 6484 | nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
| 6485 | spin_unlock(&state->state_lock); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6486 | return p; |
| 6487 | } |
| 6488 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6489 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6490 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6491 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6492 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6493 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6494 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6495 | put_nfs_open_context(calldata->ctx); |
| 6496 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6497 | } |
| 6498 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6499 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6500 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6501 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6502 | struct nfs4_exception exception = { |
| 6503 | .inode = calldata->lsp->ls_state->inode, |
| 6504 | .stateid = &calldata->arg.stateid, |
| 6505 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6506 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6507 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6508 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6509 | switch (task->tk_status) { |
| 6510 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6511 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6512 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6513 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6514 | &calldata->res.stateid)) |
| 6515 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6516 | /* Fall through */ |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6517 | case -NFS4ERR_ADMIN_REVOKED: |
| 6518 | case -NFS4ERR_EXPIRED: |
| 6519 | nfs4_free_revoked_stateid(calldata->server, |
| 6520 | &calldata->arg.stateid, |
| 6521 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6522 | /* Fall through */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6523 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6524 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 32c6e7e | 2019-09-20 07:23:48 -0400 | [diff] [blame] | 6525 | if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
| 6526 | calldata->lsp)) |
| 6527 | rpc_restart_call_prepare(task); |
| 6528 | break; |
| 6529 | case -NFS4ERR_OLD_STATEID: |
| 6530 | if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
| 6531 | calldata->lsp)) |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6532 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6533 | break; |
| 6534 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6535 | task->tk_status = nfs4_async_handle_exception(task, |
| 6536 | calldata->server, task->tk_status, |
| 6537 | &exception); |
| 6538 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6539 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6540 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6541 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6542 | } |
| 6543 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6544 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6545 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6546 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6547 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6548 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6549 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6550 | return; |
| 6551 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6552 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6553 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6554 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6555 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6556 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6557 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6558 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6559 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6560 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6561 | &calldata->res.seq_res, |
| 6562 | task) != 0) |
| 6563 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6564 | return; |
| 6565 | out_no_action: |
| 6566 | task->tk_action = NULL; |
| 6567 | out_wait: |
| 6568 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6569 | } |
| 6570 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6571 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6572 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6573 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6574 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6575 | }; |
| 6576 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6577 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6578 | struct nfs_open_context *ctx, |
| 6579 | struct nfs4_lock_state *lsp, |
| 6580 | struct nfs_seqid *seqid) |
| 6581 | { |
| 6582 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6583 | struct rpc_message msg = { |
| 6584 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6585 | .rpc_cred = ctx->cred, |
| 6586 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6587 | struct rpc_task_setup task_setup_data = { |
| 6588 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6589 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6590 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6591 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6592 | .flags = RPC_TASK_ASYNC, |
| 6593 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6594 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6595 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6596 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6597 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6598 | /* Ensure this is an unlock - when canceling a lock, the |
| 6599 | * canceled lock is passed in, and it won't be an unlock. |
| 6600 | */ |
| 6601 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6602 | if (fl->fl_flags & FL_CLOSE) |
| 6603 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6604 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6605 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6606 | if (data == NULL) { |
| 6607 | nfs_free_seqid(seqid); |
| 6608 | return ERR_PTR(-ENOMEM); |
| 6609 | } |
| 6610 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6611 | 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] | 6612 | msg.rpc_argp = &data->arg; |
| 6613 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6614 | task_setup_data.callback_data = data; |
| 6615 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6616 | } |
| 6617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6618 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6619 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6620 | struct inode *inode = state->inode; |
| 6621 | struct nfs4_state_owner *sp = state->owner; |
| 6622 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6623 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6624 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6625 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6626 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6627 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6628 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6629 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6630 | status = nfs4_set_lock_state(state, request); |
| 6631 | /* Unlock _before_ we do the RPC call */ |
| 6632 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6633 | /* Exclude nfs_delegation_claim_locks() */ |
| 6634 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6635 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6636 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6637 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6638 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6639 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6640 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6641 | } |
| 6642 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6643 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6644 | if (status != 0) |
| 6645 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6646 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6647 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6648 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6649 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6650 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6651 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6652 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6653 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6654 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6655 | 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] | 6656 | status = PTR_ERR(task); |
| 6657 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6658 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6659 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6660 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6661 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6662 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6663 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6664 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6665 | } |
| 6666 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6667 | struct nfs4_lockdata { |
| 6668 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6669 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6670 | struct nfs4_lock_state *lsp; |
| 6671 | struct nfs_open_context *ctx; |
| 6672 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6673 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6674 | int rpc_status; |
| 6675 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6676 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6677 | }; |
| 6678 | |
| 6679 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6680 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6681 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6682 | { |
| 6683 | struct nfs4_lockdata *p; |
| 6684 | struct inode *inode = lsp->ls_state->inode; |
| 6685 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6686 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6687 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6688 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6689 | if (p == NULL) |
| 6690 | return NULL; |
| 6691 | |
| 6692 | p->arg.fh = NFS_FH(inode); |
| 6693 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6694 | 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] | 6695 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6696 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6697 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6698 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6699 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6700 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6701 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6702 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6703 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6704 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6705 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6706 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6707 | p->ctx = get_nfs_open_context(ctx); |
NeilBrown | 7b587e1 | 2018-11-30 10:04:08 +1100 | [diff] [blame] | 6708 | locks_init_lock(&p->fl); |
| 6709 | locks_copy_lock(&p->fl, fl); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6710 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6711 | out_free_seqid: |
| 6712 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6713 | out_free: |
| 6714 | kfree(p); |
| 6715 | return NULL; |
| 6716 | } |
| 6717 | |
| 6718 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6719 | { |
| 6720 | struct nfs4_lockdata *data = calldata; |
| 6721 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6722 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6723 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6724 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6725 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6726 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6727 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6728 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6729 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6730 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6731 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6732 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6733 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6734 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6735 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6736 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6737 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6738 | &data->lsp->ls_stateid); |
| 6739 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6740 | if (!nfs4_valid_open_stateid(state)) { |
| 6741 | data->rpc_status = -EBADF; |
| 6742 | task->tk_action = NULL; |
| 6743 | goto out_release_open_seqid; |
| 6744 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6745 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6746 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6747 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6748 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6749 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6750 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6751 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6752 | nfs_release_seqid(data->arg.open_seqid); |
| 6753 | out_release_lock_seqid: |
| 6754 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6755 | out_wait: |
| 6756 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6757 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6758 | } |
| 6759 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6760 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6761 | { |
| 6762 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6763 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6764 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6765 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6766 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6767 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6768 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6769 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6770 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6771 | switch (task->tk_status) { |
| 6772 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6773 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6774 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6775 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6776 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6777 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6778 | goto out_restart; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6779 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6780 | if (data->arg.new_lock_owner != 0) { |
| 6781 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6782 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6783 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6784 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6785 | goto out_restart; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6786 | break; |
| 6787 | case -NFS4ERR_BAD_STATEID: |
| 6788 | case -NFS4ERR_OLD_STATEID: |
| 6789 | case -NFS4ERR_STALE_STATEID: |
| 6790 | case -NFS4ERR_EXPIRED: |
| 6791 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6792 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6793 | &lsp->ls_state->open_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6794 | goto out_restart; |
| 6795 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6796 | &lsp->ls_stateid)) |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6797 | goto out_restart; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6798 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6799 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6800 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6801 | return; |
| 6802 | out_restart: |
| 6803 | if (!data->cancelled) |
| 6804 | rpc_restart_call_prepare(task); |
| 6805 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6806 | } |
| 6807 | |
| 6808 | static void nfs4_lock_release(void *calldata) |
| 6809 | { |
| 6810 | struct nfs4_lockdata *data = calldata; |
| 6811 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6812 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6813 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | 6ea76bf | 2018-07-29 22:21:22 -0400 | [diff] [blame] | 6814 | if (data->cancelled && data->rpc_status == 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6815 | struct rpc_task *task; |
| 6816 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6817 | data->arg.lock_seqid); |
| 6818 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6819 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6820 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6821 | } else |
| 6822 | nfs_free_seqid(data->arg.lock_seqid); |
| 6823 | nfs4_put_lock_state(data->lsp); |
| 6824 | put_nfs_open_context(data->ctx); |
| 6825 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6826 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6827 | } |
| 6828 | |
| 6829 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6830 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6831 | .rpc_call_done = nfs4_lock_done, |
| 6832 | .rpc_release = nfs4_lock_release, |
| 6833 | }; |
| 6834 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6835 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6836 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6837 | switch (error) { |
| 6838 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6839 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6840 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6841 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6842 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6843 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6844 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6845 | break; |
| 6846 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6847 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6848 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6849 | }; |
| 6850 | } |
| 6851 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6852 | 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] | 6853 | { |
| 6854 | struct nfs4_lockdata *data; |
| 6855 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6856 | struct rpc_message msg = { |
| 6857 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6858 | .rpc_cred = state->owner->so_cred, |
| 6859 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6860 | struct rpc_task_setup task_setup_data = { |
| 6861 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6862 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6863 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6864 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6865 | .flags = RPC_TASK_ASYNC, |
| 6866 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6867 | int ret; |
| 6868 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6869 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6870 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6871 | fl->fl_u.nfs4_fl.owner, |
| 6872 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6873 | if (data == NULL) |
| 6874 | return -ENOMEM; |
| 6875 | if (IS_SETLKW(cmd)) |
| 6876 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6877 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 6878 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6879 | msg.rpc_argp = &data->arg; |
| 6880 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6881 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6882 | if (recovery_type > NFS_LOCK_NEW) { |
| 6883 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6884 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6885 | } else |
| 6886 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6887 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6888 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6889 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6890 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6891 | if (ret == 0) { |
| 6892 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6893 | if (ret) |
| 6894 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6895 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6896 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6897 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6898 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6899 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6900 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6901 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6902 | } |
| 6903 | |
| 6904 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6905 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6906 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6907 | struct nfs4_exception exception = { |
| 6908 | .inode = state->inode, |
| 6909 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6910 | int err; |
| 6911 | |
| 6912 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6913 | /* Cache the lock if possible... */ |
| 6914 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6915 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6916 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6917 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6918 | break; |
| 6919 | nfs4_handle_exception(server, err, &exception); |
| 6920 | } while (exception.retry); |
| 6921 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6922 | } |
| 6923 | |
| 6924 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6925 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6926 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6927 | struct nfs4_exception exception = { |
| 6928 | .inode = state->inode, |
| 6929 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6930 | int err; |
| 6931 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6932 | err = nfs4_set_lock_state(state, request); |
| 6933 | if (err != 0) |
| 6934 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6935 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6936 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6937 | return 0; |
| 6938 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6939 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6940 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6941 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6942 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6943 | switch (err) { |
| 6944 | default: |
| 6945 | goto out; |
| 6946 | case -NFS4ERR_GRACE: |
| 6947 | case -NFS4ERR_DELAY: |
| 6948 | nfs4_handle_exception(server, err, &exception); |
| 6949 | err = 0; |
| 6950 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6951 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6952 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6953 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6954 | } |
| 6955 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6956 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6957 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6958 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6959 | struct nfs4_lock_state *lsp; |
| 6960 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6961 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6962 | status = nfs4_set_lock_state(state, request); |
| 6963 | if (status != 0) |
| 6964 | return status; |
| 6965 | lsp = request->fl_u.nfs4_fl.owner; |
| 6966 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6967 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6968 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6969 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6970 | } |
| 6971 | #endif |
| 6972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6973 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6974 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6975 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6976 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6977 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6978 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6979 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6980 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6981 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6982 | if (status < 0) |
| 6983 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6984 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6985 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6986 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6987 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6988 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6989 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6990 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6991 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6992 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6993 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6994 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6995 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6996 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6997 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6998 | out: |
| 6999 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7000 | return status; |
| 7001 | } |
| 7002 | |
| 7003 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7004 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7005 | struct nfs4_exception exception = { |
| 7006 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 7007 | .inode = state->inode, |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7008 | .interruptible = true, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 7009 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7010 | int err; |
| 7011 | |
| 7012 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7013 | err = _nfs4_proc_setlk(state, cmd, request); |
| 7014 | if (err == -NFS4ERR_DENIED) |
| 7015 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7016 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 7017 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7018 | } while (exception.retry); |
| 7019 | return err; |
| 7020 | } |
| 7021 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7022 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 7023 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 7024 | |
| 7025 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7026 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 7027 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7028 | { |
| 7029 | int status = -ERESTARTSYS; |
| 7030 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 7031 | |
| 7032 | while(!signalled()) { |
| 7033 | status = nfs4_proc_setlk(state, cmd, request); |
| 7034 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 7035 | break; |
| 7036 | freezable_schedule_timeout_interruptible(timeout); |
| 7037 | timeout *= 2; |
| 7038 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 7039 | status = -ERESTARTSYS; |
| 7040 | } |
| 7041 | return status; |
| 7042 | } |
| 7043 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7044 | #ifdef CONFIG_NFS_V4_1 |
| 7045 | struct nfs4_lock_waiter { |
| 7046 | struct task_struct *task; |
| 7047 | struct inode *inode; |
| 7048 | struct nfs_lowner *owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7049 | }; |
| 7050 | |
| 7051 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7052 | 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] | 7053 | { |
| 7054 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7055 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7056 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7057 | /* NULL key means to wake up everyone */ |
| 7058 | if (key) { |
| 7059 | struct cb_notify_lock_args *cbnl = key; |
| 7060 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 7061 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7062 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7063 | /* Only wake if the callback was for the same owner. */ |
| 7064 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 7065 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7066 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7067 | /* Make sure it's for the right inode */ |
| 7068 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 7069 | return 0; |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 7070 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7071 | |
| 7072 | /* override "private" so we can use default_wake_function */ |
| 7073 | wait->private = waiter->task; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7074 | ret = woken_wake_function(wait, mode, flags, key); |
| 7075 | if (ret) |
| 7076 | list_del_init(&wait->entry); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7077 | wait->private = waiter; |
| 7078 | return ret; |
| 7079 | } |
| 7080 | |
| 7081 | static int |
| 7082 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7083 | { |
| 7084 | int status = -ERESTARTSYS; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7085 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 7086 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 7087 | struct nfs_client *clp = server->nfs_client; |
| 7088 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 7089 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 7090 | .id = lsp->ls_seqid.owner_id, |
| 7091 | .s_dev = server->s_dev }; |
| 7092 | struct nfs4_lock_waiter waiter = { .task = current, |
| 7093 | .inode = state->inode, |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7094 | .owner = &owner}; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 7095 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7096 | |
| 7097 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 7098 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 7099 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7100 | |
| 7101 | init_wait(&wait); |
| 7102 | wait.private = &waiter; |
| 7103 | wait.func = nfs4_wake_lock_waiter; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7104 | |
| 7105 | while(!signalled()) { |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7106 | add_wait_queue(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7107 | status = nfs4_proc_setlk(state, cmd, request); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7108 | if ((status != -EAGAIN) || IS_SETLK(cmd)) { |
| 7109 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7110 | break; |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7111 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7112 | |
| 7113 | status = -ERESTARTSYS; |
Yihao Wu | 52b042a | 2019-05-22 01:57:10 +0800 | [diff] [blame] | 7114 | freezer_do_not_count(); |
| 7115 | wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT); |
| 7116 | freezer_count(); |
Yihao Wu | ba851a3 | 2019-05-13 14:58:22 +0800 | [diff] [blame] | 7117 | finish_wait(q, &wait); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7118 | } |
| 7119 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 7120 | return status; |
| 7121 | } |
| 7122 | #else /* !CONFIG_NFS_V4_1 */ |
| 7123 | static inline int |
| 7124 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 7125 | { |
| 7126 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 7127 | } |
| 7128 | #endif |
| 7129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7130 | static int |
| 7131 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 7132 | { |
| 7133 | struct nfs_open_context *ctx; |
| 7134 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7135 | int status; |
| 7136 | |
| 7137 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 7138 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7139 | state = ctx->state; |
| 7140 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7141 | if (IS_GETLK(cmd)) { |
| 7142 | if (state != NULL) |
| 7143 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 7144 | return 0; |
| 7145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7146 | |
| 7147 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 7148 | return -EINVAL; |
| 7149 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7150 | if (request->fl_type == F_UNLCK) { |
| 7151 | if (state != NULL) |
| 7152 | return nfs4_proc_unlck(state, cmd, request); |
| 7153 | return 0; |
| 7154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7155 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 7156 | if (state == NULL) |
| 7157 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7158 | |
| 7159 | if ((request->fl_flags & FL_POSIX) && |
| 7160 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 7161 | return -ENOLCK; |
| 7162 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 7163 | /* |
| 7164 | * Don't rely on the VFS having checked the file open mode, |
| 7165 | * since it won't do this for flock() locks. |
| 7166 | */ |
| 7167 | switch (request->fl_type) { |
| 7168 | case F_RDLCK: |
| 7169 | if (!(filp->f_mode & FMODE_READ)) |
| 7170 | return -EBADF; |
| 7171 | break; |
| 7172 | case F_WRLCK: |
| 7173 | if (!(filp->f_mode & FMODE_WRITE)) |
| 7174 | return -EBADF; |
| 7175 | } |
| 7176 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 7177 | status = nfs4_set_lock_state(state, request); |
| 7178 | if (status != 0) |
| 7179 | return status; |
| 7180 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 7181 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7182 | } |
| 7183 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7184 | 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] | 7185 | { |
| 7186 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7187 | int err; |
| 7188 | |
| 7189 | err = nfs4_set_lock_state(state, fl); |
| 7190 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 7191 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 7192 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 7193 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 7194 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7195 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7196 | struct nfs_release_lockowner_data { |
| 7197 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7198 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7199 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7200 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7201 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7202 | }; |
| 7203 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7204 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7205 | { |
| 7206 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7207 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7208 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7209 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7210 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7211 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7212 | } |
| 7213 | |
| 7214 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7215 | { |
| 7216 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7217 | struct nfs_server *server = data->server; |
| 7218 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7219 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7220 | |
| 7221 | switch (task->tk_status) { |
| 7222 | case 0: |
| 7223 | renew_lease(server, data->timestamp); |
| 7224 | break; |
| 7225 | case -NFS4ERR_STALE_CLIENTID: |
| 7226 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7227 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7228 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7229 | case -NFS4ERR_LEASE_MOVED: |
| 7230 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7231 | if (nfs4_async_handle_error(task, server, |
| 7232 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7233 | rpc_restart_call_prepare(task); |
| 7234 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7235 | } |
| 7236 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7237 | static void nfs4_release_lockowner_release(void *calldata) |
| 7238 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7239 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7240 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7241 | kfree(calldata); |
| 7242 | } |
| 7243 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7244 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7245 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7246 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7247 | .rpc_release = nfs4_release_lockowner_release, |
| 7248 | }; |
| 7249 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7250 | static void |
| 7251 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7252 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7253 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7254 | struct rpc_message msg = { |
| 7255 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7256 | }; |
| 7257 | |
| 7258 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7259 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7260 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7261 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7262 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7263 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7264 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7265 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7266 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7267 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7268 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7269 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7270 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7271 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7272 | 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] | 7273 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7274 | } |
| 7275 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7276 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7277 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7278 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7279 | struct dentry *unused, struct inode *inode, |
| 7280 | const char *key, const void *buf, |
| 7281 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7282 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7283 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7284 | } |
| 7285 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7286 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7287 | struct dentry *unused, struct inode *inode, |
| 7288 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7289 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7290 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7291 | } |
| 7292 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7293 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7294 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7295 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7296 | } |
| 7297 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7298 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7299 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7300 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7301 | struct dentry *unused, struct inode *inode, |
| 7302 | const char *key, const void *buf, |
| 7303 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7304 | { |
| 7305 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7306 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7307 | |
| 7308 | return -EOPNOTSUPP; |
| 7309 | } |
| 7310 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7311 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7312 | struct dentry *unused, struct inode *inode, |
| 7313 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7314 | { |
| 7315 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7316 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7317 | return -EOPNOTSUPP; |
| 7318 | } |
| 7319 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7320 | static ssize_t |
| 7321 | 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] | 7322 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7323 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7324 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7325 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7326 | len = security_inode_listsecurity(inode, list, list_len); |
| 7327 | if (list_len && len > list_len) |
| 7328 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7329 | } |
| 7330 | return len; |
| 7331 | } |
| 7332 | |
| 7333 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7334 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7335 | .get = nfs4_xattr_get_nfs4_label, |
| 7336 | .set = nfs4_xattr_set_nfs4_label, |
| 7337 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7338 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7339 | #else |
| 7340 | |
| 7341 | static ssize_t |
| 7342 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7343 | { |
| 7344 | return 0; |
| 7345 | } |
| 7346 | |
| 7347 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7348 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7349 | /* |
| 7350 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7351 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7352 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7353 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7354 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7355 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7356 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7357 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7358 | return; |
| 7359 | |
| 7360 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7361 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7362 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7363 | fattr->nlink = 2; |
| 7364 | } |
| 7365 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7366 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7367 | const struct qstr *name, |
| 7368 | struct nfs4_fs_locations *fs_locations, |
| 7369 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7370 | { |
| 7371 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7372 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7373 | struct nfs4_fs_locations_arg args = { |
| 7374 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7375 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7376 | .page = page, |
| 7377 | .bitmask = bitmask, |
| 7378 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7379 | struct nfs4_fs_locations_res res = { |
| 7380 | .fs_locations = fs_locations, |
| 7381 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7382 | struct rpc_message msg = { |
| 7383 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7384 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7385 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7386 | }; |
| 7387 | int status; |
| 7388 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7389 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7390 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7391 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7392 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7393 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7394 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7395 | * is not supported */ |
| 7396 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7397 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7398 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7399 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7400 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7401 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7402 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7403 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7404 | 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] | 7405 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7406 | return status; |
| 7407 | } |
| 7408 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7409 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7410 | const struct qstr *name, |
| 7411 | struct nfs4_fs_locations *fs_locations, |
| 7412 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7413 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7414 | struct nfs4_exception exception = { |
| 7415 | .interruptible = true, |
| 7416 | }; |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7417 | int err; |
| 7418 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7419 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7420 | fs_locations, page); |
| 7421 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7422 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7423 | &exception); |
| 7424 | } while (exception.retry); |
| 7425 | return err; |
| 7426 | } |
| 7427 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7428 | /* |
| 7429 | * This operation also signals the server that this client is |
| 7430 | * performing migration recovery. The server can stop returning |
| 7431 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7432 | * appended to this compound to identify the client ID which is |
| 7433 | * performing recovery. |
| 7434 | */ |
| 7435 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7436 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7437 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7438 | { |
| 7439 | struct nfs_server *server = NFS_SERVER(inode); |
| 7440 | struct rpc_clnt *clnt = server->client; |
| 7441 | u32 bitmask[2] = { |
| 7442 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7443 | }; |
| 7444 | struct nfs4_fs_locations_arg args = { |
| 7445 | .clientid = server->nfs_client->cl_clientid, |
| 7446 | .fh = NFS_FH(inode), |
| 7447 | .page = page, |
| 7448 | .bitmask = bitmask, |
| 7449 | .migration = 1, /* skip LOOKUP */ |
| 7450 | .renew = 1, /* append RENEW */ |
| 7451 | }; |
| 7452 | struct nfs4_fs_locations_res res = { |
| 7453 | .fs_locations = locations, |
| 7454 | .migration = 1, |
| 7455 | .renew = 1, |
| 7456 | }; |
| 7457 | struct rpc_message msg = { |
| 7458 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7459 | .rpc_argp = &args, |
| 7460 | .rpc_resp = &res, |
| 7461 | .rpc_cred = cred, |
| 7462 | }; |
| 7463 | unsigned long now = jiffies; |
| 7464 | int status; |
| 7465 | |
| 7466 | nfs_fattr_init(&locations->fattr); |
| 7467 | locations->server = server; |
| 7468 | locations->nlocations = 0; |
| 7469 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7470 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7471 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7472 | &args.seq_args, &res.seq_res); |
| 7473 | if (status) |
| 7474 | return status; |
| 7475 | |
| 7476 | renew_lease(server, now); |
| 7477 | return 0; |
| 7478 | } |
| 7479 | |
| 7480 | #ifdef CONFIG_NFS_V4_1 |
| 7481 | |
| 7482 | /* |
| 7483 | * This operation also signals the server that this client is |
| 7484 | * performing migration recovery. The server can stop asserting |
| 7485 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7486 | * performing this operation is identified in the SEQUENCE |
| 7487 | * operation in this compound. |
| 7488 | * |
| 7489 | * When the client supports GETATTR(fs_locations_info), it can |
| 7490 | * be plumbed in here. |
| 7491 | */ |
| 7492 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7493 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7494 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7495 | { |
| 7496 | struct nfs_server *server = NFS_SERVER(inode); |
| 7497 | struct rpc_clnt *clnt = server->client; |
| 7498 | u32 bitmask[2] = { |
| 7499 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7500 | }; |
| 7501 | struct nfs4_fs_locations_arg args = { |
| 7502 | .fh = NFS_FH(inode), |
| 7503 | .page = page, |
| 7504 | .bitmask = bitmask, |
| 7505 | .migration = 1, /* skip LOOKUP */ |
| 7506 | }; |
| 7507 | struct nfs4_fs_locations_res res = { |
| 7508 | .fs_locations = locations, |
| 7509 | .migration = 1, |
| 7510 | }; |
| 7511 | struct rpc_message msg = { |
| 7512 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7513 | .rpc_argp = &args, |
| 7514 | .rpc_resp = &res, |
| 7515 | .rpc_cred = cred, |
| 7516 | }; |
| 7517 | int status; |
| 7518 | |
| 7519 | nfs_fattr_init(&locations->fattr); |
| 7520 | locations->server = server; |
| 7521 | locations->nlocations = 0; |
| 7522 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7523 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7524 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7525 | &args.seq_args, &res.seq_res); |
| 7526 | if (status == NFS4_OK && |
| 7527 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7528 | status = -NFS4ERR_LEASE_MOVED; |
| 7529 | return status; |
| 7530 | } |
| 7531 | |
| 7532 | #endif /* CONFIG_NFS_V4_1 */ |
| 7533 | |
| 7534 | /** |
| 7535 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7536 | * @inode: inode on FSID that is migrating |
| 7537 | * @locations: result of query |
| 7538 | * @page: buffer |
| 7539 | * @cred: credential to use for this operation |
| 7540 | * |
| 7541 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7542 | * operation failed, or a negative errno if a local error occurred. |
| 7543 | * |
| 7544 | * On success, "locations" is filled in, but if the server has |
| 7545 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7546 | * asserted. |
| 7547 | * |
| 7548 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7549 | * from this client that require migration recovery. |
| 7550 | */ |
| 7551 | int nfs4_proc_get_locations(struct inode *inode, |
| 7552 | struct nfs4_fs_locations *locations, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7553 | struct page *page, const struct cred *cred) |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7554 | { |
| 7555 | struct nfs_server *server = NFS_SERVER(inode); |
| 7556 | struct nfs_client *clp = server->nfs_client; |
| 7557 | const struct nfs4_mig_recovery_ops *ops = |
| 7558 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7559 | struct nfs4_exception exception = { |
| 7560 | .interruptible = true, |
| 7561 | }; |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7562 | int status; |
| 7563 | |
| 7564 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7565 | (unsigned long long)server->fsid.major, |
| 7566 | (unsigned long long)server->fsid.minor, |
| 7567 | clp->cl_hostname); |
| 7568 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7569 | |
| 7570 | do { |
| 7571 | status = ops->get_locations(inode, locations, page, cred); |
| 7572 | if (status != -NFS4ERR_DELAY) |
| 7573 | break; |
| 7574 | nfs4_handle_exception(server, status, &exception); |
| 7575 | } while (exception.retry); |
| 7576 | return status; |
| 7577 | } |
| 7578 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7579 | /* |
| 7580 | * This operation also signals the server that this client is |
| 7581 | * performing "lease moved" recovery. The server can stop |
| 7582 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7583 | * is appended to this compound to identify the client ID which is |
| 7584 | * performing recovery. |
| 7585 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7586 | 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] | 7587 | { |
| 7588 | struct nfs_server *server = NFS_SERVER(inode); |
| 7589 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7590 | struct rpc_clnt *clnt = server->client; |
| 7591 | struct nfs4_fsid_present_arg args = { |
| 7592 | .fh = NFS_FH(inode), |
| 7593 | .clientid = clp->cl_clientid, |
| 7594 | .renew = 1, /* append RENEW */ |
| 7595 | }; |
| 7596 | struct nfs4_fsid_present_res res = { |
| 7597 | .renew = 1, |
| 7598 | }; |
| 7599 | struct rpc_message msg = { |
| 7600 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7601 | .rpc_argp = &args, |
| 7602 | .rpc_resp = &res, |
| 7603 | .rpc_cred = cred, |
| 7604 | }; |
| 7605 | unsigned long now = jiffies; |
| 7606 | int status; |
| 7607 | |
| 7608 | res.fh = nfs_alloc_fhandle(); |
| 7609 | if (res.fh == NULL) |
| 7610 | return -ENOMEM; |
| 7611 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7612 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7613 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7614 | &args.seq_args, &res.seq_res); |
| 7615 | nfs_free_fhandle(res.fh); |
| 7616 | if (status) |
| 7617 | return status; |
| 7618 | |
| 7619 | do_renew_lease(clp, now); |
| 7620 | return 0; |
| 7621 | } |
| 7622 | |
| 7623 | #ifdef CONFIG_NFS_V4_1 |
| 7624 | |
| 7625 | /* |
| 7626 | * This operation also signals the server that this client is |
| 7627 | * performing "lease moved" recovery. The server can stop asserting |
| 7628 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7629 | * this operation is identified in the SEQUENCE operation in this |
| 7630 | * compound. |
| 7631 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7632 | 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] | 7633 | { |
| 7634 | struct nfs_server *server = NFS_SERVER(inode); |
| 7635 | struct rpc_clnt *clnt = server->client; |
| 7636 | struct nfs4_fsid_present_arg args = { |
| 7637 | .fh = NFS_FH(inode), |
| 7638 | }; |
| 7639 | struct nfs4_fsid_present_res res = { |
| 7640 | }; |
| 7641 | struct rpc_message msg = { |
| 7642 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7643 | .rpc_argp = &args, |
| 7644 | .rpc_resp = &res, |
| 7645 | .rpc_cred = cred, |
| 7646 | }; |
| 7647 | int status; |
| 7648 | |
| 7649 | res.fh = nfs_alloc_fhandle(); |
| 7650 | if (res.fh == NULL) |
| 7651 | return -ENOMEM; |
| 7652 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7653 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7654 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7655 | &args.seq_args, &res.seq_res); |
| 7656 | nfs_free_fhandle(res.fh); |
| 7657 | if (status == NFS4_OK && |
| 7658 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7659 | status = -NFS4ERR_LEASE_MOVED; |
| 7660 | return status; |
| 7661 | } |
| 7662 | |
| 7663 | #endif /* CONFIG_NFS_V4_1 */ |
| 7664 | |
| 7665 | /** |
| 7666 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7667 | * @inode: inode on FSID to check |
| 7668 | * @cred: credential to use for this operation |
| 7669 | * |
| 7670 | * Server indicates whether the FSID is present, moved, or not |
| 7671 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7672 | * condition for this client ID. |
| 7673 | * |
| 7674 | * Returns NFS4_OK if the FSID is present on this server, |
| 7675 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7676 | * NFS4ERR code if some error occurred on the server, or a |
| 7677 | * negative errno if a local failure occurred. |
| 7678 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7679 | int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7680 | { |
| 7681 | struct nfs_server *server = NFS_SERVER(inode); |
| 7682 | struct nfs_client *clp = server->nfs_client; |
| 7683 | const struct nfs4_mig_recovery_ops *ops = |
| 7684 | clp->cl_mvops->mig_recovery_ops; |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7685 | struct nfs4_exception exception = { |
| 7686 | .interruptible = true, |
| 7687 | }; |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7688 | int status; |
| 7689 | |
| 7690 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7691 | (unsigned long long)server->fsid.major, |
| 7692 | (unsigned long long)server->fsid.minor, |
| 7693 | clp->cl_hostname); |
| 7694 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7695 | |
| 7696 | do { |
| 7697 | status = ops->fsid_present(inode, cred); |
| 7698 | if (status != -NFS4ERR_DELAY) |
| 7699 | break; |
| 7700 | nfs4_handle_exception(server, status, &exception); |
| 7701 | } while (exception.retry); |
| 7702 | return status; |
| 7703 | } |
| 7704 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 7705 | /* |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7706 | * If 'use_integrity' is true and the state managment nfs_client |
| 7707 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7708 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7709 | * Considerations sections. Otherwise, just use the user cred with the |
| 7710 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7711 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7712 | 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] | 7713 | { |
| 7714 | int status; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7715 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 7716 | struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7717 | struct nfs4_secinfo_arg args = { |
| 7718 | .dir_fh = NFS_FH(dir), |
| 7719 | .name = name, |
| 7720 | }; |
| 7721 | struct nfs4_secinfo_res res = { |
| 7722 | .flavors = flavors, |
| 7723 | }; |
| 7724 | struct rpc_message msg = { |
| 7725 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7726 | .rpc_argp = &args, |
| 7727 | .rpc_resp = &res, |
| 7728 | }; |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7729 | struct nfs4_call_sync_data data = { |
| 7730 | .seq_server = NFS_SERVER(dir), |
| 7731 | .seq_args = &args.seq_args, |
| 7732 | .seq_res = &res.seq_res, |
| 7733 | }; |
| 7734 | struct rpc_task_setup task_setup = { |
| 7735 | .rpc_client = clnt, |
| 7736 | .rpc_message = &msg, |
| 7737 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 7738 | .callback_data = &data, |
| 7739 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 7740 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7741 | const struct cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7742 | |
| 7743 | if (use_integrity) { |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7744 | clnt = clp->cl_rpcclient; |
| 7745 | task_setup.rpc_client = clnt; |
| 7746 | |
| 7747 | cred = nfs4_get_clid_cred(clp); |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7748 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7749 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7750 | |
| 7751 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7752 | |
Anna Schumaker | 5049336 | 2019-08-14 15:30:16 -0400 | [diff] [blame] | 7753 | nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7754 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 7755 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7756 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7757 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7758 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7759 | put_cred(cred); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7760 | return status; |
| 7761 | } |
| 7762 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7763 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7764 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7765 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 7766 | struct nfs4_exception exception = { |
| 7767 | .interruptible = true, |
| 7768 | }; |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7769 | int err; |
| 7770 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7771 | err = -NFS4ERR_WRONGSEC; |
| 7772 | |
| 7773 | /* try to use integrity protection with machine cred */ |
| 7774 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7775 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7776 | |
| 7777 | /* |
| 7778 | * if unable to use integrity protection, or SECINFO with |
| 7779 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7780 | * disallowed by spec, but exists in deployed servers) use |
| 7781 | * the current filesystem's rpc_client and the user cred. |
| 7782 | */ |
| 7783 | if (err == -NFS4ERR_WRONGSEC) |
| 7784 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7785 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7786 | trace_nfs4_secinfo(dir, name, err); |
| 7787 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7788 | &exception); |
| 7789 | } while (exception.retry); |
| 7790 | return err; |
| 7791 | } |
| 7792 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7793 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7794 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7795 | * Check the exchange flags returned by the server for invalid flags, having |
| 7796 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7797 | * DS flags set. |
| 7798 | */ |
| 7799 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7800 | { |
| 7801 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7802 | goto out_inval; |
| 7803 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7804 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7805 | goto out_inval; |
| 7806 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7807 | goto out_inval; |
| 7808 | return NFS_OK; |
| 7809 | out_inval: |
| 7810 | return -NFS4ERR_INVAL; |
| 7811 | } |
| 7812 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7813 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7814 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7815 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7816 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7817 | if (a->server_scope_sz != b->server_scope_sz) |
| 7818 | return false; |
| 7819 | 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] | 7820 | } |
| 7821 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7822 | static void |
| 7823 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7824 | { |
| 7825 | } |
| 7826 | |
| 7827 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7828 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7829 | }; |
| 7830 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7831 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7832 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7833 | * |
| 7834 | * The 4.1 client currently uses the same TCP connection for the |
| 7835 | * fore and backchannel. |
| 7836 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7837 | static |
| 7838 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7839 | struct rpc_xprt *xprt, |
| 7840 | struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7841 | const struct cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7842 | { |
| 7843 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7844 | struct nfs41_bind_conn_to_session_args args = { |
| 7845 | .client = clp, |
| 7846 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7847 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7848 | struct nfs41_bind_conn_to_session_res res; |
| 7849 | struct rpc_message msg = { |
| 7850 | .rpc_proc = |
| 7851 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7852 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7853 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7854 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7855 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7856 | struct rpc_task_setup task_setup_data = { |
| 7857 | .rpc_client = clnt, |
| 7858 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7859 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7860 | .rpc_message = &msg, |
| 7861 | .flags = RPC_TASK_TIMEOUT, |
| 7862 | }; |
| 7863 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7864 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7865 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7866 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7867 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7868 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7869 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7870 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7871 | args.dir = NFS4_CDFC4_FORE; |
| 7872 | |
| 7873 | task = rpc_run_task(&task_setup_data); |
| 7874 | if (!IS_ERR(task)) { |
| 7875 | status = task->tk_status; |
| 7876 | rpc_put_task(task); |
| 7877 | } else |
| 7878 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7879 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7880 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7881 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7882 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7883 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7884 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7885 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7886 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7887 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7888 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7889 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7890 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7891 | 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] | 7892 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7893 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7894 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7895 | } |
| 7896 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7897 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7898 | return status; |
| 7899 | } |
| 7900 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7901 | struct rpc_bind_conn_calldata { |
| 7902 | struct nfs_client *clp; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7903 | const struct cred *cred; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7904 | }; |
| 7905 | |
| 7906 | static int |
| 7907 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7908 | struct rpc_xprt *xprt, |
| 7909 | void *calldata) |
| 7910 | { |
| 7911 | struct rpc_bind_conn_calldata *p = calldata; |
| 7912 | |
| 7913 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7914 | } |
| 7915 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 7916 | 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] | 7917 | { |
| 7918 | struct rpc_bind_conn_calldata data = { |
| 7919 | .clp = clp, |
| 7920 | .cred = cred, |
| 7921 | }; |
| 7922 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7923 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7924 | } |
| 7925 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7926 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7927 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7928 | * 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] | 7929 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7930 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7931 | .how = SP4_MACH_CRED, |
| 7932 | .enforce.u.words = { |
| 7933 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7934 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7935 | 1 << (OP_CREATE_SESSION - 32) | |
| 7936 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7937 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7938 | }, |
| 7939 | .allow.u.words = { |
| 7940 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7941 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7942 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7943 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7944 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7945 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7946 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7947 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7948 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7949 | 1 << (OP_FREE_STATEID - 32) | |
| 7950 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7951 | } |
| 7952 | }; |
| 7953 | |
| 7954 | /* |
| 7955 | * Select the state protection mode for client `clp' given the server results |
| 7956 | * from exchange_id in `sp'. |
| 7957 | * |
| 7958 | * Returns 0 on success, negative errno otherwise. |
| 7959 | */ |
| 7960 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7961 | struct nfs41_state_protection *sp) |
| 7962 | { |
| 7963 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7964 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7965 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7966 | 1 << (OP_CREATE_SESSION - 32) | |
| 7967 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7968 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7969 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7970 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7971 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7972 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7973 | |
| 7974 | if (sp->how == SP4_MACH_CRED) { |
| 7975 | /* Print state protect result */ |
| 7976 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7977 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7978 | if (test_bit(i, sp->enforce.u.longs)) |
| 7979 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7980 | if (test_bit(i, sp->allow.u.longs)) |
| 7981 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7982 | } |
| 7983 | |
| 7984 | /* make sure nothing is on enforce list that isn't supported */ |
| 7985 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7986 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7987 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7988 | ret = -EINVAL; |
| 7989 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7990 | } |
| 7991 | } |
| 7992 | |
| 7993 | /* |
| 7994 | * Minimal mode - state operations are allowed to use machine |
| 7995 | * credential. Note this already happens by default, so the |
| 7996 | * client doesn't have to do anything more than the negotiation. |
| 7997 | * |
| 7998 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7999 | * we're already using the machine cred for exchange_id |
| 8000 | * and will never use a different cred. |
| 8001 | */ |
| 8002 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 8003 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 8004 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 8005 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 8006 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 8007 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8008 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8009 | } else { |
| 8010 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8011 | ret = -EINVAL; |
| 8012 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8013 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8014 | |
| 8015 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8016 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 8017 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8018 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 8019 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8020 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 8021 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8022 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8023 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 8024 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8025 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8026 | } |
| 8027 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8028 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 8029 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 8030 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8031 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 8032 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8033 | |
| 8034 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 8035 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 8036 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8037 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8038 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8039 | |
| 8040 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 8041 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8042 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8043 | } |
| 8044 | |
| 8045 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 8046 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8047 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 8048 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8049 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 8050 | out: |
| 8051 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 8052 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8053 | } |
| 8054 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8055 | struct nfs41_exchange_id_data { |
| 8056 | struct nfs41_exchange_id_res res; |
| 8057 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8058 | }; |
| 8059 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8060 | static void nfs4_exchange_id_release(void *data) |
| 8061 | { |
| 8062 | struct nfs41_exchange_id_data *cdata = |
| 8063 | (struct nfs41_exchange_id_data *)data; |
| 8064 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8065 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8066 | kfree(cdata->res.impl_id); |
| 8067 | kfree(cdata->res.server_scope); |
| 8068 | kfree(cdata->res.server_owner); |
| 8069 | kfree(cdata); |
| 8070 | } |
| 8071 | |
| 8072 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8073 | .rpc_release = nfs4_exchange_id_release, |
| 8074 | }; |
| 8075 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8076 | /* |
| 8077 | * _nfs4_proc_exchange_id() |
| 8078 | * |
| 8079 | * Wrapper for EXCHANGE_ID operation. |
| 8080 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8081 | static struct rpc_task * |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8082 | nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8083 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8084 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8085 | struct rpc_message msg = { |
| 8086 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8087 | .rpc_cred = cred, |
| 8088 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8089 | struct rpc_task_setup task_setup_data = { |
| 8090 | .rpc_client = clp->cl_rpcclient, |
| 8091 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 8092 | .rpc_message = &msg, |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8093 | .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8094 | }; |
| 8095 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 8096 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8097 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8098 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8099 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8100 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8101 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8102 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8103 | if (!calldata) |
| 8104 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8105 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8106 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 8107 | |
| 8108 | status = nfs4_init_uniform_client_string(clp); |
| 8109 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8110 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 8111 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8112 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 8113 | GFP_NOFS); |
| 8114 | status = -ENOMEM; |
| 8115 | if (unlikely(calldata->res.server_owner == NULL)) |
| 8116 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8117 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8118 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 8119 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8120 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 8121 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8122 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8123 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 8124 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8125 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 8126 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8127 | switch (sp4_how) { |
| 8128 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8129 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8130 | break; |
| 8131 | |
| 8132 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8133 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8134 | break; |
| 8135 | |
| 8136 | default: |
| 8137 | /* unsupported! */ |
| 8138 | WARN_ON_ONCE(1); |
| 8139 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 8140 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8141 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8142 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8143 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 8144 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 8145 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 8146 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 8147 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8148 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8149 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 8150 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8151 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 8152 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8153 | #endif |
| 8154 | msg.rpc_argp = &calldata->args; |
| 8155 | msg.rpc_resp = &calldata->res; |
| 8156 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 8157 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8158 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 8159 | |
| 8160 | out_impl_id: |
| 8161 | kfree(calldata->res.impl_id); |
| 8162 | out_server_scope: |
| 8163 | kfree(calldata->res.server_scope); |
| 8164 | out_server_owner: |
| 8165 | kfree(calldata->res.server_owner); |
| 8166 | out_calldata: |
| 8167 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8168 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 8169 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8170 | return ERR_PTR(status); |
| 8171 | } |
| 8172 | |
| 8173 | /* |
| 8174 | * _nfs4_proc_exchange_id() |
| 8175 | * |
| 8176 | * Wrapper for EXCHANGE_ID operation. |
| 8177 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8178 | 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] | 8179 | u32 sp4_how) |
| 8180 | { |
| 8181 | struct rpc_task *task; |
| 8182 | struct nfs41_exchange_id_args *argp; |
| 8183 | struct nfs41_exchange_id_res *resp; |
| 8184 | int status; |
| 8185 | |
| 8186 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 8187 | if (IS_ERR(task)) |
| 8188 | return PTR_ERR(task); |
| 8189 | |
| 8190 | argp = task->tk_msg.rpc_argp; |
| 8191 | resp = task->tk_msg.rpc_resp; |
| 8192 | status = task->tk_status; |
| 8193 | if (status != 0) |
| 8194 | goto out; |
| 8195 | |
| 8196 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 8197 | if (status != 0) |
| 8198 | goto out; |
| 8199 | |
| 8200 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 8201 | if (status != 0) |
| 8202 | goto out; |
| 8203 | |
| 8204 | clp->cl_clientid = resp->clientid; |
| 8205 | clp->cl_exchange_flags = resp->flags; |
| 8206 | clp->cl_seqid = resp->seqid; |
| 8207 | /* Client ID is not confirmed */ |
| 8208 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 8209 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 8210 | &clp->cl_session->session_state); |
| 8211 | |
| 8212 | if (clp->cl_serverscope != NULL && |
| 8213 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 8214 | resp->server_scope)) { |
| 8215 | dprintk("%s: server_scope mismatch detected\n", |
| 8216 | __func__); |
| 8217 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 8218 | } |
| 8219 | |
| 8220 | swap(clp->cl_serverowner, resp->server_owner); |
| 8221 | swap(clp->cl_serverscope, resp->server_scope); |
| 8222 | swap(clp->cl_implid, resp->impl_id); |
| 8223 | |
| 8224 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8225 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8226 | sizeof(clp->cl_confirm.data)); |
| 8227 | out: |
| 8228 | trace_nfs4_exchange_id(clp, status); |
| 8229 | rpc_put_task(task); |
| 8230 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8231 | } |
| 8232 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8233 | /* |
| 8234 | * nfs4_proc_exchange_id() |
| 8235 | * |
| 8236 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8237 | * |
| 8238 | * Since the clientid has expired, all compounds using sessions |
| 8239 | * associated with the stale clientid will be returning |
| 8240 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8241 | * be in some phase of session reset. |
| 8242 | * |
| 8243 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8244 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8245 | 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] | 8246 | { |
| 8247 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8248 | int status; |
| 8249 | |
| 8250 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8251 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8252 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8253 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8254 | if (!status) |
| 8255 | return 0; |
| 8256 | } |
| 8257 | |
| 8258 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8259 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8260 | } |
| 8261 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8262 | /** |
| 8263 | * nfs4_test_session_trunk |
| 8264 | * |
| 8265 | * This is an add_xprt_test() test function called from |
| 8266 | * rpc_clnt_setup_test_and_add_xprt. |
| 8267 | * |
| 8268 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8269 | * and is dereferrenced in nfs4_exchange_id_release |
| 8270 | * |
| 8271 | * Upon success, add the new transport to the rpc_clnt |
| 8272 | * |
| 8273 | * @clnt: struct rpc_clnt to get new transport |
| 8274 | * @xprt: the rpc_xprt to test |
| 8275 | * @data: call data for _nfs4_proc_exchange_id. |
| 8276 | */ |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8277 | 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] | 8278 | void *data) |
| 8279 | { |
| 8280 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8281 | struct rpc_task *task; |
| 8282 | int status; |
| 8283 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8284 | u32 sp4_how; |
| 8285 | |
| 8286 | dprintk("--> %s try %s\n", __func__, |
| 8287 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8288 | |
| 8289 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8290 | |
| 8291 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8292 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8293 | if (IS_ERR(task)) |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8294 | return; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8295 | |
| 8296 | status = task->tk_status; |
| 8297 | if (status == 0) |
| 8298 | status = nfs4_detect_session_trunking(adata->clp, |
| 8299 | task->tk_msg.rpc_resp, xprt); |
| 8300 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 8301 | if (status == 0) |
| 8302 | rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
| 8303 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8304 | rpc_put_task(task); |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8305 | } |
| 8306 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8307 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8308 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8309 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8310 | { |
| 8311 | struct rpc_message msg = { |
| 8312 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8313 | .rpc_argp = clp, |
| 8314 | .rpc_cred = cred, |
| 8315 | }; |
| 8316 | int status; |
| 8317 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8318 | status = rpc_call_sync(clp->cl_rpcclient, &msg, |
| 8319 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8320 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8321 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8322 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8323 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8324 | return status; |
| 8325 | } |
| 8326 | |
| 8327 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8328 | const struct cred *cred) |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8329 | { |
| 8330 | unsigned int loop; |
| 8331 | int ret; |
| 8332 | |
| 8333 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8334 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8335 | switch (ret) { |
| 8336 | case -NFS4ERR_DELAY: |
| 8337 | case -NFS4ERR_CLIENTID_BUSY: |
| 8338 | ssleep(1); |
| 8339 | break; |
| 8340 | default: |
| 8341 | return ret; |
| 8342 | } |
| 8343 | } |
| 8344 | return 0; |
| 8345 | } |
| 8346 | |
| 8347 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8348 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8349 | const struct cred *cred; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8350 | int ret = 0; |
| 8351 | |
| 8352 | if (clp->cl_mvops->minor_version < 1) |
| 8353 | goto out; |
| 8354 | if (clp->cl_exchange_flags == 0) |
| 8355 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8356 | if (clp->cl_preserve_clid) |
| 8357 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8358 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8359 | ret = nfs4_proc_destroy_clientid(clp, cred); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8360 | put_cred(cred); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8361 | switch (ret) { |
| 8362 | case 0: |
| 8363 | case -NFS4ERR_STALE_CLIENTID: |
| 8364 | clp->cl_exchange_flags = 0; |
| 8365 | } |
| 8366 | out: |
| 8367 | return ret; |
| 8368 | } |
| 8369 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8370 | #endif /* CONFIG_NFS_V4_1 */ |
| 8371 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8372 | struct nfs4_get_lease_time_data { |
| 8373 | struct nfs4_get_lease_time_args *args; |
| 8374 | struct nfs4_get_lease_time_res *res; |
| 8375 | struct nfs_client *clp; |
| 8376 | }; |
| 8377 | |
| 8378 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8379 | void *calldata) |
| 8380 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8381 | struct nfs4_get_lease_time_data *data = |
| 8382 | (struct nfs4_get_lease_time_data *)calldata; |
| 8383 | |
| 8384 | dprintk("--> %s\n", __func__); |
| 8385 | /* just setup sequence, do not trigger session recovery |
| 8386 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8387 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8388 | &data->args->la_seq_args, |
| 8389 | &data->res->lr_seq_res, |
| 8390 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8391 | dprintk("<-- %s\n", __func__); |
| 8392 | } |
| 8393 | |
| 8394 | /* |
| 8395 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8396 | * from sequence operation or clientid errors. |
| 8397 | */ |
| 8398 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8399 | { |
| 8400 | struct nfs4_get_lease_time_data *data = |
| 8401 | (struct nfs4_get_lease_time_data *)calldata; |
| 8402 | |
| 8403 | dprintk("--> %s\n", __func__); |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8404 | if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8405 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8406 | switch (task->tk_status) { |
| 8407 | case -NFS4ERR_DELAY: |
| 8408 | case -NFS4ERR_GRACE: |
| 8409 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8410 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8411 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8412 | /* fall through */ |
| 8413 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8414 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8415 | return; |
| 8416 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8417 | dprintk("<-- %s\n", __func__); |
| 8418 | } |
| 8419 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8420 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8421 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8422 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8423 | }; |
| 8424 | |
| 8425 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8426 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8427 | struct nfs4_get_lease_time_args args; |
| 8428 | struct nfs4_get_lease_time_res res = { |
| 8429 | .lr_fsinfo = fsinfo, |
| 8430 | }; |
| 8431 | struct nfs4_get_lease_time_data data = { |
| 8432 | .args = &args, |
| 8433 | .res = &res, |
| 8434 | .clp = clp, |
| 8435 | }; |
| 8436 | struct rpc_message msg = { |
| 8437 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8438 | .rpc_argp = &args, |
| 8439 | .rpc_resp = &res, |
| 8440 | }; |
| 8441 | struct rpc_task_setup task_setup = { |
| 8442 | .rpc_client = clp->cl_rpcclient, |
| 8443 | .rpc_message = &msg, |
| 8444 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8445 | .callback_data = &data, |
| 8446 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8447 | }; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8448 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8449 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0, 1); |
Anna Schumaker | f836b27 | 2019-08-19 10:18:28 -0400 | [diff] [blame] | 8450 | return nfs4_call_sync_custom(&task_setup); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8451 | } |
| 8452 | |
Donald Buczek | 0efb01b | 2019-07-07 21:26:08 +0200 | [diff] [blame] | 8453 | #ifdef CONFIG_NFS_V4_1 |
| 8454 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8455 | /* |
| 8456 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8457 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8458 | * use them. |
| 8459 | * |
| 8460 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8461 | * always set csa_cachethis to FALSE because the current implementation |
| 8462 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8463 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8464 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8465 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8466 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8467 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8468 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Trond Myklebust | 7402a4f | 2019-07-16 13:51:29 -0400 | [diff] [blame] | 8469 | unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8470 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8471 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8472 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8473 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8474 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8475 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8476 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8477 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8478 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8479 | |
| 8480 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8481 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8482 | __func__, |
| 8483 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8484 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8485 | |
| 8486 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8487 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8488 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8489 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8490 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8491 | 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] | 8492 | if (args->bc_attrs.max_reqs > max_bc_slots) |
| 8493 | args->bc_attrs.max_reqs = max_bc_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8494 | |
| 8495 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8496 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8497 | __func__, |
| 8498 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8499 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8500 | args->bc_attrs.max_reqs); |
| 8501 | } |
| 8502 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8503 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8504 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8505 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8506 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8507 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8508 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8509 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8510 | return -EINVAL; |
| 8511 | /* |
| 8512 | * Our requested max_ops is the minimum we need; we're not |
| 8513 | * prepared to break up compounds into smaller pieces than that. |
| 8514 | * So, no point even trying to continue if the server won't |
| 8515 | * cooperate: |
| 8516 | */ |
| 8517 | if (rcvd->max_ops < sent->max_ops) |
| 8518 | return -EINVAL; |
| 8519 | if (rcvd->max_reqs == 0) |
| 8520 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8521 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8522 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8523 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8524 | } |
| 8525 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8526 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8527 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8528 | { |
| 8529 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8530 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8531 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8532 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8533 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8534 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8535 | return -EINVAL; |
| 8536 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8537 | return -EINVAL; |
| 8538 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8539 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8540 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8541 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8542 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8543 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8544 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8545 | return 0; |
| 8546 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8547 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8548 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8549 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8550 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8551 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8552 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8553 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8554 | if (ret) |
| 8555 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8556 | return nfs4_verify_back_channel_attrs(args, res); |
| 8557 | } |
| 8558 | |
| 8559 | static void nfs4_update_session(struct nfs4_session *session, |
| 8560 | struct nfs41_create_session_res *res) |
| 8561 | { |
| 8562 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8563 | /* Mark client id and session as being confirmed */ |
| 8564 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8565 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8566 | session->flags = res->flags; |
| 8567 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8568 | if (res->flags & SESSION4_BACK_CHAN) |
| 8569 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8570 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8571 | } |
| 8572 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8573 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8574 | const struct cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8575 | { |
| 8576 | struct nfs4_session *session = clp->cl_session; |
| 8577 | struct nfs41_create_session_args args = { |
| 8578 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8579 | .clientid = clp->cl_clientid, |
| 8580 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8581 | .cb_program = NFS4_CALLBACK, |
| 8582 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8583 | struct nfs41_create_session_res res; |
| 8584 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8585 | struct rpc_message msg = { |
| 8586 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8587 | .rpc_argp = &args, |
| 8588 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8589 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8590 | }; |
| 8591 | int status; |
| 8592 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8593 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8594 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8595 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8596 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8597 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8598 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8599 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8600 | switch (status) { |
| 8601 | case -NFS4ERR_STALE_CLIENTID: |
| 8602 | case -NFS4ERR_DELAY: |
| 8603 | case -ETIMEDOUT: |
| 8604 | case -EACCES: |
| 8605 | case -EAGAIN: |
| 8606 | goto out; |
| 8607 | }; |
| 8608 | |
| 8609 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8610 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8611 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8612 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8613 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8614 | if (status) |
| 8615 | goto out; |
| 8616 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8617 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8618 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8619 | return status; |
| 8620 | } |
| 8621 | |
| 8622 | /* |
| 8623 | * Issues a CREATE_SESSION operation to the server. |
| 8624 | * It is the responsibility of the caller to verify the session is |
| 8625 | * expired before calling this routine. |
| 8626 | */ |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8627 | 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] | 8628 | { |
| 8629 | int status; |
| 8630 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8631 | struct nfs4_session *session = clp->cl_session; |
| 8632 | |
| 8633 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8634 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8635 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8636 | if (status) |
| 8637 | goto out; |
| 8638 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8639 | /* Init or reset the session slot tables */ |
| 8640 | status = nfs4_setup_session_slot_tables(session); |
| 8641 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8642 | if (status) |
| 8643 | goto out; |
| 8644 | |
| 8645 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8646 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8647 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8648 | out: |
| 8649 | dprintk("<-- %s\n", __func__); |
| 8650 | return status; |
| 8651 | } |
| 8652 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8653 | /* |
| 8654 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8655 | * The caller must serialize access to this routine. |
| 8656 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8657 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8658 | const struct cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8659 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8660 | struct rpc_message msg = { |
| 8661 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8662 | .rpc_argp = session, |
| 8663 | .rpc_cred = cred, |
| 8664 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8665 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8666 | |
| 8667 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8668 | |
| 8669 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8670 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8671 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8672 | |
NeilBrown | 5a0c257 | 2019-05-30 10:41:28 +1000 | [diff] [blame] | 8673 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
| 8674 | RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8675 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8676 | |
| 8677 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8678 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8679 | "Session has been destroyed regardless...\n", status); |
| 8680 | |
| 8681 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8682 | return status; |
| 8683 | } |
| 8684 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8685 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8686 | * Renew the cl_session lease. |
| 8687 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8688 | struct nfs4_sequence_data { |
| 8689 | struct nfs_client *clp; |
| 8690 | struct nfs4_sequence_args args; |
| 8691 | struct nfs4_sequence_res res; |
| 8692 | }; |
| 8693 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8694 | static void nfs41_sequence_release(void *data) |
| 8695 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8696 | struct nfs4_sequence_data *calldata = data; |
| 8697 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8698 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8699 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8700 | nfs4_schedule_state_renewal(clp); |
| 8701 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8702 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8703 | } |
| 8704 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8705 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8706 | { |
| 8707 | switch(task->tk_status) { |
| 8708 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8709 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8710 | return -EAGAIN; |
| 8711 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8712 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8713 | } |
| 8714 | return 0; |
| 8715 | } |
| 8716 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8717 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8718 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8719 | struct nfs4_sequence_data *calldata = data; |
| 8720 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8721 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8722 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8723 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8724 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8725 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8726 | if (task->tk_status < 0) { |
| 8727 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8728 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8729 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8730 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8731 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8732 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8733 | return; |
| 8734 | } |
| 8735 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8736 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8737 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8738 | dprintk("<-- %s\n", __func__); |
| 8739 | } |
| 8740 | |
| 8741 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8742 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8743 | struct nfs4_sequence_data *calldata = data; |
| 8744 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8745 | struct nfs4_sequence_args *args; |
| 8746 | struct nfs4_sequence_res *res; |
| 8747 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8748 | args = task->tk_msg.rpc_argp; |
| 8749 | res = task->tk_msg.rpc_resp; |
| 8750 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8751 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8752 | } |
| 8753 | |
| 8754 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8755 | .rpc_call_done = nfs41_sequence_call_done, |
| 8756 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8757 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8758 | }; |
| 8759 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8760 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8761 | const struct cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8762 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8763 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8764 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8765 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8766 | struct rpc_message msg = { |
| 8767 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8768 | .rpc_cred = cred, |
| 8769 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8770 | struct rpc_task_setup task_setup_data = { |
| 8771 | .rpc_client = clp->cl_rpcclient, |
| 8772 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8773 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8774 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8775 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8776 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8777 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8778 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8779 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8780 | goto out_err; |
| 8781 | |
| 8782 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8783 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8784 | if (calldata == NULL) |
| 8785 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8786 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8787 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8788 | msg.rpc_argp = &calldata->args; |
| 8789 | msg.rpc_resp = &calldata->res; |
| 8790 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8791 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8792 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8793 | ret = rpc_run_task(&task_setup_data); |
| 8794 | if (IS_ERR(ret)) |
| 8795 | goto out_err; |
| 8796 | return ret; |
| 8797 | out_put_clp: |
| 8798 | nfs_put_client(clp); |
| 8799 | out_err: |
| 8800 | nfs41_release_slot(slot); |
| 8801 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8802 | } |
| 8803 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8804 | 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] | 8805 | { |
| 8806 | struct rpc_task *task; |
| 8807 | int ret = 0; |
| 8808 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8809 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8810 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8811 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8812 | if (IS_ERR(task)) |
| 8813 | ret = PTR_ERR(task); |
| 8814 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8815 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8816 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8817 | return ret; |
| 8818 | } |
| 8819 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8820 | 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] | 8821 | { |
| 8822 | struct rpc_task *task; |
| 8823 | int ret; |
| 8824 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8825 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8826 | if (IS_ERR(task)) { |
| 8827 | ret = PTR_ERR(task); |
| 8828 | goto out; |
| 8829 | } |
| 8830 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8831 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8832 | ret = task->tk_status; |
| 8833 | rpc_put_task(task); |
| 8834 | out: |
| 8835 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8836 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8837 | } |
| 8838 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8839 | struct nfs4_reclaim_complete_data { |
| 8840 | struct nfs_client *clp; |
| 8841 | struct nfs41_reclaim_complete_args arg; |
| 8842 | struct nfs41_reclaim_complete_res res; |
| 8843 | }; |
| 8844 | |
| 8845 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8846 | { |
| 8847 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8848 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8849 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8850 | &calldata->arg.seq_args, |
| 8851 | &calldata->res.seq_res, |
| 8852 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8853 | } |
| 8854 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8855 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8856 | { |
| 8857 | switch(task->tk_status) { |
| 8858 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8859 | wake_up_all(&clp->cl_lock_waitq); |
| 8860 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8861 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8862 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8863 | break; |
| 8864 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8865 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8866 | /* fall through */ |
| 8867 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8868 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8869 | case -NFS4ERR_BADSESSION: |
| 8870 | case -NFS4ERR_DEADSESSION: |
| 8871 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8872 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8873 | task->tk_status); |
| 8874 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8875 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8876 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8877 | } |
| 8878 | return 0; |
| 8879 | } |
| 8880 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8881 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8882 | { |
| 8883 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8884 | struct nfs_client *clp = calldata->clp; |
| 8885 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8886 | |
| 8887 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8888 | if (!nfs41_sequence_done(task, res)) |
| 8889 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8890 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8891 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8892 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8893 | rpc_restart_call_prepare(task); |
| 8894 | return; |
| 8895 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8896 | dprintk("<-- %s\n", __func__); |
| 8897 | } |
| 8898 | |
| 8899 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8900 | { |
| 8901 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8902 | |
| 8903 | kfree(calldata); |
| 8904 | } |
| 8905 | |
| 8906 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8907 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8908 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8909 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8910 | }; |
| 8911 | |
| 8912 | /* |
| 8913 | * Issue a global reclaim complete. |
| 8914 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8915 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 8916 | const struct cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8917 | { |
| 8918 | struct nfs4_reclaim_complete_data *calldata; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8919 | struct rpc_message msg = { |
| 8920 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8921 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8922 | }; |
| 8923 | struct rpc_task_setup task_setup_data = { |
| 8924 | .rpc_client = clp->cl_rpcclient, |
| 8925 | .rpc_message = &msg, |
| 8926 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 8927 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8928 | }; |
| 8929 | int status = -ENOMEM; |
| 8930 | |
| 8931 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8932 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8933 | if (calldata == NULL) |
| 8934 | goto out; |
| 8935 | calldata->clp = clp; |
| 8936 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8937 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8938 | 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] | 8939 | msg.rpc_argp = &calldata->arg; |
| 8940 | msg.rpc_resp = &calldata->res; |
| 8941 | task_setup_data.callback_data = calldata; |
Anna Schumaker | 4c952e3 | 2019-08-14 15:46:48 -0400 | [diff] [blame] | 8942 | status = nfs4_call_sync_custom(&task_setup_data); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8943 | out: |
| 8944 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8945 | return status; |
| 8946 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8947 | |
| 8948 | static void |
| 8949 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8950 | { |
| 8951 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8952 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8953 | |
| 8954 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8955 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8956 | &lgp->res.seq_res, task); |
| 8957 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8958 | } |
| 8959 | |
| 8960 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8961 | { |
| 8962 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8963 | |
| 8964 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8965 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8966 | dprintk("<-- %s\n", __func__); |
| 8967 | } |
| 8968 | |
| 8969 | static int |
| 8970 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8971 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8972 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8973 | struct inode *inode = lgp->args.inode; |
| 8974 | struct nfs_server *server = NFS_SERVER(inode); |
| 8975 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8976 | int nfs4err = task->tk_status; |
| 8977 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8978 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8979 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8980 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8981 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 8982 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 8983 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8984 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8985 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8986 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8987 | |
| 8988 | /* |
| 8989 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8990 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8991 | * retry go inband. |
| 8992 | */ |
| 8993 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8994 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8995 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8996 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8997 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8998 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8999 | */ |
| 9000 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9001 | status = -EOVERFLOW; |
| 9002 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9003 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9004 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 9005 | * (or clients) writing to the same RAID stripe except when |
| 9006 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9007 | * |
| 9008 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 9009 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9010 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9011 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9012 | if (lgp->args.minlength == 0) { |
| 9013 | status = -EOVERFLOW; |
| 9014 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 9015 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9016 | status = -EBUSY; |
| 9017 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9018 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9019 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9020 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9021 | case -NFS4ERR_DELEG_REVOKED: |
| 9022 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9023 | case -NFS4ERR_EXPIRED: |
| 9024 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9025 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9026 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9027 | lo = NFS_I(inode)->layout; |
| 9028 | /* If the open stateid was bad, then recover it. */ |
| 9029 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 9030 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9031 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9032 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 9033 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 9034 | break; |
| 9035 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9036 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9037 | /* |
| 9038 | * Mark the bad layout state as invalid, then retry |
| 9039 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 9040 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9041 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 9042 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 9043 | pnfs_free_lseg_list(&head); |
| 9044 | status = -EAGAIN; |
| 9045 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9046 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9047 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 9048 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 9049 | if (!status) { |
| 9050 | if (exception->retry) |
| 9051 | status = -EAGAIN; |
| 9052 | else |
| 9053 | status = err; |
| 9054 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 9055 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9056 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9057 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9058 | } |
| 9059 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9060 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 9061 | { |
| 9062 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 9063 | return nfs_page_array_len(0, max_resp_sz); |
| 9064 | } |
| 9065 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9066 | static void nfs4_layoutget_release(void *calldata) |
| 9067 | { |
| 9068 | struct nfs4_layoutget *lgp = calldata; |
| 9069 | |
| 9070 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 9071 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 9072 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9073 | dprintk("<-- %s\n", __func__); |
| 9074 | } |
| 9075 | |
| 9076 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 9077 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 9078 | .rpc_call_done = nfs4_layoutget_done, |
| 9079 | .rpc_release = nfs4_layoutget_release, |
| 9080 | }; |
| 9081 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9082 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 9083 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9084 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 9085 | struct inode *inode = lgp->args.inode; |
| 9086 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9087 | struct rpc_task *task; |
| 9088 | struct rpc_message msg = { |
| 9089 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 9090 | .rpc_argp = &lgp->args, |
| 9091 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 9092 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9093 | }; |
| 9094 | struct rpc_task_setup task_setup_data = { |
| 9095 | .rpc_client = server->client, |
| 9096 | .rpc_message = &msg, |
| 9097 | .callback_ops = &nfs4_layoutget_call_ops, |
| 9098 | .callback_data = lgp, |
| 9099 | .flags = RPC_TASK_ASYNC, |
| 9100 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9101 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 9102 | struct nfs4_exception exception = { |
| 9103 | .inode = inode, |
| 9104 | .timeout = *timeout, |
| 9105 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9106 | int status = 0; |
| 9107 | |
| 9108 | dprintk("--> %s\n", __func__); |
| 9109 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 9110 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 9111 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 9112 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9113 | 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] | 9114 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9115 | task = rpc_run_task(&task_setup_data); |
| 9116 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9117 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 9118 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9119 | if (status != 0) |
| 9120 | goto out; |
| 9121 | |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9122 | if (task->tk_status < 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9123 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 9124 | *timeout = exception.timeout; |
Trond Myklebust | 18c0778 | 2019-02-13 07:55:31 -0500 | [diff] [blame] | 9125 | } else if (lgp->res.layoutp->len == 0) { |
| 9126 | status = -EAGAIN; |
| 9127 | *timeout = nfs4_update_delay(&exception.timeout); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 9128 | } else |
| 9129 | lseg = pnfs_layout_process(lgp); |
| 9130 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9131 | trace_nfs4_layoutget(lgp->args.ctx, |
| 9132 | &lgp->args.range, |
| 9133 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9134 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 9135 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 9136 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9137 | rpc_put_task(task); |
| 9138 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 9139 | if (status) |
| 9140 | return ERR_PTR(status); |
| 9141 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9142 | } |
| 9143 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9144 | static void |
| 9145 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 9146 | { |
| 9147 | struct nfs4_layoutreturn *lrp = calldata; |
| 9148 | |
| 9149 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9150 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9151 | &lrp->args.seq_args, |
| 9152 | &lrp->res.seq_res, |
| 9153 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 9154 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 9155 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9156 | } |
| 9157 | |
| 9158 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 9159 | { |
| 9160 | struct nfs4_layoutreturn *lrp = calldata; |
| 9161 | struct nfs_server *server; |
| 9162 | |
| 9163 | dprintk("--> %s\n", __func__); |
| 9164 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9165 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9166 | return; |
| 9167 | |
Trond Myklebust | 6109bcf | 2019-09-20 07:23:43 -0400 | [diff] [blame] | 9168 | /* |
| 9169 | * Was there an RPC level error? Assume the call succeeded, |
| 9170 | * and that we need to release the layout |
| 9171 | */ |
| 9172 | if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
| 9173 | lrp->res.lrs_present = 0; |
| 9174 | return; |
| 9175 | } |
| 9176 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9177 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9178 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9179 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 30cb3ee | 2019-09-20 07:23:45 -0400 | [diff] [blame] | 9180 | if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame] | 9181 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9182 | lrp->args.inode)) |
| 9183 | goto out_restart; |
| 9184 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9185 | default: |
| 9186 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9187 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9188 | case 0: |
| 9189 | break; |
| 9190 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9191 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 9192 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9193 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9194 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9195 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 9196 | return; |
| 9197 | out_restart: |
| 9198 | task->tk_status = 0; |
| 9199 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 9200 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9201 | } |
| 9202 | |
| 9203 | static void nfs4_layoutreturn_release(void *calldata) |
| 9204 | { |
| 9205 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 9206 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9207 | |
| 9208 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 9209 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 9210 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 9211 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 9212 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 9213 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 9214 | pnfs_put_layout_hdr(lrp->args.layout); |
| 9215 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9216 | kfree(calldata); |
| 9217 | dprintk("<-- %s\n", __func__); |
| 9218 | } |
| 9219 | |
| 9220 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 9221 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 9222 | .rpc_call_done = nfs4_layoutreturn_done, |
| 9223 | .rpc_release = nfs4_layoutreturn_release, |
| 9224 | }; |
| 9225 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9226 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9227 | { |
| 9228 | struct rpc_task *task; |
| 9229 | struct rpc_message msg = { |
| 9230 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9231 | .rpc_argp = &lrp->args, |
| 9232 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9233 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9234 | }; |
| 9235 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9236 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9237 | .rpc_message = &msg, |
| 9238 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9239 | .callback_data = lrp, |
| 9240 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9241 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9242 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9243 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9244 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9245 | &task_setup_data.rpc_client, &msg); |
| 9246 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9247 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9248 | if (!sync) { |
| 9249 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 9250 | if (!lrp->inode) { |
| 9251 | nfs4_layoutreturn_release(lrp); |
| 9252 | return -EAGAIN; |
| 9253 | } |
| 9254 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9255 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9256 | 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] | 9257 | task = rpc_run_task(&task_setup_data); |
| 9258 | if (IS_ERR(task)) |
| 9259 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9260 | if (sync) |
| 9261 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9262 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9263 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9264 | rpc_put_task(task); |
| 9265 | return status; |
| 9266 | } |
| 9267 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9268 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9269 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9270 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9271 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9272 | { |
| 9273 | struct nfs4_getdeviceinfo_args args = { |
| 9274 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9275 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9276 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9277 | }; |
| 9278 | struct nfs4_getdeviceinfo_res res = { |
| 9279 | .pdev = pdev, |
| 9280 | }; |
| 9281 | struct rpc_message msg = { |
| 9282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9283 | .rpc_argp = &args, |
| 9284 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9285 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9286 | }; |
| 9287 | int status; |
| 9288 | |
| 9289 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9290 | 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] | 9291 | if (res.notification & ~args.notify_types) |
| 9292 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9293 | if (res.notification != args.notify_types) |
| 9294 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9295 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9296 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9297 | |
| 9298 | return status; |
| 9299 | } |
| 9300 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9301 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9302 | struct pnfs_device *pdev, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9303 | const struct cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9304 | { |
| 9305 | struct nfs4_exception exception = { }; |
| 9306 | int err; |
| 9307 | |
| 9308 | do { |
| 9309 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9310 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9311 | &exception); |
| 9312 | } while (exception.retry); |
| 9313 | return err; |
| 9314 | } |
| 9315 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9316 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9317 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9318 | { |
| 9319 | struct nfs4_layoutcommit_data *data = calldata; |
| 9320 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9321 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9322 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9323 | &data->args.seq_args, |
| 9324 | &data->res.seq_res, |
| 9325 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9326 | } |
| 9327 | |
| 9328 | static void |
| 9329 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9330 | { |
| 9331 | struct nfs4_layoutcommit_data *data = calldata; |
| 9332 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9333 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9334 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9335 | return; |
| 9336 | |
| 9337 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9338 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9339 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9340 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9341 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9342 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9343 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9344 | break; |
| 9345 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9346 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9347 | rpc_restart_call_prepare(task); |
| 9348 | return; |
| 9349 | } |
| 9350 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9351 | } |
| 9352 | |
| 9353 | static void nfs4_layoutcommit_release(void *calldata) |
| 9354 | { |
| 9355 | struct nfs4_layoutcommit_data *data = calldata; |
| 9356 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9357 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9358 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9359 | data->res.fattr); |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9360 | put_cred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9361 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9362 | kfree(data); |
| 9363 | } |
| 9364 | |
| 9365 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9366 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9367 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9368 | .rpc_release = nfs4_layoutcommit_release, |
| 9369 | }; |
| 9370 | |
| 9371 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9372 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9373 | { |
| 9374 | struct rpc_message msg = { |
| 9375 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9376 | .rpc_argp = &data->args, |
| 9377 | .rpc_resp = &data->res, |
| 9378 | .rpc_cred = data->cred, |
| 9379 | }; |
| 9380 | struct rpc_task_setup task_setup_data = { |
| 9381 | .task = &data->task, |
| 9382 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9383 | .rpc_message = &msg, |
| 9384 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9385 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9386 | }; |
| 9387 | struct rpc_task *task; |
| 9388 | int status = 0; |
| 9389 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9390 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9391 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9392 | data->args.lastbytewritten, |
| 9393 | data->args.inode->i_ino); |
| 9394 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9395 | if (!sync) { |
| 9396 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9397 | if (data->inode == NULL) { |
| 9398 | nfs4_layoutcommit_release(data); |
| 9399 | return -EAGAIN; |
| 9400 | } |
| 9401 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9402 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9403 | 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] | 9404 | task = rpc_run_task(&task_setup_data); |
| 9405 | if (IS_ERR(task)) |
| 9406 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9407 | if (sync) |
| 9408 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9409 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9410 | dprintk("%s: status %d\n", __func__, status); |
| 9411 | rpc_put_task(task); |
| 9412 | return status; |
| 9413 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9414 | |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9415 | /* |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9416 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9417 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9418 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9419 | static int |
| 9420 | _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] | 9421 | struct nfs_fsinfo *info, |
| 9422 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9423 | { |
| 9424 | struct nfs41_secinfo_no_name_args args = { |
| 9425 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9426 | }; |
| 9427 | struct nfs4_secinfo_res res = { |
| 9428 | .flavors = flavors, |
| 9429 | }; |
| 9430 | struct rpc_message msg = { |
| 9431 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9432 | .rpc_argp = &args, |
| 9433 | .rpc_resp = &res, |
| 9434 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9435 | struct rpc_clnt *clnt = server->client; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9436 | struct nfs4_call_sync_data data = { |
| 9437 | .seq_server = server, |
| 9438 | .seq_args = &args.seq_args, |
| 9439 | .seq_res = &res.seq_res, |
| 9440 | }; |
| 9441 | struct rpc_task_setup task_setup = { |
| 9442 | .rpc_client = server->client, |
| 9443 | .rpc_message = &msg, |
| 9444 | .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
| 9445 | .callback_data = &data, |
| 9446 | .flags = RPC_TASK_NO_ROUND_ROBIN, |
| 9447 | }; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9448 | const struct cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9449 | int status; |
| 9450 | |
| 9451 | if (use_integrity) { |
| 9452 | clnt = server->nfs_client->cl_rpcclient; |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9453 | task_setup.rpc_client = clnt; |
| 9454 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9455 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9456 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9457 | } |
| 9458 | |
| 9459 | dprintk("--> %s\n", __func__); |
Anna Schumaker | cc15e24 | 2019-08-14 16:22:31 -0400 | [diff] [blame] | 9460 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
| 9461 | status = nfs4_call_sync_custom(&task_setup); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9462 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9463 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9464 | put_cred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9465 | |
| 9466 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9467 | } |
| 9468 | |
| 9469 | static int |
| 9470 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9471 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9472 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9473 | struct nfs4_exception exception = { |
| 9474 | .interruptible = true, |
| 9475 | }; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9476 | int err; |
| 9477 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9478 | /* first try using integrity protection */ |
| 9479 | err = -NFS4ERR_WRONGSEC; |
| 9480 | |
| 9481 | /* try to use integrity protection with machine cred */ |
| 9482 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9483 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9484 | flavors, true); |
| 9485 | |
| 9486 | /* |
| 9487 | * if unable to use integrity protection, or SECINFO with |
| 9488 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9489 | * disallowed by spec, but exists in deployed servers) use |
| 9490 | * the current filesystem's rpc_client and the user cred. |
| 9491 | */ |
| 9492 | if (err == -NFS4ERR_WRONGSEC) |
| 9493 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9494 | flavors, false); |
| 9495 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9496 | switch (err) { |
| 9497 | case 0: |
| 9498 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9499 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9500 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9501 | default: |
| 9502 | err = nfs4_handle_exception(server, err, &exception); |
| 9503 | } |
| 9504 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9505 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9506 | return err; |
| 9507 | } |
| 9508 | |
| 9509 | static int |
| 9510 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9511 | struct nfs_fsinfo *info) |
| 9512 | { |
| 9513 | int err; |
| 9514 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9515 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9516 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9517 | struct nfs4_secinfo4 *secinfo; |
| 9518 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9519 | |
| 9520 | page = alloc_page(GFP_KERNEL); |
| 9521 | if (!page) { |
| 9522 | err = -ENOMEM; |
| 9523 | goto out; |
| 9524 | } |
| 9525 | |
| 9526 | flavors = page_address(page); |
| 9527 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9528 | |
| 9529 | /* |
| 9530 | * Fall back on "guess and check" method if |
| 9531 | * the server doesn't support SECINFO_NO_NAME |
| 9532 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9533 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9534 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9535 | goto out_freepage; |
| 9536 | } |
| 9537 | if (err) |
| 9538 | goto out_freepage; |
| 9539 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9540 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9541 | secinfo = &flavors->flavors[i]; |
| 9542 | |
| 9543 | switch (secinfo->flavor) { |
| 9544 | case RPC_AUTH_NULL: |
| 9545 | case RPC_AUTH_UNIX: |
| 9546 | case RPC_AUTH_GSS: |
| 9547 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9548 | &secinfo->flavor_info); |
| 9549 | break; |
| 9550 | default: |
| 9551 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9552 | break; |
| 9553 | } |
| 9554 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9555 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9556 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9557 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9558 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9559 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9560 | info, flavor); |
| 9561 | if (!err) |
| 9562 | break; |
| 9563 | } |
| 9564 | } |
| 9565 | |
| 9566 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9567 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9568 | |
| 9569 | out_freepage: |
| 9570 | put_page(page); |
| 9571 | if (err == -EACCES) |
| 9572 | return -EPERM; |
| 9573 | out: |
| 9574 | return err; |
| 9575 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9576 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9577 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9578 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9579 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9580 | { |
| 9581 | int status; |
| 9582 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9583 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9584 | }; |
| 9585 | struct nfs41_test_stateid_res res; |
| 9586 | struct rpc_message msg = { |
| 9587 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9588 | .rpc_argp = &args, |
| 9589 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9590 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9591 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9592 | struct rpc_clnt *rpc_client = server->client; |
| 9593 | |
| 9594 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9595 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9596 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9597 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9598 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9599 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9600 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9601 | if (status != NFS_OK) { |
| 9602 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9603 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9604 | } |
| 9605 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9606 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9607 | } |
| 9608 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9609 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9610 | int err, struct nfs4_exception *exception) |
| 9611 | { |
| 9612 | exception->retry = 0; |
| 9613 | switch(err) { |
| 9614 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9615 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9616 | nfs4_handle_exception(server, err, exception); |
| 9617 | break; |
| 9618 | case -NFS4ERR_BADSESSION: |
| 9619 | case -NFS4ERR_BADSLOT: |
| 9620 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9621 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9622 | case -NFS4ERR_DEADSESSION: |
| 9623 | nfs4_do_handle_exception(server, err, exception); |
| 9624 | } |
| 9625 | } |
| 9626 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9627 | /** |
| 9628 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9629 | * |
| 9630 | * @server: server / transport on which to perform the operation |
| 9631 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9632 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9633 | * |
| 9634 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9635 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9636 | * failed or the state ID is not currently valid. |
| 9637 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9638 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9639 | nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9640 | const struct cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9641 | { |
Trond Myklebust | 0688e64 | 2019-04-07 13:59:09 -0400 | [diff] [blame] | 9642 | struct nfs4_exception exception = { |
| 9643 | .interruptible = true, |
| 9644 | }; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9645 | int err; |
| 9646 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9647 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9648 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9649 | } while (exception.retry); |
| 9650 | return err; |
| 9651 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9652 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9653 | struct nfs_free_stateid_data { |
| 9654 | struct nfs_server *server; |
| 9655 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9656 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9657 | }; |
| 9658 | |
| 9659 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9660 | { |
| 9661 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9662 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9663 | &data->args.seq_args, |
| 9664 | &data->res.seq_res, |
| 9665 | task); |
| 9666 | } |
| 9667 | |
| 9668 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9669 | { |
| 9670 | struct nfs_free_stateid_data *data = calldata; |
| 9671 | |
| 9672 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9673 | |
| 9674 | switch (task->tk_status) { |
| 9675 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9676 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9677 | rpc_restart_call_prepare(task); |
| 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | static void nfs41_free_stateid_release(void *calldata) |
| 9682 | { |
| 9683 | kfree(calldata); |
| 9684 | } |
| 9685 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9686 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9687 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9688 | .rpc_call_done = nfs41_free_stateid_done, |
| 9689 | .rpc_release = nfs41_free_stateid_release, |
| 9690 | }; |
| 9691 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9692 | /** |
| 9693 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9694 | * |
| 9695 | * @server: server / transport on which to perform the operation |
| 9696 | * @stateid: state ID to release |
| 9697 | * @cred: credential |
Trond Myklebust | 302fad7 | 2019-02-18 13:32:38 -0500 | [diff] [blame] | 9698 | * @privileged: set to true if this call needs to be privileged |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9699 | * |
| 9700 | * Note: this function is always asynchronous. |
| 9701 | */ |
| 9702 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9703 | const nfs4_stateid *stateid, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9704 | const struct cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9705 | bool privileged) |
| 9706 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9707 | struct rpc_message msg = { |
| 9708 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9709 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9710 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9711 | struct rpc_task_setup task_setup = { |
| 9712 | .rpc_client = server->client, |
| 9713 | .rpc_message = &msg, |
| 9714 | .callback_ops = &nfs41_free_stateid_ops, |
| 9715 | .flags = RPC_TASK_ASYNC, |
| 9716 | }; |
| 9717 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9718 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9719 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9720 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9721 | &task_setup.rpc_client, &msg); |
| 9722 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9723 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9724 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9725 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9726 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9727 | data->server = server; |
| 9728 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9729 | |
| 9730 | task_setup.callback_data = data; |
| 9731 | |
| 9732 | msg.rpc_argp = &data->args; |
| 9733 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9734 | 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] | 9735 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9736 | if (IS_ERR(task)) |
| 9737 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9738 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9739 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9740 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9741 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9742 | static void |
| 9743 | 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] | 9744 | { |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 9745 | const struct cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9746 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9747 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9748 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9749 | } |
| 9750 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9751 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9752 | const nfs4_stateid *s2) |
| 9753 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9754 | if (s1->type != s2->type) |
| 9755 | return false; |
| 9756 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9757 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9758 | return false; |
| 9759 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9760 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9761 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9762 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9763 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9764 | } |
| 9765 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9766 | #endif /* CONFIG_NFS_V4_1 */ |
| 9767 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9768 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9769 | const nfs4_stateid *s2) |
| 9770 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9771 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9772 | } |
| 9773 | |
| 9774 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9775 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9776 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9777 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9778 | .recover_open = nfs4_open_reclaim, |
| 9779 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9780 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9781 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9782 | }; |
| 9783 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9784 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9785 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9786 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9787 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9788 | .recover_open = nfs4_open_reclaim, |
| 9789 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9790 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9791 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9792 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9793 | }; |
| 9794 | #endif /* CONFIG_NFS_V4_1 */ |
| 9795 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9796 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9797 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9798 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9799 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9800 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9801 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9802 | }; |
| 9803 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9804 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9805 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9806 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9807 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9808 | .recover_open = nfs41_open_expired, |
| 9809 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9810 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9811 | }; |
| 9812 | #endif /* CONFIG_NFS_V4_1 */ |
| 9813 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9814 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9815 | .sched_state_renewal = nfs4_proc_async_renew, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 9816 | .get_state_renewal_cred = nfs4_get_renew_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9817 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9818 | }; |
| 9819 | |
| 9820 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9821 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9822 | .sched_state_renewal = nfs41_proc_async_sequence, |
NeilBrown | f15e1e8 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 9823 | .get_state_renewal_cred = nfs4_get_machine_cred, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9824 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9825 | }; |
| 9826 | #endif |
| 9827 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9828 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9829 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9830 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9831 | }; |
| 9832 | |
| 9833 | #if defined(CONFIG_NFS_V4_1) |
| 9834 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9835 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9836 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9837 | }; |
| 9838 | #endif /* CONFIG_NFS_V4_1 */ |
| 9839 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9840 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9841 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9842 | .init_caps = NFS_CAP_READDIRPLUS |
| 9843 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9844 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9845 | .init_client = nfs40_init_client, |
| 9846 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9847 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9848 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9849 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9850 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9851 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9852 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9853 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9854 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9855 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9856 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9857 | }; |
| 9858 | |
| 9859 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9860 | static struct nfs_seqid * |
| 9861 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9862 | { |
| 9863 | return NULL; |
| 9864 | } |
| 9865 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9866 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9867 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9868 | .init_caps = NFS_CAP_READDIRPLUS |
| 9869 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9870 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9871 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9872 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 9873 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9874 | .init_client = nfs41_init_client, |
| 9875 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9876 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9877 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9878 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9879 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9880 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9881 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9882 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9883 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9884 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9885 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9886 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9887 | }; |
| 9888 | #endif |
| 9889 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9890 | #if defined(CONFIG_NFS_V4_2) |
| 9891 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9892 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9893 | .init_caps = NFS_CAP_READDIRPLUS |
| 9894 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9895 | | NFS_CAP_POSIX_LOCK |
| 9896 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9897 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9898 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9899 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9900 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 9901 | | NFS_CAP_OFFLOAD_CANCEL |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 9902 | | NFS_CAP_COPY_NOTIFY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9903 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9904 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9905 | | NFS_CAP_LAYOUTSTATS |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 9906 | | NFS_CAP_CLONE |
| 9907 | | NFS_CAP_LAYOUTERROR, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9908 | .init_client = nfs41_init_client, |
| 9909 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9910 | .match_stateid = nfs41_match_stateid, |
| 9911 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9912 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9913 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9914 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9915 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9916 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9917 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9918 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9919 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9920 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9921 | }; |
| 9922 | #endif |
| 9923 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9924 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9925 | [0] = &nfs_v4_0_minor_ops, |
| 9926 | #if defined(CONFIG_NFS_V4_1) |
| 9927 | [1] = &nfs_v4_1_minor_ops, |
| 9928 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9929 | #if defined(CONFIG_NFS_V4_2) |
| 9930 | [2] = &nfs_v4_2_minor_ops, |
| 9931 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9932 | }; |
| 9933 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9934 | 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] | 9935 | { |
| 9936 | ssize_t error, error2; |
| 9937 | |
| 9938 | error = generic_listxattr(dentry, list, size); |
| 9939 | if (error < 0) |
| 9940 | return error; |
| 9941 | if (list) { |
| 9942 | list += error; |
| 9943 | size -= error; |
| 9944 | } |
| 9945 | |
| 9946 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9947 | if (error2 < 0) |
| 9948 | return error2; |
| 9949 | return error + error2; |
| 9950 | } |
| 9951 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9952 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9953 | .create = nfs_create, |
| 9954 | .lookup = nfs_lookup, |
| 9955 | .atomic_open = nfs_atomic_open, |
| 9956 | .link = nfs_link, |
| 9957 | .unlink = nfs_unlink, |
| 9958 | .symlink = nfs_symlink, |
| 9959 | .mkdir = nfs_mkdir, |
| 9960 | .rmdir = nfs_rmdir, |
| 9961 | .mknod = nfs_mknod, |
| 9962 | .rename = nfs_rename, |
| 9963 | .permission = nfs_permission, |
| 9964 | .getattr = nfs_getattr, |
| 9965 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9966 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9967 | }; |
| 9968 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9969 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9970 | .permission = nfs_permission, |
| 9971 | .getattr = nfs_getattr, |
| 9972 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9973 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9974 | }; |
| 9975 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9976 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9977 | .version = 4, /* protocol version */ |
| 9978 | .dentry_ops = &nfs4_dentry_operations, |
| 9979 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9980 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9981 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9982 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9983 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9984 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9985 | .getattr = nfs4_proc_getattr, |
| 9986 | .setattr = nfs4_proc_setattr, |
| 9987 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9988 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9989 | .access = nfs4_proc_access, |
| 9990 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9991 | .create = nfs4_proc_create, |
| 9992 | .remove = nfs4_proc_remove, |
| 9993 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9994 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9995 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9996 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9997 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9998 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9999 | .link = nfs4_proc_link, |
| 10000 | .symlink = nfs4_proc_symlink, |
| 10001 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 10002 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10003 | .readdir = nfs4_proc_readdir, |
| 10004 | .mknod = nfs4_proc_mknod, |
| 10005 | .statfs = nfs4_proc_statfs, |
| 10006 | .fsinfo = nfs4_proc_fsinfo, |
| 10007 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 10008 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10009 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 10010 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10011 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10012 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10013 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10014 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10015 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 10016 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 10017 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10018 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 10019 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 10020 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 10021 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 10022 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 10023 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 10024 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 10025 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 10026 | .create_server = nfs4_create_server, |
| 10027 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10028 | }; |
| 10029 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10030 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 10031 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10032 | .list = nfs4_xattr_list_nfs4_acl, |
| 10033 | .get = nfs4_xattr_get_nfs4_acl, |
| 10034 | .set = nfs4_xattr_set_nfs4_acl, |
| 10035 | }; |
| 10036 | |
| 10037 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 10038 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 10039 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 10040 | &nfs4_xattr_nfs4_label_handler, |
| 10041 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 10042 | NULL |
| 10043 | }; |
| 10044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10045 | /* |
| 10046 | * Local variables: |
| 10047 | * c-basic-offset: 8 |
| 10048 | * End: |
| 10049 | */ |